Test performance between Tomcat BIO and NIO connectors

169 Views Asked by At

I would like to observe the performance improvement of using NIO connector vs BIO connector on Apache Tomcat. The differences between BIO and NIO is, (quoting from DZONE),

The BIO connector (blocking I/O) is blocking – it uses a thread pool where each thread receives a request, handles it, responds, and is returned to the pool.

The NIO connector (non-blocking I/O) uses the java NIO library and multiplexes between requests. It has two thread pools – one holds the the poller threads, which handle all incoming requests and push these requests to be handled by worker threads, held in another pool.

I learnt from documentation that Apache Tomcat 7 defaults to BIO but is configurable to be used with NIO conenctor. Starting from Apache Tomcat 8.5 BIO connector is removed completely and NIO is the default considering that NIO is non blocking.

Inorder to visualize/compare the performance of BIO and NIO connector I have setup a test application that has REST API that serves response after waiting a random period of time between 1-30 seconds, and this test application is deployed on Apache Tomcat 7. I have set maxThread=300, minSpareThreads=10 under 'Executor' section of server.xml file.

I varied the tests between setting connector protocol between BIO and NIO (in settings.xml) and ran the test with a load of 5000 requests dispersed over 60 second window via Jmeter and observed the thread and cpu consumption on Jconsole, I varied the test duration with few other parameters and I expected to see NIO to consume less number of threads compared to BIO connector but I end up getting similiar results for either of the cases (NIO or BIO).

I would like to figure out the specific testcase scenario that I need to follow such that I get to observe that NIO performs better than BIO connector on Apache Tomcat 7. Much appreciated if anyone can point me in the right direction.

1

There are 1 best solutions below

2
aled On

I don't believe it is possible to give a correct answer the way the question is currently written. Probably doing stress tests NIO will behave better before breaking than BIO. But as always tests need to be done to confirm.

My recommendation would be to not try to test NIO vs BIO in an abstract use case. Test your real life applications with both in real life conditions. That will give a better idea of which configuration is better for your each type of your existing applications.