Before you run into the streets shouting "Lies! Bloody lies all of it!", I think I should mention that this was on the 2.6 Linux kernel. If you have played around with threads on earlier Linux kernels, you know that threads on those systems ate resources like crazy. Apparently the new threading implementation changed all that. Interestingly, Windows XP also show significantly better performance with multiple threads rather than NIO.
Talk about the world turning upside down.
That said, I still am not 100% convinced that the last word has been said. Most of the examples were of IO where data flows in one direction at a time. This is where multi-threaded blocking IO rules. But what if you have something like say an online poker server, where you have continuous input and output? Suddenly one thread isn't good enough, you need at least one for input and one for output. In addition, any timeouts require yet another thread, since it has to be unaffected by the blocking IO.
So say you have your java process with 15k connections. That's a whopping 30k threads just to handle the IO. That is not counting the threads for the poker tables or db access.
What's more, both input and output threads become little more than worker threads to receive and send data, since the actual gameplay will necessarily run on another thread. This means that all the connection input thread will do is really to read input and dispatch it to some poker table thread. A message being another word for "event".
Which means we're back to event handling just like in the NIO case, and we just gained 30k threads mostly doing nothing.
What I'm trying to say is that I don't think the results are as conclusive as they may seem. Yes, there are many applications where threads with blocking IO makes things incredibly easy to code, and that's where the benchmarks are applicable, but then there are other situations where they quite simply doesn't make sense, like in the poker server example, where each connection would require more threads and those threads in turn would need to communicate with other threads a lot more.
0 comments:
Post a Comment