Changeset 28 for branches/multithread
- Timestamp:
- 10/02/07 12:49:26 (1 year ago)
- Location:
- branches/multithread
- Files:
-
- 15 modified
-
.classpath (modified) (1 diff)
-
bin/build.xml (modified) (3 diffs)
-
conf/chord.properties (modified) (3 diffs)
-
conf/chord_dht.properties (modified) (2 diffs)
-
conf/symphony.properties (modified) (1 diff)
-
conf/trivial.properties (modified) (3 diffs)
-
lib/planetsim.jar (modified) (previous)
-
src/planet/generic/commonapi/MultiThreadedNetworkImpl.java (modified) (8 diffs)
-
src/planet/generic/commonapi/behaviours/BehavioursPoolImpl.java (modified) (2 diffs)
-
src/planet/generic/commonapi/factory/RouteMessagePoolImpl.java (modified) (3 diffs)
-
src/planet/simulate/Results.java (modified) (6 diffs)
-
src/planet/test/helloworld/DHTApplication.java (modified) (1 diff)
-
src/planet/test/helloworld/DHTPeerTest.java (modified) (1 diff)
-
src/planet/trivialp2p/behaviours/DataBehaviour.java (modified) (2 diffs)
-
src/planet/util/KeyGen.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/multithread/.classpath
r2 r28 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER "/>5 <classpathentry kind=" lib" path="lib/junit.jar"/>4 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.6.0_02"/> 5 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/> 6 6 <classpathentry kind="output" path="out"/> 7 7 </classpath> -
branches/multithread/bin/build.xml
r21 r28 1 <project name="URV.PLANETSIM " default="targets" basedir=".">1 <project name="URV.PLANETSIM.MULTITHREAD" default="targets" basedir="."> 2 2 3 3 <property environment="env"/> … … 63 63 64 64 65 <target name="run"> 66 <java classname="planet.test.SimTest"> 67 <arg value="${event_file}"/> 68 <arg value="${steps}"/> 65 <target name="run1" description="planet.test.helloworld.DHTPeerTest"> 66 <echo message="running planet.test.helloworld.DHTPeerTest..."/> 67 <java classname="planet.test.helloworld.DHTPeerTest"> 68 <jvmarg value="-Xms512M"/> 69 <jvmarg value="-Xmx1024M"/> 69 70 <classpath refid="base.path"/> 70 71 </java> 71 72 </target> 72 73 74 <target name="run2" description="planet.test.trivialp2ptest.TrivialTest"> 75 <echo message="running planet.test.trivialp2ptest.TrivialTest..."/> 76 <java classname="planet.test.trivialp2ptest.TrivialTest"> 77 <jvmarg value="-Xms512M"/> 78 <jvmarg value="-Xmx1024M"/> 79 <classpath refid="base.path"/> 80 </java> 81 </target> 73 82 <target name="test"> 74 83 <mkdir dir="reports"/> … … 104 113 <echo message=" jar_debug Compile and create distribution with activated debug options"/> 105 114 <echo message=" api Generate api docs "/> 106 <echo message=" run Run one simple command line test"/> 115 <echo message=" run1 Runs planet.test.helloworld.DHTPeerTest"/> 116 <echo message=" run2 Runs planet.test.trivialp2ptest.TrivialTest"/> 107 117 <echo message=" test Execute a JUnit test. The output is in HTML format in 'reports' directory."/> 108 118 </target> -
branches/multithread/conf/chord.properties
r21 r28 40 40 41 41 # The default Network class 42 FACTORIES_NETWORK = planet.generic.commonapi. NetworkImpl42 FACTORIES_NETWORK = planet.generic.commonapi.MultiThreadedNetworkImpl 43 43 44 44 # The default NodeHandle class … … 53 53 54 54 # The default initial network size 55 FACTORIES_NETWORKSIZE = 100055 FACTORIES_NETWORKSIZE = 3000 56 56 57 57 … … 105 105 106 106 #Number of processors 107 SIMULATOR_PROCESSORS = 1107 SIMULATOR_PROCESSORS = 2 108 108 ################################################################################ 109 109 # SERIALIZATION PART # -
branches/multithread/conf/chord_dht.properties
r2 r28 40 40 41 41 # The default Network class 42 FACTORIES_NETWORK = planet.generic.commonapi. NetworkImpl42 FACTORIES_NETWORK = planet.generic.commonapi.MultiThreadedNetworkImpl 43 43 44 44 # The default NodeHandle class … … 104 104 SIMULATOR_EVENT_FILE = ./data/test_join1000r.txt 105 105 106 106 #Number of processors 107 SIMULATOR_PROCESSORS = 2 107 108 ################################################################################ 108 109 # SERIALIZATION PART # -
branches/multithread/conf/symphony.properties
r21 r28 40 40 41 41 # The default Network class 42 FACTORIES_NETWORK = planet.generic.commonapi. NetworkImpl42 FACTORIES_NETWORK = planet.generic.commonapi.MultiThreadedNetworkImpl 43 43 44 44 # The default NodeHandle class -
branches/multithread/conf/trivial.properties
r21 r28 40 40 41 41 # The default Network class 42 FACTORIES_NETWORK = planet.generic.commonapi. NetworkImpl42 FACTORIES_NETWORK = planet.generic.commonapi.MultiThreadedNetworkImpl 43 43 44 44 # The default NodeHandle class … … 53 53 54 54 # The default initial network size 55 FACTORIES_NETWORKSIZE = 100 56 57 55 FACTORIES_NETWORKSIZE = 3000 56 57 #Number of processors 58 SIMULATOR_PROCESSORS = 2 58 59 ########## OPTIONAL ATTRIBUTES: Test dependant 59 60 … … 173 174 174 175 # Identifies when to show specific debug info for behaviours 175 BEHAVIOURS_PROPERTIES_DEBUG = true176 BEHAVIOURS_PROPERTIES_DEBUG = false 176 177 177 178 # NOTE: The following keys start by 'BEHAVIOURS_PROPERTIES_INSTANCE', ended -
branches/multithread/src/planet/generic/commonapi/MultiThreadedNetworkImpl.java
r20 r28 61 61 * Containts all nodes to remove from the network. 62 62 */ 63 private Stack toRemove;63 private Stack<NodeHandle> toRemove; 64 64 /** 65 65 * NodeFactory implementation which permits build new nodes. … … 80 80 81 81 private final int PROCESSORS; 82 private final Thread[] threads; 83 private final ProcessGroup[] processGroups; 84 // private final Boolean[] continues; 82 85 /** 83 86 * Initialize the network with no nodes and wihtout simulation steps. … … 85 88 public MultiThreadedNetworkImpl() { 86 89 PROCESSORS = Properties.simulatorProcessors; 90 threads = new Thread[PROCESSORS]; 91 processGroups = new ProcessGroup[PROCESSORS]; 92 for (int i = 0; i < processGroups.length; i++) { 93 processGroups[i] = new ProcessGroup(); 94 } 95 // continues = new Boolean[PROCESSORS]; 87 96 nodes = new HashMap<NodeHandle, Node>(); //to contain all nodes 88 97 toRemove = new Stack<NodeHandle>(); … … 553 562 554 563 555 Thread[] threads = new Thread[PROCESSORS];564 556 565 Node[] nodes = new Node[this.nodes.size()]; 557 566 nodes = this.nodes.values().toArray(nodes); 558 Boolean[] continues = new Boolean[PROCESSORS]; 559 //init continues 560 for (int i = 0; i < continues.length; i++) { 561 continues[i] = false; 562 } 567 568 563 569 564 570 … … 568 574 569 575 int from = i*groupSize; 576 570 577 //if it is the last thread it gets all remaining nodes, i.e. 7 nodes and two processors groupA {0..2} and groupB {3..6} 571 int to = i==threads.length-1 ? nodes.length : from+groupSize; 572 ProcessGroup group = new ProcessGroup(nodes,from,to,continues,i); 573 Thread thread = new Thread(group); 574 threads[i] = thread; 578 int to = i==threads.length-1 ? nodes.length : from+groupSize; 579 580 //ProcessGroup group = new ProcessGroup(nodes,from,to,continues,i); 581 processGroups[i].setFrom(from); 582 processGroups[i].setTo(to); 583 processGroups[i].setNodes(nodes); 584 threads[i] = new Thread(processGroups[i]); 585 586 575 587 } 576 588 //start all threads … … 595 607 aNode = (Node)it.next(); 596 608 // always process the node 597 if (!aNode.isAlive()) { //the node has failed or le aved??609 if (!aNode.isAlive()) { //the node has failed or left?? 598 610 toRemove.add(aNode.getLocalHandle()); 599 611 } 600 612 } 601 613 boolean toContinue = false; 602 for ( Boolean b : continues) {603 toContinue |= b;614 for (int i = 0; i < processGroups.length; i++) { 615 toContinue |= processGroups[i].isToContinue(); 604 616 } 605 617 return toContinue; … … 836 848 private Node[] nodes = null; 837 849 private int from,to; 838 private Boolean[] continues = null;839 private int nr;850 // private int nr; 851 private boolean toContinue; 840 852 /** 841 853 * … … 846 858 * @param nr the positon where to set in <b>conitues</b> <code>true</code> or <code>false</code> 847 859 */ 848 public ProcessGroup(Node[] nodes, int from, int to, 849 Boolean[] continues, int nr) { 850 super(); 851 this.nodes = nodes; 852 this.from = from; 853 this.to = to; 854 this.continues = continues; 855 this.nr = nr; 856 } 860 857 861 858 862 public void run() { 859 863 860 booleantoContinue = false;864 toContinue = false; 861 865 for (int i = from; i < to; i++) { 862 866 Node n = nodes[i]; 863 867 toContinue |= n.process(totalSteps); 864 868 } 865 continues[nr]=toContinue;869 866 870 867 871 } 872 public void setNodes(Node[] nodes) { 873 this.nodes = nodes; 874 } 875 public void setFrom(int from) { 876 this.from = from; 877 } 878 public void setTo(int to) { 879 this.to = to; 880 } 881 public boolean isToContinue() { 882 return toContinue; 883 } 868 884 } 869 885 } -
branches/multithread/src/planet/generic/commonapi/behaviours/BehavioursPoolImpl.java
r2 r28 98 98 * Auxiliar Vector to use in the onMessage() method. 99 99 */ 100 protected Vector behaviours = null;100 // protected Vector behaviours = null; 101 101 /** 102 102 * Auxiliar Iterator to use in the onMessage() method. … … 357 357 whichQueue = whichQueue * BEH_MAPPINGS / 2 + (node.isLocalMessage(msg)? TRAFFIC_LOCAL: TRAFFIC_REMOTE); 358 358 359 behaviours = beh[whichQueue][msg.getType() * Properties.behavioursNumberOfModes + msg.getMode()];359 Vector behaviours = beh[whichQueue][msg.getType() * Properties.behavioursNumberOfModes + msg.getMode()]; 360 360 361 361 if (behaviours.isEmpty()) throw new NoSuchBehaviourException(); -
branches/multithread/src/planet/generic/commonapi/factory/RouteMessagePoolImpl.java
r2 r28 66 66 * @see planet.commonapi.factory.RouteMessagePool#freeMessage(planet.commonapi.RouteMessage) 67 67 */ 68 public void freeMessage(RouteMessage msg) {68 public synchronized void freeMessage(RouteMessage msg) { 69 69 if (msg == null) return; 70 70 messages.push (msg); … … 84 84 * @see planet.commonapi.factory.RouteMessagePool#getMessage(java.lang.String, planet.commonapi.NodeHandle, planet.commonapi.NodeHandle, int, int) 85 85 */ 86 public RouteMessage getMessage(String key, NodeHandle from, NodeHandle to,86 public synchronized RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 87 87 int type, int mode) throws InitializationException { 88 88 if (messages.size() > 0) { … … 117 117 * @see planet.commonapi.factory.RouteMessagePool#getMessage(String, NodeHandle, NodeHandle, NodeHandle, int, int, Message, String) 118 118 */ 119 public RouteMessage getMessage(String key, NodeHandle from, NodeHandle to,119 public synchronized RouteMessage getMessage(String key, NodeHandle from, NodeHandle to, 120 120 NodeHandle nextHop, int type, int mode, Message msg, String appId) 121 121 throws InitializationException { -
branches/multithread/src/planet/simulate/Results.java
r19 r28 26 26 27 27 28 public static synchronizedvoid incStabRate() {28 public static void incStabRate() { 29 29 stabRate++; 30 30 } 31 31 32 public static synchronizedvoid clearStabRate() {32 public static void clearStabRate() { 33 33 stabRate=0; 34 34 } 35 35 36 public static synchronizedint getStabRate() {36 public static int getStabRate() { 37 37 return stabRate; 38 38 } … … 50 50 } 51 51 52 public static synchronizedint getTraffic() {52 public static int getTraffic() { 53 53 return traffic; 54 54 } … … 57 57 58 58 //type --> in/out 59 public static synchronizedvoid numMessagesTime(Id id, int step, int num, String type) {59 public static void numMessagesTime(Id id, int step, int num, String type) { 60 60 updateNodeStress(id,num,type); 61 61 addMaxMessages(id,step,num,type); … … 138 138 } 139 139 140 public static synchronizedvoid addInsert(String key,String dest) {140 public static void addInsert(String key,String dest) { 141 141 inserts.put(key,dest); 142 142 } 143 143 144 public static synchronizedString getInsert(String key) {144 public static String getInsert(String key) { 145 145 return (String) inserts.get(key); 146 146 } 147 147 148 public static synchronizedvoid resetInserts() {148 public static void resetInserts() { 149 149 inserts.clear(); 150 150 } 151 151 152 public static synchronizedHashtable getAllInserts() {152 public static Hashtable getAllInserts() { 153 153 return (Hashtable) inserts.clone(); 154 154 } 155 155 156 public static synchronizedvoid addLookup(Id key, Id own) {156 public static void addLookup(Id key, Id own) { 157 157 lookups.put(key,own); 158 158 } 159 159 160 public static synchronizedId getLookup(Id key) {160 public static Id getLookup(Id key) { 161 161 return ((Id) lookups.get(key)); 162 162 } 163 163 164 public static synchronizedvoid resetLookups(){164 public static void resetLookups(){ 165 165 lookups.clear(); 166 166 } 167 167 168 public static synchronizedHashtable getAllLookups() {168 public static Hashtable getAllLookups() { 169 169 return (Hashtable) lookups.clone(); 170 170 } 171 171 172 public static synchronizedvoid print () {172 public static void print () { 173 173 long total_in_msg = 0; 174 174 long total_out_msg = 0; … … 223 223 * print total and average hops 224 224 */ 225 public static synchronizedvoid printhops() {225 public static void printhops() { 226 226 Collection keys = hops.keySet(); 227 227 Iterator it = keys.iterator(); … … 255 255 } 256 256 257 public static synchronizedint getLookup_number() {257 public static int getLookup_number() { 258 258 return lookup_number; 259 259 } -
branches/multithread/src/planet/test/helloworld/DHTApplication.java
r2 r28 69 69 */ 70 70 public boolean forward(Message message) { 71 System.out.println("[" + appId + "] sobre [" + endPoint.getId()72 + "]: Fent forward del missatge...");71 // System.out.println("[" + appId + "] sobre [" + endPoint.getId() 72 // + "]: Fent forward del missatge..."); 73 73 return true; 74 74 } -
branches/multithread/src/planet/test/helloworld/DHTPeerTest.java
r2 r28 37 37 long t2 = System.currentTimeMillis(); 38 38 System.out.println("Network with ["+network.size()+"] created in ["+GenericApp.timeElapsedInSeconds(t1,t2)+"] seconds and ["+steps1+"] steps\n"); 39 network.prettyPrintNodes();39 // network.prettyPrintNodes(); 40 40 //register to all nodes the application specified at properties 41 41 network.registerApplicationAll(); 42 System.out.println("Application added. Making 15 'Hello World!' from random nodes....\n");42 // System.out.println("Application added. Making 15 'Hello World!' from random nodes....\n"); 43 43 int steps2 =0; 44 for (int i=0; i< 1 5; i++)44 for (int i=0; i< 1; i++) 45 45 steps2=sendMessage(); 46 46 long t3 = System.currentTimeMillis(); -
branches/multithread/src/planet/trivialp2p/behaviours/DataBehaviour.java
r2 r28 15 15 public class DataBehaviour implements Behaviour { 16 16 /* Internal atributes. */ 17 private TrivialNode trivialNode = null;17 18 18 19 19 /** … … 44 44 */ 45 45 public void onMessage(RouteMessage msg, Node node) { 46 trivialNode = (TrivialNode)node;46 TrivialNode trivialNode = (TrivialNode)node; 47 47 //it is necessary build a copy; the 'msg' is free at the end of its process 48 48 trivialNode.dispatchDataMessage(trivialNode.buildMessage(msg),TrivialNode.REQUEST,TrivialNode.REFRESH); -
branches/multithread/src/planet/util/KeyGen.java
r2 r28 15 15 } 16 16 17 public String generateKey() {17 public synchronized String generateKey() { 18 18 cnt++; 19 19 if (cnt>MAX) cnt = ini;
