Skip to content

Commit

Permalink
force acoThreadSmooting on Windows
Browse files Browse the repository at this point in the history
- because without it the async server seems unstable and consumes too much CPU in its R0 thread - see https://synopse.info/forum/viewtopic.php?id=6682
- this is a temporary solution until something better is reported (and needed)
- idea is to use the plain THttpSocketServer on Windows, and use the async code on Linux only (where it seems very stable and efficient)
- writing cross-platform multi-thread IO is hard for sure :)
  • Loading branch information
Arnaud Bouchez committed Aug 24, 2023
1 parent 8b53847 commit 3b1b6df
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/mormot.commit.inc
@@ -1 +1 @@
'2.1.5794'
'2.1.5795'
7 changes: 6 additions & 1 deletion src/net/mormot.net.async.pas
Expand Up @@ -2201,7 +2201,7 @@ function TAsyncConnections.ThreadClientsConnect: TAsyncConnection;
FreeAndNil(result);
end;

// NOTICE on the acoThreadSmooting algorithm (genuine AFAICT)
// NOTICE on the acoThreadSmooting scheduling algorithm (genuine AFAICT)
// - in TAsyncConnectionsThread.Execute, the R0/atpReadPoll main thread calls
// PollForPendingEvents (e.g. the epoll API on Linux) then ThreadPollingWakeup()
// to process the socket reads in the R1..Rn/atpReadPending threads of the pool
Expand All @@ -2223,6 +2223,8 @@ function TAsyncConnections.ThreadClientsConnect: TAsyncConnection;
// thread is supposed to handle in its loop - default value is computed as
// (ThreadPoolCount / CpuCount) * 8 so should scale depending on the actual HW
// - on Linux, waking up threads is done via efficient blocking eventfd()
// - on Windows, acoThreadSmooting is forced because without it the async
// server seems unstable and consumes too much CPU in its R0 thread

function TAsyncConnections.ThreadPollingWakeup(Events: integer): PtrInt;
var
Expand Down Expand Up @@ -3645,6 +3647,9 @@ constructor THttpAsyncServer.Create(const aPort: RawUtf8; const OnStart,
//include(aco, acoWritePollOnly);
if hsoEnableTls in ProcessOptions then
include(aco, acoEnableTls);
{$ifdef OSWINDOWS}
include(ProcessOptions, hsoThreadSmooting); // seems unstable without it
{$endif OSWINDOWS}
if hsoThreadSmooting in ProcessOptions then
include(aco, acoThreadSmooting)
else // our thread smooting algorithm excludes CPU affinity
Expand Down

2 comments on commit 3b1b6df

@EdilsonLisboa
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ab, the ProDelphi6432 accounted, in 2 minutes of execution, the following results:
mormot_profile

@synopse
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems as expected: the R0 loops are waiting & sleeping...

Please sign in to comment.