You are not logged in.
Maybe it will be interesting to improve the performance of the servers on windows...
https://github.com/piscisaureus/wepoll
This library implements the epoll API for Windows applications. It is fast and scalable, and it closely resembles the API and behavior of Linux' epoll.
Rationale
Unlike Linux, OS X, and many other operating systems, Windows doesn't have a good API for receiving socket state notifications. It only supports the select and WSAPoll APIs, but they don't scale and suffer from other issues.Using I/O completion ports isn't always practical when software is designed to be cross-platform. Wepoll offers an alternative that is much closer to a drop-in replacement for software that was designed to run on Linux.
Compiling as a dll and using it is easy, just a copy&paste the types definition from SynFPCSock.pas, some small modifications, and load the functions from the external dll.
unit wepolldll;
interface
const
// associated file is available for read operations
EPOLLIN = $01;
// urgent data available for read operations
EPOLLPRI = $02;
// associated file is available for write operations
EPOLLOUT = $04;
// error condition happened on the associated file descriptor
EPOLLERR = $08;
// hang up happened on the associated file descriptor
EPOLLHUP = $10;
// sets the One-Shot behaviour for the associated file descriptor
// - i.e. after an event is pulled out, the file descriptor is disabled
EPOLLONESHOT = $40000000;
// sets the Edge-Triggered (ET) behaviour for the associated file descriptor
EPOLLET = $80000000;
EPOLL_CTL_ADD = 1;
EPOLL_CTL_DEL = 2;
EPOLL_CTL_MOD = 3;
type
/// application-level data structure for epoll
TEPollData = record
case integer of
0: (ptr: pointer);
1: (fd: integer);
2: (u32: cardinal);
3: (u64: Int64);
end;
PEPollData = ^TEPollData;
/// epoll descriptor data structure
TEPollEvent = packed record
events: cardinal;
__padding: cardinal; ///////// don't know why, but data returned by epoll_wait is aligned to next 4bytes...
data: TEpollData;
end;
PEPollEvent = ^TEPollEvent;
TEPollEventDynArray = array of TEPollEvent;
function epoll_create(size: integer): integer; cdecl; external 'wepoll.dll';
function epoll_close(epfd: integer): Integer; cdecl; external 'wepoll.dll';
function epoll_ctl(epfd, op, fd: integer; event: PEPollEvent): Integer; cdecl; external 'wepoll.dll';
function epoll_wait(epfd: THandle; events: PEPollEvent; maxevents, timeout: integer): Integer; cdecl; external 'wepoll.dll';
implementation
end.
Static linking will need more work, but should be possible.
I haven't done extensive performance or stability tests, but seems to work fine...
Offline
Interresting.
When I investigated about the official WSAPool() Windows API - https://docs.microsoft.com/en-us/window … k2-wsapoll - I discovered its emulation was quite poor and slow.
It seems to use plain socket behind the hook.
See TPollSocketSelect comments: https://synopse.info/files/html/api-1.1 … CKETSELECT
https://github.com/piscisaureus/wepoll seems to be a much better alternative, since it uses IOCP behind the wood.
I wrote some performance numbers in
https://github.com/synopse/mORMot/blob/ … xy.dpr#L48
We may eventually use this wepoll (with static linking) to speed up multiple connections on Windows, with minimal code change.
Implementing IOCP may be pretty tricky - and Linux is now our main target for servers development, for sure.
I have added a link to wepoll repository in the sample comments, as reference.
Online
Yes, as this library uses internally IOCP it seems an easy way to add that functionality into windows.
I know that sample, but unfortunately on my configuration it does not give consistent results. I've done some tests and results sometimes seems 3x faster than Select, others it shows near the same performance... but even two consecutive tests using Select shows a lot of variation on times, so I can't trust the results.
Last edited by franfj (2019-03-14 09:59:10)
Offline
Sounds very cool!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
@franfj
wepoll demo?
How to use it
Offline
@franfj
wepoll demo?
How to use it
Sorry, I don't have any full demo now.
I don't remember very well, but it should be easy to replicate the code from other poll classes (have a look at wsapoll or select) and implement the wepoll.
Anyway, the performance of the select implementation worked well enough for my requirements, so I left away this approach.
Offline