elquenosabia
elquenosabia

Reputation: 31

java + restlet = strange performance behaviour

I have a strange behaviour with a restlet server and I can't understand what's happening!

I have a service that make basic string concatenation with datas from a mySQL database.

My code is :

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");
    }
}

When I run this batch I have something like this:

Duration of WS call:128 ms
Duration of WS call:1015 ms
Duration of WS call:1069 ms

But when this same batch runs on two different computer at the same time, I have for both batch something like this:

Duration of WS call:90 ms
Duration of WS call:92 ms
Duration of WS call:81 ms

The response is 10 x faster when two programs are querying the server instead of one !

Real example: Same batch running on two different computer:

+-----------------------------+----------------------------+
|           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
+-----------------------------+----------------------------+

Is there an explanation for this ?

Thanks in advance.

Upvotes: 2

Views: 82

Answers (1)

elquenosabia
elquenosabia

Reputation: 31

I was using the default HTTP server in org.restlet.jar wich seems to produce strange results. Since I switch to Jetty everything works as expected (average response time is 50-70 ms)

Upvotes: 1

Related Questions