Skip to content

Commit e3589c9

Browse files
author
Arnaud Bouchez
committed
new acoEventFD option (on Linux only)
- will use eventfd() instead of futexes to notify the processing threads - by design, will disable acoThreadSmooting - numbers on regular HW (laptop) are not better, but it may help on high-end HW with a lot of cores (let's test it) :)
1 parent a775110 commit e3589c9

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

src/mormot.commit.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
'2.0.4977'
1+
'2.0.4978'

src/net/mormot.net.async.pas

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ TAsyncConnectionsThread = class(TSynThread)
471471
// - acoThreadSmooting will change the ThreadPollingWakeup() algorithm to
472472
// focus the process on the first threads of the pool - by design, this
473473
// setting will disable both acoThreadCpuAffinity and acoThreadSocketAffinity
474+
// - acoEventFD (on Linux only) will use eventfd() instead of futexes to
475+
// notify the processing threads - by design, will disable acoThreadSmooting
474476
TAsyncConnectionsOptions = set of (
475477
acoOnErrorContinue,
476478
acoNoLogRead,
@@ -483,7 +485,8 @@ TAsyncConnectionsThread = class(TSynThread)
483485
acoThreadCpuAffinity,
484486
acoThreadSocketAffinity,
485487
acoReusePort,
486-
acoThreadSmooting
488+
acoThreadSmooting,
489+
acoEventFD
487490
);
488491

489492
/// to implement generational garbage collector of asynchronous connections
@@ -1843,10 +1846,7 @@ procedure TAsyncConnectionsThread.Execute;
18431846
//fOwner.fClients.fRead.PendingLogDebug('Wakeup');
18441847
fEvent.ResetEvent;
18451848
fWaitForReadPending := true; // should be set before wakeup
1846-
if Assigned(fOwner.fThreadPollingEventFD) then
1847-
fOwner.fThreadPollingEventFD.SetEvent(new)
1848-
else
1849-
fOwner.ThreadPollingWakeup(pending);
1849+
fOwner.ThreadPollingWakeup(new);
18501850
//fOwner.DoLog(sllCustom1, 'Execute: WaitFor ReadPending', [], self);
18511851
if not Terminated then
18521852
fEvent.WaitFor(20);
@@ -1978,7 +1978,8 @@ constructor TAsyncConnections.Create(const OnStart, OnStop: TOnNotifyThread;
19781978
// prepare this main thread: fThreads[] requires proper fOwner.OnStart/OnStop
19791979
inherited Create({suspended=}false, OnStart, OnStop, ProcessName);
19801980
// initiate the read/receive thread(s)
1981-
// fThreadPollingEventFD := NewEventFD; // nil if unsupported
1981+
if acoEventFD in aOptions then
1982+
fThreadPollingEventFD := NewEventFD; // nil if unsupported
19821983
fThreadPoolCount := aThreadPoolCount;
19831984
SetLength(fThreads, fThreadPoolCount);
19841985
if aThreadPoolCount = 1 then
@@ -3528,7 +3529,10 @@ constructor THttpAsyncServer.Create(const aPort: RawUtf8;
35283529
//include(aco, acoWritePollOnly);
35293530
if hsoEnableTls in ProcessOptions then
35303531
include(aco, acoEnableTls);
3531-
if hsoThreadSmooting in ProcessOptions then
3532+
if (hsoEventFD in ProcessOptions) and
3533+
(NewEventFD <> nil) then // try to allocate a temporary eventfd() instance
3534+
include(aco, acoEventFD) // and exclude other options
3535+
else if hsoThreadSmooting in ProcessOptions then
35323536
include(aco, acoThreadSmooting) // and exclude any thread affinity
35333537
else
35343538
begin

src/net/mormot.net.server.pas

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ THttpServerRequest = class(THttpServerRequestAbstract)
343343
// - hsoThreadSmooting will change the TAsyncConnections.ThreadPollingWakeup()
344344
// algorithm to focus the process on the first threads of the pool - by design,
345345
// this will disable both hsoThreadCpuAffinity and hsoThreadSocketAffinity
346+
// - hsoEventFD (on Linux only) will use eventfd() instead of futexes to
347+
// notify the TAsyncConnections threads - by design, disable acoThreadSmooting
346348
THttpServerOption = (
347349
hsoHeadersUnfiltered,
348350
hsoHeadersInterning,
@@ -356,7 +358,8 @@ THttpServerRequest = class(THttpServerRequestAbstract)
356358
hsoThreadCpuAffinity,
357359
hsoThreadSocketAffinity,
358360
hsoReusePort,
359-
hsoThreadSmooting);
361+
hsoThreadSmooting,
362+
hsoEventFD);
360363

361364
/// how a THttpServerGeneric class is expected to process incoming requests
362365
THttpServerOptions = set of THttpServerOption;

src/net/mormot.net.sock.posix.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1214,7 +1214,7 @@ const
12141214
// exists since Kernel 2.6.27
12151215
syscall_nr_eventfd2 = 290;
12161216
// = 328 on i386
1217-
// = 356 on AARM64
1217+
// = 356 on AARCH64
12181218

12191219
function eventfd(initval, flags: cardinal): integer; inline;
12201220
begin

0 commit comments

Comments
 (0)