Reputation: 121
Should i use they with TIdTcpServer, and where they can improve something on my application?
i ask it because maybe they can improve some speed/agility action on TIdTcpServer since i use a Queue.
Upvotes: 1
Views: 731
Reputation: 596998
TIdTCPServer
runs a thread for every client that is connected. Those threads are managed by the TIdScheduler
that is assigned to the TIdTCPServer.Scheduler
property. If you do not assign a scheduler of your own, a default TIdSchedulerOfThreadDefault
is created internally for you.
The difference between TIdSchedulerOfThreadDefault
and TIdSchedulerOfThreadPool
is:
TIdSchedulerOfThreadDefault
creates a new thread when a client connects, and then terminates that thread when the client disconnects.
TIdSchedulerOfThreadPool
maintains a pool of idle threads. When a client connects, a thread is pulled out of the pool if one is available, otherwise a new thread is created. When the client disconnects, the thread is put back in the pool for reuse if the scheduler's PoolSize
will not be exceeded, otherwise the thread is terminated.
From the OS's perspective, creating a new thread is an expensive operation. So in general, using a thread pool is usually preferred for better performance, but at the cost of using memory and resources for idle threads hanging around waiting to be used.
Whichever component you decide to use will not have much effect on how the server performs while processing active clients, only how it performs while handling socket connects/disconnects.
Upvotes: 2