Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
pankaj
2014-10-07 14:24:22 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f49b45e893f1bd52a06ef05a7d90d0279fdbb7f8
f49b45e8
1 parent
221e64e4
Added simple netty client/servers to foo app to measure performance
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
159 additions
and
15 deletions
apps/foo/pom.xml
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServerCommand.java
apps/foo/pom.xml
View file @
f49b45e
...
...
@@ -28,6 +28,11 @@
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.onlab.onos
</groupId>
<artifactId>
onlab-netty
</artifactId>
<version>
${project.version}
</version>
</dependency>
<dependency>
<groupId>
org.apache.karaf.shell
</groupId>
<artifactId>
org.apache.karaf.shell.console
</artifactId>
</dependency>
...
...
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClient.java
0 → 100644
View file @
f49b45e
package
org
.
onlab
.
onos
.
foo
;
import
java.io.IOException
;
import
java.util.concurrent.ExecutionException
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeoutException
;
import
org.onlab.metrics.MetricsComponent
;
import
org.onlab.metrics.MetricsFeature
;
import
org.onlab.metrics.MetricsManager
;
import
org.onlab.netty.Endpoint
;
import
org.onlab.netty.NettyMessagingService
;
import
org.onlab.netty.Response
;
import
com.codahale.metrics.Timer
;
// FIXME: Should be move out to test or app
public
final
class
SimpleNettyClient
{
private
SimpleNettyClient
()
{
}
public
static
void
main
(
String
[]
args
)
throws
IOException
,
InterruptedException
,
ExecutionException
,
TimeoutException
{
try
{
startStandalone
(
args
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
System
.
exit
(
0
);
}
public
static
void
startStandalone
(
String
...
args
)
throws
Exception
{
NettyMessagingService
messaging
=
new
TestNettyMessagingService
(
9081
);
MetricsManager
metrics
=
new
MetricsManager
();
messaging
.
activate
();
metrics
.
activate
();
MetricsFeature
feature
=
new
MetricsFeature
(
"timers"
);
MetricsComponent
component
=
metrics
.
registerComponent
(
"NettyMessaging"
);
Timer
sendAsyncTimer
=
metrics
.
createTimer
(
component
,
feature
,
"AsyncSender"
);
final
int
warmup
=
100
;
for
(
int
i
=
0
;
i
<
warmup
;
i
++)
{
Timer
.
Context
context
=
sendAsyncTimer
.
time
();
messaging
.
sendAsync
(
new
Endpoint
(
"localhost"
,
8080
),
"simple"
,
"Hello World"
.
getBytes
());
context
.
stop
();
}
metrics
.
registerMetric
(
component
,
feature
,
"AsyncTimer"
,
sendAsyncTimer
);
Timer
sendAndReceiveTimer
=
metrics
.
createTimer
(
component
,
feature
,
"SendAndReceive"
);
final
int
iterations
=
1000000
;
for
(
int
i
=
0
;
i
<
iterations
;
i
++)
{
Timer
.
Context
context
=
sendAndReceiveTimer
.
time
();
Response
response
=
messaging
.
sendAndReceive
(
new
Endpoint
(
"localhost"
,
8080
),
"echo"
,
"Hello World"
.
getBytes
());
System
.
out
.
println
(
"Got back:"
+
new
String
(
response
.
get
(
2
,
TimeUnit
.
SECONDS
)));
context
.
stop
();
}
metrics
.
registerMetric
(
component
,
feature
,
"AsyncTimer"
,
sendAndReceiveTimer
);
}
public
static
class
TestNettyMessagingService
extends
NettyMessagingService
{
public
TestNettyMessagingService
(
int
port
)
throws
Exception
{
super
(
port
);
}
}
}
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyClientCommand.java
0 → 100644
View file @
f49b45e
package
org
.
onlab
.
onos
.
foo
;
import
static
org
.
onlab
.
onos
.
foo
.
SimpleNettyClient
.
startStandalone
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
/**
* Test Netty client performance.
*/
@Command
(
scope
=
"onos"
,
name
=
"simple-netty-client"
,
description
=
"Starts the simple Netty client"
)
public
class
SimpleNettyClientCommand
extends
AbstractShellCommand
{
@Argument
(
index
=
0
,
name
=
"serverIp"
,
description
=
"Server IP address"
,
required
=
false
,
multiValued
=
false
)
String
serverIp
=
"127.0.0.1"
;
@Argument
(
index
=
1
,
name
=
"workers"
,
description
=
"IO workers"
,
required
=
false
,
multiValued
=
false
)
String
workers
=
"6"
;
@Argument
(
index
=
2
,
name
=
"messageCount"
,
description
=
"Message count"
,
required
=
false
,
multiValued
=
false
)
String
messageCount
=
"1000000"
;
@Argument
(
index
=
3
,
name
=
"messageLength"
,
description
=
"Message length (bytes)"
,
required
=
false
,
multiValued
=
false
)
String
messageLength
=
"128"
;
@Argument
(
index
=
4
,
name
=
"timeoutSecs"
,
description
=
"Test timeout (seconds)"
,
required
=
false
,
multiValued
=
false
)
String
timeoutSecs
=
"60"
;
@Override
protected
void
execute
()
{
try
{
startStandalone
(
new
String
[]{
serverIp
,
workers
,
messageCount
,
messageLength
,
timeoutSecs
});
}
catch
(
Exception
e
)
{
error
(
"Unable to start client %s"
,
e
);
}
}
}
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServer.java
View file @
f49b45e
package
org
.
onlab
.
onos
.
foo
;
import
java.io.IOException
;
import
org.jboss.netty.handler.logging.LoggingHandler
;
import
org.onlab.netty.EchoHandler
;
import
org.onlab.netty.KryoSerializer
;
import
org.onlab.netty.NettyMessagingService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -22,17 +18,11 @@ import org.slf4j.LoggerFactory;
System
.
exit
(
0
);
}
public
static
void
startStandalone
(
String
[]
args
)
throws
IOException
{
NettyMessagingService
server
=
new
NettyMessagingService
(
8080
);
try
{
server
.
activate
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
server
.
setSerializer
(
new
KryoSerializer
());
server
.
registerHandler
(
"simple"
,
(
org
.
onlab
.
netty
.
MessageHandler
)
new
LoggingHandler
());
server
.
registerHandler
(
"echo"
,
new
EchoHandler
());
public
static
void
startStandalone
(
String
[]
args
)
throws
Exception
{
NettyMessagingService
server
=
new
NettyMessagingService
(
8080
);
server
.
activate
();
server
.
registerHandler
(
"simple"
,
new
org
.
onlab
.
netty
.
LoggingHandler
());
server
.
registerHandler
(
"echo"
,
new
EchoHandler
());
}
}
...
...
apps/foo/src/main/java/org/onlab/onos/foo/SimpleNettyServerCommand.java
0 → 100644
View file @
f49b45e
package
org
.
onlab
.
onos
.
foo
;
import
static
org
.
onlab
.
onos
.
foo
.
SimpleNettyServer
.
startStandalone
;
import
org.apache.karaf.shell.commands.Argument
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cli.AbstractShellCommand
;
/**
* Starts the Simple Netty server.
*/
@Command
(
scope
=
"onos"
,
name
=
"test-netty-server"
,
description
=
"Starts the simple netty server"
)
public
class
SimpleNettyServerCommand
extends
AbstractShellCommand
{
@Argument
(
index
=
0
,
name
=
"serverIp"
,
description
=
"Server IP address"
,
required
=
false
,
multiValued
=
false
)
String
serverIp
=
"127.0.0.1"
;
@Argument
(
index
=
1
,
name
=
"workers"
,
description
=
"IO workers"
,
required
=
false
,
multiValued
=
false
)
String
workers
=
"6"
;
@Argument
(
index
=
2
,
name
=
"messageLength"
,
description
=
"Message length (bytes)"
,
required
=
false
,
multiValued
=
false
)
String
messageLength
=
"128"
;
@Override
protected
void
execute
()
{
try
{
startStandalone
(
new
String
[]{
serverIp
,
workers
,
messageLength
});
}
catch
(
Exception
e
)
{
error
(
"Unable to start server %s"
,
e
);
}
}
}
Please
register
or
login
to post a comment