guildenstern/dispatcher

Search:
Group by:

This is the default dispatcher that ships with GuildenStern. Use it by importing guildenstern/dispatcher and then starting a server's dispatcher thread by calling start.

This dispatcher spawns a thread from a server-specific threadpool for every incoming read request. The threadpool size can be set in the start procedure. Dispatcher avoids excessive thread swapping by not spawning a thread when activethreadcount has reached maxactivethreadcount. However, if a thread reports itself as inactive (by calling server's suspend procedure), another thread is allowed to run. This keeps the server serving even when there are more threads waiting for I/O than the maxactivethreadcount. This design seems to deliver decent performance without leaning to more complex asynchronous concurrency techniques.

Procs

proc start(server: GuildenServer; port: int; threadpoolsize: uint = 0;
           maxactivethreadcount: uint = 0) {....raises: [], tags: [], forbids: [].}
Starts the server.thread loop, which then listens the given port for read requests until shuttingdown == true. By default maxactivethreadcount will be set to processor core count, and threadpoolsize twice that. If you a running lots of servers, or if this server is not under a heavy load, these numbers can be lowered.