IOCP Server

Windows I/O Completion Ports acceptor for high concurrency. Switch the sgcWebSockets server to the IOCP IOHandler and serve thousands of connections from a small, fixed thread pool instead of one thread per connection.

IOCP IOHandler

A Windows-only I/O Completion Ports mode for the standard sgcWebSockets servers. Enable it through IOHandlerOptions to scale far beyond the default Indy thread-per-connection model.

Component class

TsgcWebSocketServer / TsgcWebSocketHTTPServer — enabled via IOHandlerOptions.

Mechanism

Windows I/O Completion Ports (Windows only).

Platforms

Windows

Edition

Enterprise

Set the IOHandler type, go

Go to the IOHandlerOptions property and select iohIOCP as the IOHandler Type. Leave the thread counts at zero to auto-size from the CPU count.

Server.IOHandlerOptions.IOHandlerType := iohIOCP;
Server.IOHandlerOptions.IOCP.IOCPThreads := 0;
Server.IOHandlerOptions.IOCP.WorkOpThreads := 0;
Server->IOHandlerOptions->IOHandlerType = iohIOCP;
Server->IOHandlerOptions->IOCP->IOCPThreads = 0;
Server->IOHandlerOptions->IOCP->WorkOpThreads = 0;
Server.IOHandlerOptions.IOHandlerType = iohIOCP;
Server.IOHandlerOptions.IOCP.IOCPThreads = 0;
Server.IOHandlerOptions.IOCP.WorkOpThreads = 0;

What's inside

How the IOCP IOHandler behaves and how to tune it.

Thread-pool I/O

Handle thousands of connections from a limited pool of threads instead of one thread per connection, the way Indy works by default.

IOCPThreads

Threads used for IOCP asynchronous (overlapped) requests. 0 auto-sizes from the processor count. On Delphi 7 and 2007 the default is 32, because cpucount is not available.

WorkOpThreads

Pin a connection to the same thread when you need it. Requests are normally spread across the pool, so each request for a connection may run on a different thread. Set a value greater than zero only if you require this. It is a performance trade-off.

When to use

Recommended when you need to handle thousands of connections. If your server tops out around 100 concurrent connections, the default Indy thread model is fine.

Disconnect detection

IOCP detects a dead socket only on write. Enable CleanDisconnect on TsgcWebSocketClient or a server-side heartbeat so the server learns of the drop and OnDisconnect fires.

Specifications & references

Authoritative sources for the mechanism this mode is built on.

Documentation & Demos

Deep-link to the feature reference, grab the ready-to-run demo project, and download the trial.

Online Help — IOCP Feature reference for enabling Windows I/O Completion Ports on the sgcWebSockets server.
Demo Project — Demos\Server Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
User Manual (PDF) Comprehensive manual covering every component in the library.

Scale to Thousands of Connections

Download the free trial and switch your Delphi server to the Windows IOCP IOHandler.