我对restlet服务器有一种奇怪的行为,我不明白发生了什么!
我有一个服务,可以将基本字符串与mySQL数据库中的数据连接起来。
我的代码是:
private static void testWS() throws Exception {
Client client = new Client(Protocol.HTTP);
for (String id : listIds) {
long startTime = System.nanoTime();
Request request = new Request(Method.GET, REST_SERVICE + id);
Response response = client.handle(request);
long endTime = System.nanoTime();
System.out.println("Duration of WS call:" + ((endTime - startTime) / 1000000) + " ms");
}
}
当我运行这个批时,我有这样的东西:
Duration of WS call:128 ms
Duration of WS call:1015 ms
Duration of WS call:1069 ms
但是,当同一批数据同时在两台不同的计算机上运行时,对于这两个批数据,我必须这样做:
Duration of WS call:90 ms
Duration of WS call:92 ms
Duration of WS call:81 ms
当两个程序查询服务器而不是一个程序时,响应速度会快10倍!
实例:同一批在两台不同的计算机上运行:
+-----------------------------+----------------------------+
| Batch 1 | Batch 2 |
+-----------------------------+----------------------------+
| Duration of WS call:128 ms | | Start of Batch1
| Duration of WS call:1015 ms | |
| Duration of WS call:1010 ms | |
| Duration of WS call:1012 ms | |
| Duration of WS call:1031 ms | |
| Duration of WS call:1036 ms | |
| Duration of WS call:834 ms | |
| Duration of WS call:90 ms | Duration of WS call:75 ms | Start of Batch2
| Duration of WS call:92 ms | Duration of WS call:82 ms |
| Duration of WS call:81 ms | Duration of WS call:85 ms |
| Duration of WS call:89 ms | Duration of WS call:82 ms |
| Duration of WS call:146 ms | Duration of WS call:90 ms |
| Duration of WS call:92 ms | Duration of WS call:85 ms |
| Duration of WS call:85 ms | Duration of WS call:76 ms |
| Duration of WS call:28 ms | Duration of WS call:96 ms |
| Duration of WS call:165 ms | Duration of WS call:88 ms |
| Duration of WS call:78 ms | Duration of WS call:84 ms |
| Duration of WS call:85 ms | Duration of WS call:63 ms |
| Duration of WS call:103 ms | Duration of WS call:37 ms |
| Duration of WS call:129 ms | Duration of WS call:74 ms |
| Duration of WS call:73 ms | Duration of WS call:140 ms | Batch2 manually stopped
| Duration of WS call:1058 ms | |
| Duration of WS call:1016 ms | |
| Duration of WS call:1006 ms | |
| Duration of WS call:1020 ms | |
| Duration of WS call:1055 ms | |
| Duration of WS call:958 ms | |
| Duration of WS call:1003 ms | | End of Batch1
+-----------------------------+----------------------------+
有什么解释吗?
提前谢谢。
最佳答案
我在org.restlet.jar wich中使用的默认HTTP服务器似乎产生了奇怪的结果。因为我切换到Jetty,所以一切工作正常(平均响应时间为50-70ms)
关于java - java + reSTLet =奇怪的性能行为,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29282431/