changeset 31:5c704b9a9a87

add ring script
author kazz <kazz@cr.ie.u-ryukyu.ac.jp>
date Tue, 17 Jan 2012 20:24:46 +0900
parents b5a21baf0b07
children 2bfb796b0fa1
files scripts/ring.rb scripts/ring_manager_run.sh scripts/test.dot scripts/topology/ring.rb scripts/topology/test.dot scripts/topology/tree.rb scripts/tree.rb src/alice/test/topology/ring/FirstRingMessagePassing.java src/alice/test/topology/ring/RingMessagePassing.java src/alice/topology/manager/IncomingHosts.java src/alice/topology/node/IncomingConnectionInfo.java
diffstat 11 files changed, 100 insertions(+), 87 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ring.rb	Tue Jan 17 16:13:03 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-def create_nodes(node_num)
-  (0..node_num - 1).map { |i|
-    i = "node" + i.to_s
-  }
-end
-
-def print_dot(connections)
-  puts "digraph test {"
-  connections.each { |connection|
-    print "\t"
-    print connection[0]
-    print " -> "
-    print connection[1]
-    print ' [label="' + connection[2] + '"]'
-    puts
-  }
-  puts "}"
-end
-
-node_num = ARGV[0].to_i
-nodes = create_nodes(node_num)
-connections = Array.new
-nodes.each_with_index { |node, i|
-  connections << [nodes[i], nodes[(i + 1) % node_num], "right"]
-  connections << [nodes[i], nodes[i - 1], "left"]
-}
-print_dot(connections)
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/ring_manager_run.sh	Tue Jan 17 20:24:46 2012 +0900
@@ -0,0 +1,12 @@
+#!/bin/bash
+max=$1
+ruby ./topology/ring.rb $1 > ./topology/ring.dot
+java -cp ../Alice.jar alice.topology.manager.TopologyManager -p 10000 -conf ./topology/ring.dot &
+
+cnt=0
+while [ $cnt -lt $max ]
+do
+    java -cp ../Alice.jar alice.test.topology.ring.RingTopology  -host `hostname` -port 10000 -p `expr 20000 + $cnt` > ./output/ring${cnt}.log &
+    cnt=`expr $cnt + 1`
+done
+wait
--- a/scripts/test.dot	Tue Jan 17 16:13:03 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,8 +0,0 @@
-digraph ring {
-	node0 -> node1 [label="right"]
-	node1 -> node0 [label="left"]
-	node1 -> node2 [label="right"]
-	node2 -> node1 [label="left"]
-	node2 -> node0 [label="right"]
-	node0 -> node2 [label="left"]
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/topology/ring.rb	Tue Jan 17 20:24:46 2012 +0900
@@ -0,0 +1,28 @@
+def create_nodes(node_num)
+  (0..node_num - 1).map { |i|
+    i = "node" + i.to_s
+  }
+end
+
+def print_dot(connections)
+  puts "digraph test {"
+  connections.each { |connection|
+    print "\t"
+    print connection[0]
+    print " -> "
+    print connection[1]
+    print ' [label="' + connection[2] + '"]'
+    puts
+  }
+  puts "}"
+end
+
+node_num = ARGV[0].to_i
+nodes = create_nodes(node_num)
+connections = Array.new
+nodes.each_with_index { |node, i|
+  connections << [nodes[i], nodes[(i + 1) % node_num], "right"]
+  connections << [nodes[i], nodes[i - 1], "left"]
+}
+print_dot(connections)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/topology/test.dot	Tue Jan 17 20:24:46 2012 +0900
@@ -0,0 +1,8 @@
+digraph ring {
+	node0 -> node1 [label="right"]
+	node1 -> node0 [label="left"]
+	node1 -> node2 [label="right"]
+	node2 -> node1 [label="left"]
+	node2 -> node0 [label="right"]
+	node0 -> node2 [label="left"]
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/topology/tree.rb	Tue Jan 17 20:24:46 2012 +0900
@@ -0,0 +1,38 @@
+def create_nodes(node_num)
+  (0..node_num - 1).map { |i|
+    i = "node" + i.to_s
+  }
+end
+
+def print_dot(connections)
+  puts "digraph test {"
+  connections.each { |connection|
+    print "\t"
+    print connection[0]
+    print " -> "
+    print connection[1]
+    print ' [label="' + connection[2] + '"]'
+    puts
+  }
+  puts "}"
+end
+
+node_num = ARGV[0].to_i
+nodes = create_nodes(node_num)
+connections = Array.new
+nodes.each_with_index { |node, i|
+  parent = (i - 1) / 2;
+  child1 = 2 * i + 1;
+  child2 = 2 * i + 2;
+  if parent >= 0 then
+    connections << [nodes[i], nodes[parent], "parent"]
+  end
+  if child1 < node_num then
+    connections << [nodes[i], nodes[child1], "child1"]
+  end
+  if child2 < node_num then
+    connections << [nodes[i], nodes[child2], "child2"]
+  end
+}
+print_dot(connections)
+
--- a/scripts/tree.rb	Tue Jan 17 16:13:03 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-def create_nodes(node_num)
-  (0..node_num - 1).map { |i|
-    i = "node" + i.to_s
-  }
-end
-
-def print_dot(connections)
-  puts "digraph test {"
-  connections.each { |connection|
-    print "\t"
-    print connection[0]
-    print " -> "
-    print connection[1]
-    print ' [label="' + connection[2] + '"]'
-    puts
-  }
-  puts "}"
-end
-
-node_num = ARGV[0].to_i
-nodes = create_nodes(node_num)
-connections = Array.new
-nodes.each_with_index { |node, i|
-  parent = (i - 1) / 2;
-  child1 = 2 * i + 1;
-  child2 = 2 * i + 2;
-  if parent < i - 1 then
-    connections << [nodes[i], nodes[parent], "parent"]
-  end
-  if child1 < node_num then
-    connections << [nodes[i], nodes[child1], "child1"]
-  end
-  if child2 < node_num then
-    connections << [nodes[i], nodes[child2], "child2"]
-  end
-}
-print_dot(connections)
-
--- a/src/alice/test/topology/ring/FirstRingMessagePassing.java	Tue Jan 17 16:13:03 2012 +0900
+++ b/src/alice/test/topology/ring/FirstRingMessagePassing.java	Tue Jan 17 20:24:46 2012 +0900
@@ -14,11 +14,7 @@
 	public void run() {
 		int counter = this.counter.asInteger();
 		System.out.println(++counter);
-		try {
-			Thread.sleep(200);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
+
 		ods.put("right", "counter", counter);
 		
 		if (counter >= 10) {
--- a/src/alice/test/topology/ring/RingMessagePassing.java	Tue Jan 17 16:13:03 2012 +0900
+++ b/src/alice/test/topology/ring/RingMessagePassing.java	Tue Jan 17 20:24:46 2012 +0900
@@ -1,5 +1,8 @@
 package alice.test.topology.ring;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 import alice.codesegment.CodeSegment;
 import alice.datasegment.CommandType;
 import alice.datasegment.DataSegmentReceiver;
@@ -11,13 +14,14 @@
 	@Override
 	public void run() {
 		int counter = this.counter.asInteger();
-		System.out.println(counter);
-
+		
+		
 		try {
-			Thread.sleep(200);
-		} catch (InterruptedException e) {
+			System.out.print("[" + InetAddress.getLocalHost().getHostName() + "] ");
+		} catch (UnknownHostException e) {
 			e.printStackTrace();
 		}
+		System.out.println(counter);
 		
 		ods.put("right", "counter", counter);
 		
--- a/src/alice/topology/manager/IncomingHosts.java	Tue Jan 17 16:13:03 2012 +0900
+++ b/src/alice/topology/manager/IncomingHosts.java	Tue Jan 17 20:24:46 2012 +0900
@@ -33,6 +33,7 @@
 		try {
 			HostMessage host = msgpack.convert(this.host.val, HostMessage.class);
 			String nodeName = nodeNames.poll();
+			// Manager connect to Node
 			DataSegmentManager manager = DataSegment.connect(nodeName, "", host.name, host.port);
 			manager.put("host", ValueFactory.createRawValue(nodeName));
 			LinkedList<NodeInfo> nodes = topology.get(nodeName);
--- a/src/alice/topology/node/IncomingConnectionInfo.java	Tue Jan 17 16:13:03 2012 +0900
+++ b/src/alice/topology/node/IncomingConnectionInfo.java	Tue Jan 17 20:24:46 2012 +0900
@@ -26,15 +26,15 @@
 	@Override
 	public void run() {
 		if (this.hostInfo.val == null) {
-			ods.put("local", "configNodeNum", ValueFactory.createIntegerValue(count));
-			
+			ods.put("local", "configNodeNum", count);
 			return;
 		}
 		MessagePack msgpack = new MessagePack();
 		try {
 			HostMessage hostInfo = msgpack.convert(this.hostInfo.val, HostMessage.class);
-			DataSegmentManager manager = DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port);
-			manager.put("reverseKey", ValueFactory.createRawValue(hostInfo.reverseName));
+			DataSegment.connect(hostInfo.connectionName, hostInfo.reverseName, hostInfo.name, hostInfo.port);
+			//manager.put("reverseKey", ValueFactory.createRawValue(hostInfo.reverseName));
+			ods.put(hostInfo.connectionName, "reverseKey", hostInfo.reverseName);
 		} catch (IOException e) {
 			e.printStackTrace();
 		}