Comparing the two solutions

Now it's time to test the serial and concurrent server and see which has a better performance. We have automated the tests by 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 requests 90 queries and 10 reports.
  • MultipleSerialClients: This class simulates the existence of several clients at the same time. For this, we create a thread for each 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: This is analogous to the SerialClient class, but it calls the concurrent server instead of the serial one.
  • MultipleConcurrentClients: This is analogous 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:

  1. Launch the serial server and wait for its initialization.
  2. 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:

  1. Launch the concurrent server and wait for its initialization.
  2. 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/) that allows you to implement microbenchmarks in Java. Using a framework for benchmarking is a better solution that simply measures time using methods such as currentTimeMillis() or nanoTime(). We have executed them 10 times in two different architectures:

  • A computer with an Intel Core i5-5300 CPU with Windows 7 and 16 GB of RAM. This processor has two cores and each core can execute two threads, so we will have four parallel threads.
  • A computer with an AMD A8-640 APU with Windows 10 and 8 GB of RAM. This processor has four cores.

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:

  • Execution times in both architectures are very different. Take into account that there are more elements, such as the hard disk, the memory, or the operating system, that can affect the performance. In both cases, speedup is very similar.
  • 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.