1
2
3
4
5
6 package functional.performance;
7
8
9 import java.net.InetAddress;
10
11 import junit.framework.TestCase;
12
13 import org.neo.swarm.ApplicationContext;
14 import org.neo.swarm.SwarmContainer;
15 import org.neo.swarm.config.SimpleConfig;
16
17 /***
18 * Provides facility to test various container configurations with relative performance stats within a single VM.
19 * @author neil.avery
20 */
21 public class PerformanceTest extends TestCase {
22 SwarmContainer swarm1;
23 SwarmContainer swarm2;
24 int javaSpeed = 0;
25 int limit = 1000;
26 double localSpeed = 0;
27
28
29
30
31
32
33
34
35 protected void setUp() throws Exception {
36 swarm1 = new SimpleConfig("swarm1", InetAddress.getLocalHost(), 8081, InetAddress.getLocalHost(), 8082, false).setup();
37 swarm2 = new SimpleConfig("swarm2", InetAddress.getLocalHost(), 8082, InetAddress.getLocalHost(), 8081, false).setup();
38 ApplicationContext ac = swarm1.getAppContext("swarm1");
39
40
41
42
43 ac.addCachedComponent("compB", ComponentB.class);
44 swarm1.start();
45 swarm2.start();
46 Thread.sleep(3 * 1000);
47 }
48
49
50
51
52 protected void tearDown() throws Exception {
53 if (swarm1 != null) swarm1.stop();
54 if (swarm2 != null) swarm2.stop();
55 }
56 /***
57 * Compare Java, Local, and Remote invocation throughput.
58 */
59 public void _testRawInvocationPerformance() throws Exception {
60
61
62 long startTime = System.currentTimeMillis();
63
64 ComponentBI compB1 = new ComponentB();
65 startTime = System.currentTimeMillis();
66 System.out.println(" ============== starting java test =================");
67 for (int i = 0; i < limit; i++) {
68 compB1.doFastStuff(i);
69 }
70
71 double elapsed = (System.currentTimeMillis() - startTime)/1000.0;
72 System.out.println("elapsed time:" + elapsed);
73 System.out.println(" rate:" + limit/elapsed + "invocations/sec");
74 javaSpeed = new Double(limit/elapsed).intValue();
75 }
76
77 public void _testLocalPerformance() throws Exception {
78
79 ComponentBI compB2 = (ComponentBI) swarm1.getComponent("compB");
80 long startTime = System.currentTimeMillis();
81 System.out.println(" ============== starting local test =================");
82 for (int i = 0; i < limit; i++) {
83 compB2.doFastStuff(i);
84 }
85 double elapsed = (System.currentTimeMillis() - startTime)/1000.0;
86 System.out.println("elapsed time:" + elapsed);
87 System.out.println(" rate:" + limit/elapsed + "invocations/sec");
88 localSpeed = limit/elapsed;
89 System.out.println("elapsed time:" + elapsed);
90 System.out.println(" rate:" + limit/elapsed + "invocations/sec");
91
92 }
93
94 public void testRemotingSpeed() throws Exception {
95
96 ComponentBI compB3 = (ComponentBI) swarm2.getComponent("compB");
97 long startTime = System.currentTimeMillis();
98
99
100
101 System.out.println(" ============== starting remoting test =================");
102 for (int i = 0; i < limit; i++) {
103 compB3.doFastStuff(i);
104 }
105 double elapsed = (System.currentTimeMillis() - startTime)/1000.0;
106 System.out.println("elapsed time:" + elapsed);
107 System.out.println(" rate:" + limit/elapsed + "invocations/sec");
108 double remotingSpeed = limit/elapsed;
109
110
111 System.out.println(" ============== relative performance to raw java =================");
112 System.out.println(" Java:1 \t SILC Local: " + localSpeed/javaSpeed + " \t SILC Remote: " + remotingSpeed/javaSpeed);
113
114 }
115
116 }