Saturday, February 21, 2009

NIO adventures

I assumed anew task for myself last week. Due to some performance constraints in one of the pieces of software I had into maintenance I decided that the only possible solution for improvement is to rewrite it. I knew that this would not be an easy job I had no real certitude that this would really work better. Bu I took the chance because I considered that having one thread per concurrent client in this software was really not the best approach.
Therefore I had to implement something lighter.
I took the approach of non blocking IO. All the incoming SIP requests are handled by a thread that is using a selector to react on the incoming requests. The incoming messages are then queues into a dispatch thread that dequeues them and depending on the SIP method/answer's CallID dispatches to a state machine that handles that client.
The results seem promising for the moment. Before I had about 16% CPU per process on a Netra T2000 server, now it dropped to a maximum of 9% while in traffic and 1% in idle mode.
However the NIO documentation is quite scarce. I was quite lucky with those two sources:

that clarified me some of the NIO ways of doing things.

On Unices NIO works well (I'd say that it works best on Solaris). On the other hand it works awfully on Windows. It hogs 50% of CPU and after the program is finished it doesn't dive back the CPU (System process on my XP stays all the time at 50%).

No comments:

Post a Comment