使用Linux NPTL的Java I / O与Java新I / O(NIO) [英] Java I/O vs. Java new I/O (NIO) with Linux NPTL

查看:142
本文介绍了使用Linux NPTL的Java I / O与Java新I / O(NIO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络服务器使用通常的Java I / O和每个连接线程机制。如今,他们越来越user with用户(长轮询连接)。但是,连接大多是空闲的。虽然可以通过添加更多网络服务器来解决这个问题,但我一直在尝试对 NIO进行一些研究实施。

My webservers use the usual Java I/O with thread per connection mechanism. Nowadays, they are getting on their knees with increased user (long polling connection). However, the connections are mostly idle. While this can be solved by adding more webservers, I have been trying to do some research on the NIO implementation.

我对此印象不一。我读过基准测试,其中Linux中新的 NPTL 库的常规I / O优于NIO。

I got a mixed impression about it. I have read about benchmarks where regular I/O with the new NPTL library in Linux outperforms NIO.

使用Java I / O配置和使用最新的NPTL for Linux有什么真实的体验?是否有任何提升的表现?

What is the real life experience of configuring and using the latest NPTL for Linux with Java I/O? Is there any increased performance?

并且在更大范围的问题上:

I / O和阻塞线程的最大数量是什么(我们在 Tomcat中配置)我们希望在标准服务器类机器(带有四核处理器的戴尔)中使用线程池(使用Linux NPTL库吗?)。如果线程池变得非常大,比如超过1000个线程会有什么影响?

What is the maximum number of I/O and blocking threads (that we configure in the Tomcat thread pool) in a standard server class machine (Dell with a quad-core processor) we expect to perform normally (with Linux NPTL library?). What's the impact if the threadpool gets really big, say more than 1000 threads?

任何引用和指针都将非常受欢迎。

Any references and pointers will be very much appreciated.

推荐答案

挑衅博客帖子, 避免使用NIO,获得更好的吞吐量。 Paul Tyma的(2008)博客声称〜5000个线程没有任何麻烦;我听说人们声称更多:

Provocative blog posting, "Avoid NIO, get better throughput." Paul Tyma's(2008) blog claims ~5000 threads without any trouble; I've heard folks claim more:



  1. 随着NPTL打开,Sun和Blackwidow JVM 1.4.2很容易扩展到5000+
    个主题。阻塞模型的价格是
    ,比使用
    NIO选择器的速度快25-35%。很多技术
    由EmberIO人员建议使用
    - 使用多个选择器,
    执行多次(2)读取,如果第一个
    读取返回EAGAIN等价于
    Java。然而,我们无法用Linux
    NPTL击败每个连接模型的普通
    线程。


我认为这里的关键是 衡量开销和性能 ,并且只有在您知道需要并且可以证明改进时才转移到非阻塞I / O.编写和维护非阻塞代码的额外工作应该考虑在内。我的看法是,如果你的应用程序可以使用同步/阻塞I / O干净地表达,那就是。如果您的应用程序适用于非阻塞I / O,您不仅会在应用程序空间中重新发明阻塞I / O,而是根据测量的性能需求考虑转移到nio 当我浏览谷歌搜索结果时,我很惊讶这几个资源实际上引用了任何(最近的)数字

I think the key here is to measure the overhead and performance, and make the move to non-blocking I/O only when you know you need to and can demonstrate an improvement. The additional effort to write and maintain non-blocking code should be factored in to your decision. My take is, if your application can be cleanly expressed using synchronous/blocking I/O, DO THAT. If your application is amenable to non-blocking I/O and you won't just be re-inventing blocking I/O badly in application-space, CONSIDER moving to nio based on measured performance needs. I'm amazed when I poke around the google results for this how few of the resources actually cite any (recent) numbers!

此外,请参阅 Paul Tyma的演示幻灯片:旧的方式再次出现。基于他在谷歌的工作,具体的数字表明同步线程I / O在Linux上具有相当大的可扩展性,并认为NIO更快是一段时间的真实,但不再是。一些很好的额外评论这里有关于Comet Daily 。他引用了以下内容(轶事,仍然没有与基准等有关的固定链接......)NPTL上的结果:

Also, see Paul Tyma's presentation slides: The old way is new again. Based on his work at Google, concrete numbers suggest that synchronous threaded I/O is quite scalable on Linux, and consider "NIO is faster" a myth that was true for awhile, but no longer. Some good additional commentary here on Comet Daily. He cites the following (anecdotal, still no solid link to benchmarks, etc...) result on NPTL:


在测试中,NPTL成功在两个
秒内在IA-32上启动
100,000个线程。相比之下,在没有NPTL的内核下测试
将在15分钟内获得

In tests, NPTL succeeded in starting 100,000 threads on a IA-32 in two seconds. In comparison, this test under a kernel without NPTL would have taken around 15 minutes

如果你真的正在遇到可扩展性问题,你可能想要使用 rel =nofollow noreferrer> XX:ThreadStackSize 。由于你提到 Tomcat,请看这里

If you really are running into scalability problems, you may want to tune the thread stack size using XX:ThreadStackSize. Since you mention Tomcat see here.

最后,如果您受到约束并决定使用非阻塞I / O,请尽一切努力构建知道他们正在做什么的人的框架。我浪费了太多时间来试图获得一个错综复杂的非阻塞I / O解决方案(出于错误的原因)。

Finally, if you're bound and determined to use non-blocking I/O, make every effort to build on an existing framework by people who know what they're doing. I've wasted far too much of my own time trying to get an intricate non-blocking I/O solution right (for the wrong reasons).

参见与SO相关

这篇关于使用Linux NPTL的Java I / O与Java新I / O(NIO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆