This is the default dispatcher (see also: guildenstern/epolldispatcher).
Servers are started by using the start proc.
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 when there are more threads suspended than the maxactivethreadcount. This design seems to deliver decent performance by dynamically adjusting number of active threads and thereby avoids excessive context switching.
Procs
proc registerSocket(theserver: GuildenServer; socket: SocketHandle; flags = 0; customdata: pointer = nil): bool {....raises: [], tags: [RootEffect], forbids: [].}
- Add a socket whose read events will be then dispatched. Useful for servers operating in client mode.
proc start(server: GuildenServer; port: int; threadpoolsize: uint = 0; maxactivethreadcount: uint = 0): bool {. ...raises: [ResourceExhaustedError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], 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 max(4, countProcessors(), and threadpoolsize to maxactivethreadcount * 2. If you a running lots of other servers, or if this server is not under a heavy load, these numbers can be lowered. If port number 0 is given, the server runs in client mode, where server.thread is not started, and sockets can be added manually using the registerSocket proc.