#1 2017-07-25 10:47:06

keinn
Member
Registered: 2014-10-20
Posts: 103

Is the IOCP mode of THttpServer not for real?

usually  we implement an IOCP Server by these steps:
1、Create an IO complete port by CreateIoCompletionPort
2、Create some Worker threads
3、Listen on a Network Socket
4、when there is an incoming connect socket ,bind that socket HANDLE to the complete port created in step 1 (also by CreateIoCompletionPort), then the OS can do its job.
5、worker thread loop to GetQueuedCompletionStatus and do the business

6、at last, use PostQueuedCompletionStatus to notify the worker threads to exit;

7、 Clean up .


but in THttpServer. it only create complete port once at the threadpool, when there is an client connection coming , it does NOT  do step 4.

mORMot just use IOCP as an Queue list~ am i right???

Offline

#2 2017-07-25 11:47:30

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: Is the IOCP mode of THttpServer not for real?

The THttpServer socket-based class uses indeed the worker thread in a cross-platform way, using IOCP only for the threaded process queue (i.e. TSynThreadPool).
See this conditional:

  {$ifdef MSWINDOWS}
    // I/O completion ports API is the best option under Windows
    // under Linux/POSIX, we fallback to a classical event-driven pool
    {$define USE_WINIOCP}
  {$endif}

This is used only for short-lived connection (i.e. not kept-alive connections) - under Linux/BSD, we expect the THttpServer to be behind a nginx front-end, and closing local loopback connection for each request is in fact not a problem.
In practice, performance is very good.

Under Windows, THttpApiServer is to be used for public APIs and web pages, and it will leverage the http.sys kernel API, which has better performance than IOCP.
So under Windows, we didn't implement IOCP sockets, since it wouldn't have any benefit.

Offline

#3 2017-07-26 01:16:04

keinn
Member
Registered: 2014-10-20
Posts: 103

Re: Is the IOCP mode of THttpServer not for real?

got it , thanks.

just found this lib:https://github.com/winddriver/Delphi-Cross-Socket , it target all major os platform win/mac/ios/android,  using IOCP on windows, EPOLL on Linux ,KQUEUE on BSD , can handle 100k concurrent connections. so i look into our good mORMot socket  to check the implement detail ~~
thanks anyway

Offline

#4 2017-07-26 06:35:11

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,669
Website

Re: Is the IOCP mode of THttpServer not for real?

We already have TAsynchConnection, TAsynchClient and TAsynchServer classes using Epoll on Linux, or Poll/Select/WSAPoll on other
It can handle 100k connections, and mainly targets Linux/BSD (via poll/epoll), via Kylix or FPC (and not Delphi Linux and its NextGen ARC compiler).
We already have Windows as a good HTTP server platform with http.sys - so there is no IOCP API version for Windows yet.
See some numbers in https://github.com/synopse/mORMot/tree/ … %20Polling

But I didn't know about Delphi-Cross-Socket, and it sounds pretty good! (even if it is not FPC compatible)
The SSL code will help us finishing our SynOpenSSL.pas unit.
Thanks for the feedback!

Offline

Board footer

Powered by FluxBB