Now it's time to test the serial and concurrent servers and see which has a better performance. We have automatized the tests implementing four classes that make queries to the servers. These classes are:
SerialClient: This implements a possible client of the serial server. It makes nine requests using the query message and a query using the report message. It repeats the process 10 times, so it request 90 queries and 10 reports.
MultipleSerialClients: This class simulates the existence of several clients at the same time. For this, we create a thread per SerialClient and execute them at the same time to see the performance of the server. We have tested from one to five concurrent clients.
ConcurrentClient: It is analogue to the SerialClient class, but it calls the concurrent server instead of the serial one.
MultipleConcurrentClients: It is analogue to the MultipleSerialClients class, but it calls the concurrent server instead of the serial one.
To test the serial server, you can follow these steps:
Launch the serial server and wait for its initialization.
Launch the MultipleSerialClients class, which launches one, then two, three, four, and finally, five SerialClient classes.
You can follow a similar process with the concurrent server:
Launch the concurrent server and wait for its initialization.
Launch the MultipleConcurrentClients class, which launches one, two, three, four, and finally, five ConcurrentClient classes.
To compare the execution times of both versions, we have implemented a microbenchmark using the JMH framework (http://openjdk.java.net/projects/code-tools/jmh/). We have implemented two executions based in the SerialClient and ConcurrentClient tasks. We have repeated this process 10 times calculating the mean time per number of concurrent clients. We launched the tests in a computer with a processor with four cores, so it can execute four parallel tasks at the same time.
These are the results of all these executions:
The contents of the cells are the mean time of each client in seconds. We can draw the following conclusions:
The performance of both kinds of servers is affected by the number of concurrent clients that send requests to our server
In all cases, the execution times of the concurrent version are much lower than the execution times of the serial one