Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Advantage of using NIO vs BIO in jetty?

Tags:

java

nio

jetty

Any experience on the tradeoffs in terms of nio vs bio when having heap and computationally intensive process executed for every query with execution times in (100ms-900ms) range ?


2 Answers

The real issue is how many concurrent open connections do you want to be able to scale up to per physical server (say, to support server messaging push ala Comet pattern - and who doesn't want to do that these days?). NIO will get you realistically into the 10,000 to 20,000 range. Threads are an extremely expensive resource from the OS implementation point of view (per thread memory consumption and context switching overhead). So thousands of NIO connections can be sustained with modest thread pool.

Use a NIO framework like MINA and rolling NIO is not bad at all. (Pretty darn easy actually.) I've rolled my own NIO and then also incorporated MINA. MINA is a good way to go.

http://mina.apache.org/testimonials.html

EURid used MINA during the landrush for .eu domain names on the 7th of april 2006. More than 700.000 domain names were registered during the first 4 hours. After one hour MINA had handled more than 0.5 million SSL connections.

We found the speed and stability of MINA to be excellent. And although we are still using MINA 0.8.1, we found the API very elegant and easy.

like image 136
RogerV Avatar answered Jan 27 '26 17:01

RogerV


One thing that you should take in mind, is that are some reports of bugs in JVM for NIO, which causes Jetty to hang and uses 100% of CPU. So, for now, I recommend you to stay with BIO if you see this behavior. Related links:

http://jira.codehaus.org/browse/JETTY-937

https://bugs.java.com/bugdatabase/view_bug?bug_id=6403933

like image 37
Diego Plentz Avatar answered Jan 27 '26 16:01

Diego Plentz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!