Discussions

Performance and scalability: Thread per connection : NIO, Linux NPTL and epoll

  1. I have been benchmarking Java NIO with various JDKs on Linux. Server is
    running on a 2 CPU 1.7 GHz, 1GB RAM, Ultra160 SCSI 36GB disk

    With Linux kernel 2.6.5 (Gentoo) I had NPTL turned on and support for
    epoll compiled in. The server application was designed to support
    multiple disptach models :

    1. Reactor with Iterative Disptach with multiple selector threads. Essentially
    the accepted connections were load-balanced between varying number of
    selector threads. The benchmark then applied a step function to experimentally
    determine the optimal # of threads and connection per selector ratio.

    2. Also a simple concurrent blocking disptach model was supported. This is
    essentially a reader thread per connection model.

    Client application opens concurrent persistent connections to the server
    and starts blasting messages. Server just reads the messages and does
    basic un-marshalling to ensure message is ok.

    Results were interesting:

    1. With NPTL on, Sun and Blackwidow JVM 1.4.2 scaled easily to 5000+ threads. Blocking
    model was consistently 25-35% faster than using NIO selectors. Lot of techniques suggested
    by EmberIO folks were employed - using multiple selectors, doing multiple (2) reads if the first
    read returned EAGAIN equivalent in Java. Yet we couldn't beat the plain thread per connection model
    with Linux NPTL.

    2. To work around not so performant/scalable poll() implementation on Linux's we tried using
    epoll with Blackwidow JVM on a 2.6.5 kernel. While epoll improved the over scalability, the
    performance still remained 25% below the vanilla thread per connection model. With epoll
    we needed lot fewer threads to get to the best performance mark that we could get out of NIO.

    Here are some numbers:

    (cc = Concurrent Persistent Connections, bs = Is blocking server mode on Flag,
    st = Number of server threads, ct = Connections handled per thread,
    thruput = thruput of the server )

    cc, bs,st,ct, thruput
    1700,N,2,850,1379
    1700,N,4,425,1214
    1700,N,8,212,1240
    1700,N,16,106,1140
    1700,N,32,53,1260
    1700,N,64,26,1115
    1700,N,128,13,886
    1700,N,256,6,618
    1700,N,512,3,184
    1700,Y,1700,1,1737

    As you can see the last line indicates vanilla blocking server (thread per connection)
    produced the best thruput even with 1700 threads active in the JVM.

    With epoll, the best run was with 2 threads each handling around 850 connections in
    their selector set. But the thruput is below the blocking server thruput by 25%!

    Results shows that the cost of NIO selectors coupled with OS polling mechanism (in
    this case efficient epoll VS selector/poll) has a significant overhead compared to
    the cost of context switching 1700 threads on an NPTL Linux kernel.

    Without NPTL of course it's a different story. The blocking server just melts at 400 concurrent
    connections! We have run the test upto 10K connections and the blocking server outperformed
    NIO driven selector based server by same margin. Moral of the story - NIO arrives at the scene
    a little too late - with adequate RAM and better threading models (NPTL), performance gains
    of NIO don't show up.

    Sun's JVM doesn't support epoll() so we couldn't use epoll with it. Normal poll() based
    selector from Sun didn't perform as well. We needed to reduce the number of connections
    per thread to a small number (~ 6-10) to get comprabale numbers to epoll based selector.
    That meant running lot more selector threads kind of defeats the purpose of multiplexed IO.
    The benchmarks also dispell the myth created by Matt Welsh et al (SEDA) that a single
    threaded reactor can keep up with the network. On a 100Mbps ethernet that was true: network
    got saturated prior to server CPUs but with > 1Gbps network, we needed multiple selectors
    to saturate the network. One single selector's performance was abysmal (5-6x slower than
    concurrent connections)

    For application that want to have fewer number of threads for debuggability etc, NIO may be
    the way to go. The 25-35% performance hit may be acceptable to many apps. Fewer threads
    also means easier debugging, it's a pain to attach a profiler or a debugger to a server hosting
    1000+ threads :-) . Bottom line with better MT support in kernels (Linux already with NPTL), one
    needs to re-consider the thread per connection model

    Rahul Bhargava
    CTO, Rascal Systems

    Threaded Messages (28)

  2. History[ Go to top ]

    History

    Before the 2.6 version of the Linux kernel, processes were the schedulable entities, and there was no real support for threads. However, it did support a system callclone — which creates a copy of the calling process where the copy shares the address space of the caller. The LinuxThreads project used this system call to provide kernel-level thread support (most of the previous pthread implementations in Linux worked entirely in userland). Unfortunately, it had a number of issues with true POSIX compliance, particularly in the areas of signal handling, scheduling, and inter-process synchronization primitives.

    To improve upon LinuxThreads, it was clear that some kernel support and a re-written threads library would be required. Two competing projects were started to address the requirement: NGPT (Next Generation POSIX Threads) worked on by a team which included developers from IBM, and NPTL by developers at Red Hat. NGPT was abandoned in mid-2003, at about the same time when NPTL was released.

    NPTL was first released in Red Hat Linux 9. Old-style Linux POSIX threading is known for having trouble with threads that refuse to yield to the system occasionally, because it does not take the opportunity to preempt them when it arises, something that Windows was known to do better at the time. Red Hat claimed that NPTL fixed this problem in an article on the Java website about Java on Red Hat Linux 9.[3]

    NPTL has been part of Red Hat Enterprise Linux since version 3, and in the Linux kernel since version 2.6. It is now a fully integrated part of the GNU C Library.

    There exists a tracing tool for NPTL, called POSIX Thread Trace Tool (PTT). And an Open POSIX Test Suite (OPTS) was written for testing the NPTL library against the POSIX standard.

     

  3. nice talk about EJB[ Go to top ]

    EJB servers are required to support the UserTransaction interface for use by EJB beans with the BEAN value in the @TransactionManagement annotation (this is called bean-managed transactions or BMT). The UserTransaction interface is exposed to EJB components through either the EJBContext interface using the getUserTransaction method, or directly via injection using the general @Resource annotation. Thus, an EJB application does not interface with the Transaction Manager directly for transaction demarcation; instead, the EJB bean relies on the EJB server to provide support for all of its transaction work as defined in the Enterprise JavaBeans Specification. (The underlying interaction between the EJB Server and the TM is transparent to the application; the burden of implementing transaction management is on the EJB container and server provider.

  4. Perfect![ Go to top ]

    Completely agree with this guy! Portable Dishwasher

  5. jas and java[ Go to top ]

    You said everything I wanted to say. I leave here my website jogos, realize my job as CEO of the corporation Bravanet

  6. About Site[ Go to top ]

    This Site Really helpful site

    i really enjoyed a lot's while reading post's on your site

    Thnak's John

  7. My son is going to be aspect of an excellent research overseas system in Oxford. He will be learning the Western and international financial systems as well as the govt framework of the biggest nations. He desired to do some planning before he remaining next drop and I had observed from a companion that the Collection of The legislature has classes available. Are these classes available to anyone? Are they online? trendsandgadgets.net

  8. We love linux[ Go to top ]

    Thanks for this informative article. You can also visit my sexo site.

  9. good articale[ Go to top ]

    I am happy when reading your blog with updated information!
    thanks alot and hope that you will post more site that are related to this site

     

     

     


    <a href="http://thebesthairregrowthproducts.com/">hair regrowth</a>

     

  10. New Version[ Go to top ]

    Expecting for the newest version. Hope with more features if there is one. custom home builder | home remodeling

  11. Linux the best[ Go to top ]

    Thanks for this information. Linux is really powerfull os.

    megahair

  12. linux[ Go to top ]

    I totally agree. Been around forever too <a href="http://www.teethwhiteningkits2you.co.uk/Crest-Whitening-Strips/c6/index.html">crest whitening strips</a>

  13. linux[ Go to top ]

    And it's easy  

    <a href="http://www.teethwhiteningkits2you.co.uk/Crest-Whitening-Strips/c6/index.html" title="crest whitening strips">crest whitening strips</a> 

  14. Bangalore escort[ Go to top ]

    am in the middle of working on a school report on this topic and your post has helped me with the information I needed to complete it. Thanks.Bangalore escort

  15. crush four[ Go to top ]

    Prolimehost is a leading provider of Web hosting solutions and services, like Cheap Dedicated Servers, Cpanel Dedicated Servers, low cost dedicated server,Windows and linux Dedicated Servers, best email game and virtual dedicated server. crush four

  16. Hire Car Delhi[ Go to top ]

    I agree with you. This post is truly inspiring. I like your post and everything you share with us is current and very informative, I want to bookmark the page so I can return here from you that you have done a fantastic job

    Car Hire Delhi || Delhi Taxi || Delhi Cabs || Hire Car Delhi || Car On Rent Delhi || Car Rental Delhi || Taxi Service Delhi  || Cabs In Delhi

    Taxi Gurgaon || Gurgaon Cabs

  17. great[ Go to top ]

    this is very informative "Reactor with Iterative Disptach with multiple selector threads. Essentially
    the accepted connections were load-balanced between varying number of
    selector threads. The benchmark then applied a step function to experimentally
    determine the optimal # of threads and connection per selector ratio"..thanks for sharing 

    http://www.magnumholidays.co.uk

  18. Fantastic !!![ Go to top ]

    hanks for taking the time to post such valuable information.
    Quality content is what always gets the visitors coming. And
    I am waiting for this. See you next week http://www.moncleroutletsit.com

  19. Linux is a great tool[ Go to top ]

    I look forward to more such articles. I looked here often. to read :)

    <a href="http://poza-bankowe.pl" target="_blank">Po?yczki pod zastaw nieruchomo?ci</a> | <a href="http://poza-bankowe.pl/pod-zastaw-mieszkania" target="_blank">Pod zastaw mieszkania</a> | <a href="http://poza-bankowe.pl/pod-zastaw-domu" target="_blank">Pod zastaw domu</a> | <a href="http://poza-bankowe.pl/pod-zastaw-dzia?ki" target="_blank">Pod zastaw Dzia?ki</a>

  20. Design a custom dress shirts that fits you exactly the way you want. Superb custom mens dress shirt fabrics, fine stitching quality that brings perfect custom made ... CustomizedDressShirts.com

  21. I need to read more on this topic…I admiring time and effort you put in your blog, because it is obviously one great place where I can find lot of useful info 

    user guide manual pdf download | interior home design ideas My problem has been resolved.I do agree with all of the ideas you have introduced for your post. They're really convincing and will definitely work

  22. Kios Kaos[ Go to top ]

    a nice article to our knowledge in the sophisticated technology like this now, If you want to buy motivation t-shirts please visit <a href="http://www.kioskaos.net/blog/kaos-motivasi" title="Kaos Motivasi">Kaos Motivasi</a>

  23. Kios Kaos[ Go to top ]

    a nice article to our knowledge in the sophisticated technology like this now, If you want to buy motivation t-shirts please visit www.kioskaos.net/blog/kaos-motivasi

  24. Kios Kaos[ Go to top ]

    Please visit Kaos Motivasi

  25. It was great to land on this blog post and to read such amazing stuff. Your blog is full of authentic and highly-researched information that is worth reading.
    Source: body massage and body scrub for further information.

  26. A great workout schedule is hard to beat, your fitness is your best asset. Is there any tips you could recommend for high elevation training?
    Source: mengatasi kulit kering and mengatasi kulit kering for enother information.

  27. With exercise bike like this, I can feel the respiratory system that is better than before exercise. Therefore I think there is no harm if we change the unhealthy lifestyle that we've run with a healthy lifestyle.
    Source: perawatan kulit and perawatan kulit cantik for further information.

  28. good post[ Go to top ]

    obat dari herbal sakit maag obat dari herbal untuk nyeri sendi jual madu untuk diabetes habbasyifa murah jual habbatussasuda cap kurma ajwa obat herbal untuk sakit diabetes ekstrak sambiloto kapsul jual obat herbal dimana toko herbal yang murah tempat toko herbal jakarta toko obat herbal terlengkap herbal penurun panas dingin jual daun sirsak obat kanker kunyit obat maag alami teh kulit manggis alami ramuan dari herbal kolesterol tempat beli keladi tikus untuk apa madu randu lokasi jual madu asli tempat sari kurma jazira sari kurma sahara asli habbatussauda murni minyak zaitun beli dimana tempat madu anak syamil sari kurma al jazira premium asli obat herbal untuk kanker payudara alami teh daun sirsak mujarab teh jati daun china asli teh jati belanda alami     arti syamil dates honey pelangsing herbal asli sari kurma tamr terbaik

  29. go[ Go to top ]

    best place to invest money yeah go cos we want u now invest money...fav song