开发者

Hard time choosing ... IO vs NIO

开发者 https://www.devze.com 2023-03-21 21:52 出处:网络
I would like to ask what would be more appropriate to choose when developing a server similar to SmartFoxServer. I intend to develop a similar yet different server. In the benchmarks made by the ones

I would like to ask what would be more appropriate to choose when developing a server similar to SmartFoxServer. I intend to develop a similar yet different server. In the benchmarks made by the ones that developed the above server they had 开发者_高级运维something like 10000 concurrent clients. I made a bit of research regarding the cost of using too many threads(>500) but cannot decide which way to go. I once made a server in java but that was for a small application and had nothing to do with heavy loads.

Thanks


Take a look at Apache Mina. They've done alot of the heavy lifting required to use NIO effectively in a networking application. Whether or not NIO increases your ability to process concurrent connections really depends on your implementation, but the performance boosts in Tomcat, JBoss and Jetty are plenty evidence to you already in the positive.


i'm not familiar with smartfoxserver, so i can only speak generically (which is not always good :P but here i go)

i think those are 2 different questions. on one hand, the io performance when using native java sockets vs. native sockets written in c (like tomcat).

the other question is how to scale up to that kind of concurrency level. other than that, i'd always choose native sockets (i.e: c).

now, how to scale: it's not a good idea to have a lot of threads running at the same time (os constraints, etc), so i'd choose to scale horizontally, meaning to add a load balancer that can send the requests to different servers that can be linked by using messages (using jms, like rabbitmq or activemq, or even using a protocol like stomp or amqp).

other solution, a cloud environment that allows you to grow your installation as you need


In most benchmarks which test 10K or 100K connections, the server is doing no work and unless your server does next to nothing, these test are unrealistic.

You need to take a clear idea of mow many concurrent connections you want to support.

If you have less than 1K connection, using a thread per connection will work ok. This is the simplest approach to take. Using a dispatcher model with NIO will work better if your request are very simple. Otherwise it won't matter much.

If you have more than 1K connections it is likely you want to use more than one server as each connection is getting less than 1% of a core and the cost of a basic server is relatively cheap these days.

0

精彩评论

暂无评论...
验证码 换一张
取 消