Hello,
I'm currently in the tail end process of developing a high scalability
server for my employer. Essentially it receives short socket based
connections with an ASCII message, parses that message, does some
processing and then sends out a string reply on the same connection.
I'm using the asynchrounous IO completion port based socket methods in
..NET 2.0 to handle the comms side of things (giving extremely good
performance) and the venerable Mr. Skeet's custom threadpool to execute
the processing portion of the system. My problem is that not all of the
messages are created equal. Some simply do a very quick query from a DB
(or even a cache), whereas others do a credit card authorisation or
some longer SQL work.
Because of this I've tried to seperate my messages into two classes,
short running and long running, running them on two seperate
threadpools. Its become very hard to manage how many threads I allocate
to each - as all messages involve some I/O blocking I want to avoid
starving the pools as much as possible to keep latency low.
Based on this article:
http://blogs.msdn.com/cbrumme/archiv.../21/77595.aspx (Threading
and Synchronization, near the top - he explains the concept much better
than I ever could), I've been thinking about expanding Jon's ThreadPool
to automatically determine its own maximum number of threads to keep
CPU usage high (by increasing the number of threads) whilst not choking
the machine to death with too many context switches. This is apparently
a big simplification of what MS SQL Server does internally, and I'd
like to replace my two pools with jsut one of this nature.
Essentially I'd just like anyone's comments (especially yours Jon!) as
to whether this is worthwhile, or how to go about it - I've got some
ideas of my own:
1. Check on completion of a work item the CPU usage and decide whether
to create a new thread, keep the thread count the same, suspend the
thread?
2. Add a timer (100ms?) that checks the CPU periodically and sets the
max and min thread values? How does CPU usage work with multiple CPUs?
Its getting to be a bit of a pain as I have to tune the system as it is
to the machine it runs on and the type of load it encounters!
Thanks everyone!