每个连接模式VS NIO Java线程 [英] Java thread per connection model vs NIO

查看:164
本文介绍了每个连接模式VS NIO Java线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是非阻塞的Java NIO仍高于每个连接异步套接字的标准螺纹慢?

Is the non-blocking Java NIO still slower than your standard thread per connection asynchronous socket?

此外,如果你使用线程每个连接,你只需要创建新的线程或你会用一个非常大的线程池?

In addition, if you were to use threads per connection, would you just create new threads or would you use a very large thread pool?

我在写Java中的MMORPG服务器应该能够扩展10000客户轻易的强大足够的硬件,虽然客户的最高金额为24000(我认为这是不可能达到每连接模型线程因Java中的15000线程限制)。
从三岁的文章中,我听说每个连接模型线程阻塞IO仍然比NIO(即本文件<快25% href=\"http://www.mailinator.com/tymaPaulMultithreaded.pdf\">http://www.mailinator.com/tymaPaulMultithreaded.pdf),但可以在同一个仍然在这一天能实现吗?从那时起,Java已经改变了很多,我也听说过,结果比较真实的生活场景时,因为虚拟机使用的不是的Sun Java是可疑的。
同时,由于它与许多并发用户相互交互的MMORPG服务器,将采用同步和线程安全的做法降低产品的性能到一个单线程NIO选择服务10000客户会更快一点? (所有的工作并不需要必须与选择的线程上处理,它可以在工作线程像MINA / Netty的是如何工作的处理)。

I'm writing an MMORPG server in Java that should be able to scale 10000 clients easily given powerful enough hardware, although the maximum amount of clients is 24000 (which I believe is impossible to reach for the thread per connection model because of a 15000 thread limit in Java). From a three year old article, I've heard that blocking IO with a thread per connection model was still 25% faster than NIO (namely, this document http://www.mailinator.com/tymaPaulMultithreaded.pdf), but can the same still be achieved on this day? Java has changed a lot since then, and I've heard that the results were questionable when comparing real life scenarios because the VM used was not Sun Java. Also, because it is an MMORPG server with many concurrent users interacting with each other, will the use of synchronization and thread safety practices decrease performance to the point where a single threaded NIO selector serving 10000 clients will be faster? (all the work doesn't necessary have to be processed on the thread with the selector, it can be processed on worker threads like how MINA/Netty works).

谢谢!

推荐答案

NIO的利益应采取一粒盐。

NIO benefits should be taken with a grain of salt.

在一个HTTP服务器,大多数连接保持活动的连接,他们是最空闲的时候。这将是资源的浪费,以pre-分配一个线程每个

In a HTTP server, most connections are keep-alive connections, they are idle most of times. It would be a waste of resource to pre-allocate a thread for each.

有关MMORPG的东西有很大的不同。我想连接不断地忙着从用户接收指令和发送最新的系统状态给用户。一个线程需要的大部分时间进行连接。

For MMORPG things are very different. I guess connections are constantly busy receiving instructions from users and sending latest system state to users. A thread is needed most of time for a connection.

如果您使用NIO,你必须不断重新分配一个线程的连接。它可能是一个劣溶液,以简单的固定螺纹每次连接溶液

If you use NIO, you'll have to constantly re-allocate a thread for a connection. It may be a inferior solution, to the simple fixed-thread-per-connection solution.

默认线程堆栈大小为pretty大,(1/4 MB?)这是主要的原因,只能有线程限制。尽量减少它,看看你的系统可以支持更多的。

The default thread stack size is pretty large, (1/4 MB?) it's the major reason why there can only be limited threads. Try reduce it and see if your system can support more.

然而,如果你的游戏确实很忙,这是你的CPU,你需要担心最多。 NIO与否,它真的很难处理成千上万的超活跃玩家的机器上。

However if your game is indeed very "busy", it's your CPU that you need to worry the most. NIO or not, it's really hard to handle thousands of hyper active gamers on a machine.

这篇关于每个连接模式VS NIO Java线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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