我对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
+-----------------------------+----------------------------+
对此有解释吗?
提前致谢。
答案 0 :(得分:1)
我在org.restlet.jar中使用默认的HTTP服务器,似乎产生了奇怪的结果。由于我切换到Jetty,一切都按预期工作(平均响应时间为50-70毫秒)