A new high throughput java executor service

September 12, 2016

The vmlens executor service is a high throughput executor service. It achieves three times higher throughput than the standard JDK executor service. The tradeoff is that the latency is much higher than that of the standard JDK executor service. Here are my benchmark results:

throughput of vmlens executor service

The figure shows the throughput of the vmlens executor Service compared to the standard JDK executor service for different threads on JDK 8.

latency of vmlens executor service

The figure shows the latency of the vmlens executor Service compared to the standard JDK executor service for different threads on JDK 8. Both benchmarks were run with jmh on an intel i5 4 core CPU. The source of the benchmark can be downloaded here

A wait-free algorithm for writing

The basic Idea is that writing should be as fast as possible. The vmlens executor Service uses a thread local field to store its last written queue node. So writing consists of creating a new QueueNode, writing to a thread local field and writing to the volatile QueueNode next field.
public class QueueManyWriters
private final ThreadLocal lastWrittenQueueNode = new ThreadLocal();
public void accept(E element)
{
if( dispatcherThread.stop )
{
throw new RejectedExecutionException();
}
QueueNode current = new QueueNode(element);
if( lastWrittenQueueNode.get() == null )
{
writingThreads.append(current,Thread.currentThread().getId());
lastWrittenQueueNode.set(new LastWrittenQueueNode(current));
}
else
{
lastWrittenQueueNode.get().last.next = current;
lastWrittenQueueNode.get().last = current;
}
}
...
}
public class QueueNode {
final E element;
volatile QueueNode next;
public QueueNode(E element) {
super();
this.element = element;
}
}
Reading is done by a single dispatcher Thread. The dispatcher collects the tasks and pushes them to one of the worker thread. For collecting the tasks the dispatcher thread uses a local list. The list contains the last read element for each writing thread.

Conclusion

The wait-free algorithm for writing leads to a three time higher throughput than the standard JDK executor service. The vmlens executor service is used in vmlens, a tool to test multithreaded application, for asynchronously writing events to disk. Whatever type of execution service you use you should test the multithreaded part of your application. Read more about testing multithreaded java code here.

testing multi-threaded applications on the JVM made easy

LEARN MORE

© 2020 vmlens Legal Notice Privacy Policy