Showing
1 changed file
with
29 additions
and
2 deletions
... | @@ -2,16 +2,43 @@ package org.onlab.netty; | ... | @@ -2,16 +2,43 @@ package org.onlab.netty; |
2 | 2 | ||
3 | import java.util.concurrent.TimeUnit; | 3 | import java.util.concurrent.TimeUnit; |
4 | 4 | ||
5 | +import org.onlab.metrics.MetricsComponent; | ||
6 | +import org.onlab.metrics.MetricsFeature; | ||
7 | +import org.onlab.metrics.MetricsManager; | ||
8 | + | ||
9 | +import com.codahale.metrics.Timer; | ||
10 | + | ||
5 | public final class SimpleClient { | 11 | public final class SimpleClient { |
6 | private SimpleClient() {} | 12 | private SimpleClient() {} |
7 | 13 | ||
8 | public static void main(String... args) throws Exception { | 14 | public static void main(String... args) throws Exception { |
9 | NettyMessagingService messaging = new TestNettyMessagingService(9081); | 15 | NettyMessagingService messaging = new TestNettyMessagingService(9081); |
16 | + MetricsManager metrics = new MetricsManager(); | ||
10 | messaging.activate(); | 17 | messaging.activate(); |
11 | - | 18 | + metrics.activate(); |
19 | + MetricsFeature feature = new MetricsFeature("timers"); | ||
20 | + MetricsComponent component = metrics.registerComponent("NettyMessaging"); | ||
21 | + Timer sendAsyncTimer = metrics.createTimer(component, feature, "AsyncSender"); | ||
22 | + final int warmup = 100; | ||
23 | + for (int i = 0; i < warmup; i++) { | ||
24 | + Timer.Context context = sendAsyncTimer.time(); | ||
12 | messaging.sendAsync(new Endpoint("localhost", 8080), "simple", "Hello World"); | 25 | messaging.sendAsync(new Endpoint("localhost", 8080), "simple", "Hello World"); |
13 | - Response<String> response = messaging.sendAndReceive(new Endpoint("localhost", 8080), "echo", "Hello World"); | 26 | + context.stop(); |
27 | + } | ||
28 | + metrics.registerMetric(component, feature, "AsyncTimer", sendAsyncTimer); | ||
29 | + | ||
30 | + Timer sendAndRecieveTimer = metrics.createTimer(component, feature, "SendAndReceive"); | ||
31 | + final int iterations = 1000000; | ||
32 | + for (int i=0; i < iterations; i++) { | ||
33 | + Timer.Context context = sendAndRecieveTimer.time(); | ||
34 | + Response<String> response = messaging | ||
35 | + .sendAndReceive(new Endpoint("localhost", 8080), "echo", | ||
36 | + "Hello World"); | ||
14 | System.out.println("Got back:" + response.get(2, TimeUnit.SECONDS)); | 37 | System.out.println("Got back:" + response.get(2, TimeUnit.SECONDS)); |
38 | + context.stop(); | ||
39 | + } | ||
40 | + metrics.registerMetric(component, feature, "AsyncTimer", sendAndRecieveTimer); | ||
41 | + | ||
15 | } | 42 | } |
16 | 43 | ||
17 | public static class TestNettyMessagingService extends NettyMessagingService { | 44 | public static class TestNettyMessagingService extends NettyMessagingService { | ... | ... |
-
Please register or login to post a comment