353073 parallel test option
This commit is contained in:
parent
5859a85919
commit
f17d271f07
|
@ -46,6 +46,7 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
private final String _protocol;
|
private final String _protocol;
|
||||||
private final int _timeout;
|
private final int _timeout;
|
||||||
|
|
||||||
|
private static boolean __quiet;
|
||||||
private static int __framesSent;
|
private static int __framesSent;
|
||||||
private static int __messagesSent;
|
private static int __messagesSent;
|
||||||
private static AtomicInteger __framesReceived=new AtomicInteger();
|
private static AtomicInteger __framesReceived=new AtomicInteger();
|
||||||
|
@ -76,6 +77,9 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (_connection.isClose(opcode))
|
||||||
|
return false;
|
||||||
|
|
||||||
__framesReceived.incrementAndGet();
|
__framesReceived.incrementAndGet();
|
||||||
_frames++;
|
_frames++;
|
||||||
_messageBytes+=length;
|
_messageBytes+=length;
|
||||||
|
@ -98,6 +102,7 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
while(duration<min && !__minDuration.compareAndSet(min,duration))
|
while(duration<min && !__minDuration.compareAndSet(min,duration))
|
||||||
min=__minDuration.get();
|
min=__minDuration.get();
|
||||||
__totalTime.addAndGet(duration);
|
__totalTime.addAndGet(duration);
|
||||||
|
if (!__quiet)
|
||||||
System.out.printf("%d bytes from %s: frames=%d req=%d time=%.1fms opcode=0x%s\n",_messageBytes,_host,_frames,recv,((double)duration/1000000.0),TypeUtil.toHexString(_opcode));
|
System.out.printf("%d bytes from %s: frames=%d req=%d time=%.1fms opcode=0x%s\n",_messageBytes,_host,_frames,recv,((double)duration/1000000.0),TypeUtil.toHexString(_opcode));
|
||||||
}
|
}
|
||||||
_frames=0;
|
_frames=0;
|
||||||
|
@ -118,18 +123,14 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
_handshook.countDown();
|
_handshook.countDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TestClient(String host, int port,String protocol, int timeoutMS) throws Exception
|
public TestClient(String host, int port,String protocol, int timeoutMS) throws Exception
|
||||||
{
|
{
|
||||||
_host=host;
|
_host=host;
|
||||||
_port=port;
|
_port=port;
|
||||||
_protocol=protocol;
|
_protocol=protocol;
|
||||||
_timeout=timeoutMS;
|
_timeout=timeoutMS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void open() throws Exception
|
private void open() throws Exception
|
||||||
{
|
{
|
||||||
__client.open(new URI("ws://"+_host+":"+_port+"/"),this,_protocol,_timeout);
|
__client.open(new URI("ws://"+_host+":"+_port+"/"),this,_protocol,_timeout);
|
||||||
|
@ -183,6 +184,7 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
System.err.println(" -f|--fragment n (default 4000) ");
|
System.err.println(" -f|--fragment n (default 4000) ");
|
||||||
System.err.println(" -P|--protocol echo|echo-assemble|echo-fragment|echo-broadcast");
|
System.err.println(" -P|--protocol echo|echo-assemble|echo-fragment|echo-broadcast");
|
||||||
System.err.println(" -C|--clients n (default 1) ");
|
System.err.println(" -C|--clients n (default 1) ");
|
||||||
|
System.err.println(" -d|--delay n (default 1000ms) ");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +200,7 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
int fragment=4000;
|
int fragment=4000;
|
||||||
boolean binary=false;
|
boolean binary=false;
|
||||||
int clients=1;
|
int clients=1;
|
||||||
|
int delay=1000;
|
||||||
|
|
||||||
for (int i=0;i<args.length;i++)
|
for (int i=0;i<args.length;i++)
|
||||||
{
|
{
|
||||||
|
@ -220,6 +223,10 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
binary=true;
|
binary=true;
|
||||||
else if ("-C".equals(a)||"--clients".equals(a))
|
else if ("-C".equals(a)||"--clients".equals(a))
|
||||||
clients=Integer.parseInt(args[++i]);
|
clients=Integer.parseInt(args[++i]);
|
||||||
|
else if ("-d".equals(a)||"--delay".equals(a))
|
||||||
|
delay=Integer.parseInt(args[++i]);
|
||||||
|
else if ("-q".equals(a)||"--quiet".equals(a))
|
||||||
|
__quiet=true;
|
||||||
else if (a.startsWith("-"))
|
else if (a.startsWith("-"))
|
||||||
usage(args);
|
usage(args);
|
||||||
}
|
}
|
||||||
|
@ -242,7 +249,7 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
|
|
||||||
for (int p=0;p<count;p++)
|
for (int p=0;p<count;p++)
|
||||||
{
|
{
|
||||||
long next = System.currentTimeMillis()+1000;
|
long next = System.currentTimeMillis()+delay;
|
||||||
|
|
||||||
byte opcode=binary?WebSocketConnectionD10.OP_BINARY:WebSocketConnectionD10.OP_TEXT;
|
byte opcode=binary?WebSocketConnectionD10.OP_BINARY:WebSocketConnectionD10.OP_TEXT;
|
||||||
|
|
||||||
|
@ -274,12 +281,11 @@ public class TestClient implements WebSocket.OnFrame
|
||||||
if (client[i]!=null)
|
if (client[i]!=null)
|
||||||
client[i].disconnect();
|
client[i].disconnect();
|
||||||
|
|
||||||
|
|
||||||
long duration=System.currentTimeMillis()-__start;
|
long duration=System.currentTimeMillis()-__start;
|
||||||
System.out.println("--- "+host+" websocket ping statistics using "+clients+" connection"+(clients>1?"s":"")+" ---");
|
System.out.println("--- "+host+" websocket ping statistics using "+clients+" connection"+(clients>1?"s":"")+" ---");
|
||||||
System.out.println(__framesSent+" frames transmitted, "+__framesReceived+" received, "+
|
System.out.println(__framesSent+" frames transmitted, "+__framesReceived+" received, "+
|
||||||
__messagesSent+" messages transmitted, "+__messagesReceived+" received, "+
|
__messagesSent+" messages transmitted, "+__messagesReceived+" received, "+
|
||||||
"time "+duration+"ms");
|
"time "+duration+"ms "+ (1000L*__messagesReceived.get()/duration)+" req/s");
|
||||||
System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n",__minDuration.get()/1000000.0,__messagesReceived.get()==0?0.0:(__totalTime.get()/__messagesReceived.get()/1000000.0),__maxDuration.get()/1000000.0);
|
System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n",__minDuration.get()/1000000.0,__messagesReceived.get()==0?0.0:(__totalTime.get()/__messagesReceived.get()/1000000.0),__maxDuration.get()/1000000.0);
|
||||||
|
|
||||||
__client.stop();
|
__client.stop();
|
||||||
|
|
|
@ -43,8 +43,8 @@ public class WebSocketClient extends AggregateLifeCycle
|
||||||
public WebSocketClient(ThreadPool threadpool)
|
public WebSocketClient(ThreadPool threadpool)
|
||||||
{
|
{
|
||||||
_threadPool=threadpool;
|
_threadPool=threadpool;
|
||||||
addBean(_threadPool);
|
|
||||||
addBean(_selector);
|
addBean(_selector);
|
||||||
|
addBean(_threadPool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocketClient()
|
public WebSocketClient()
|
||||||
|
@ -387,33 +387,4 @@ public class WebSocketClient extends AggregateLifeCycle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String... args) throws Exception
|
|
||||||
{
|
|
||||||
Log.getLog().setDebugEnabled(true);
|
|
||||||
|
|
||||||
|
|
||||||
WebSocketClient client = new WebSocketClient();
|
|
||||||
client.start();
|
|
||||||
|
|
||||||
client.open(new URI("ws://localhost:8080/websocket"),new WebSocket.OnTextMessage()
|
|
||||||
{
|
|
||||||
public void onOpen(org.eclipse.jetty.websocket.WebSocket.Connection connection)
|
|
||||||
{
|
|
||||||
System.err.println("onOpen "+connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClose(int closeCode, String message)
|
|
||||||
{
|
|
||||||
System.err.println("onClose "+closeCode+" "+message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onMessage(String data)
|
|
||||||
{
|
|
||||||
System.err.println("onMessage "+data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue