Building Highly Scalable Servers with Java NIO
Subject:   Design advice- Thread distribution for NIO on multiple CPU,
Date:   2005-12-21 05:43:49
From:   Archanaa
Thanks for a great article which has really improved my understanding of NIO.

I need your advice for the design of a server using NIO. Following is the scenario.

  • The server would be receiving bursty transmissions of data from multiple mobile client devices.

  • Transmissions would be over pure TCP/IP sockets over GPRS and would send around 58KB - 1440 samples of data over 2 hrs which have to be stored in a database.

  • System should scale to accept data from 5000 devices and then scale upto 40000 devices.

  • Sockets will not be kept alive due to bursty nature and frequency of transmission per device.

My questions are as follows -

  • Would NIO be suitable for this scenario, since it may be highly unlikely that all the devices transmit the data together? Avg works out to be 41 per minute and 333 after scaling?

  • How should thread distribution be done for a multiple CPU machine. I have 3 options.
    a) register ReadWriteSelectorHandler (and their channels) on other SelectorThreads - is this possible. Each thread would also be doing bulk insertion of the samples into database after collecting sufficient samples.
    b) Keep separate threads for bulk insertion into database after collecting various samples from a single SelectorThread? As per my experience, the data insertion into database may not be much overhead if we take care of bulk insertions and proper design - so I am not much in favour of this.
    c) Third option with NIO would be to have m SelectorThreads and n database insertion threads and use a kind of producer-consumer logic between them. I donít know what the values of m and n should be.

  • If I use the traditional I/O, would around 15 threads (scalable upto 30) be sufficient for the requirement. We would be using a 2 CPU machine and I donít want to keep my thread pool as large as 100 threads due to obvious limitations?

It would be really helpful if you can give your expert opinion for this.

1 to 1 of 1
1 to 1 of 1