Improve connect performance by reducing lock contention, I'm seeing 50-100% improvements

This commit is contained in:
John Sully 2022-04-12 23:28:57 +00:00 committed by John Sully
parent 994fa6b453
commit 750a7fdb16
2 changed files with 4 additions and 5 deletions

View File

@ -132,6 +132,7 @@ static_assert(sizeof(aeCommand) <= PIPE_BUF, "aeCommand must be small enough to
void aeProcessCmd(aeEventLoop *eventLoop, int fd, void *, int ) void aeProcessCmd(aeEventLoop *eventLoop, int fd, void *, int )
{ {
std::unique_lock<decltype(g_lock)> ulock(g_lock, std::defer_lock);
aeCommand cmd; aeCommand cmd;
for (;;) for (;;)
{ {
@ -153,8 +154,7 @@ void aeProcessCmd(aeEventLoop *eventLoop, int fd, void *, int )
case AE_ASYNC_OP::PostFunction: case AE_ASYNC_OP::PostFunction:
{ {
std::unique_lock<decltype(g_lock)> ulock(g_lock, std::defer_lock); if (cmd.fLock && !ulock.owns_lock())
if (cmd.fLock)
ulock.lock(); ulock.lock();
((aePostFunctionProc*)cmd.proc)(cmd.clientData); ((aePostFunctionProc*)cmd.proc)(cmd.clientData);
break; break;
@ -162,8 +162,7 @@ void aeProcessCmd(aeEventLoop *eventLoop, int fd, void *, int )
case AE_ASYNC_OP::PostCppFunction: case AE_ASYNC_OP::PostCppFunction:
{ {
std::unique_lock<decltype(g_lock)> ulock(g_lock, std::defer_lock); if (cmd.fLock && !ulock.owns_lock())
if (cmd.fLock)
ulock.lock(); ulock.lock();
(*cmd.pfn)(); (*cmd.pfn)();

View File

@ -1239,7 +1239,7 @@ void clientAcceptHandler(connection *conn) {
} }
#define MAX_ACCEPTS_PER_CALL 1000 #define MAX_ACCEPTS_PER_CALL 1000
#define MAX_ACCEPTS_PER_CALL_TLS 1 #define MAX_ACCEPTS_PER_CALL_TLS 100
static void acceptCommonHandler(connection *conn, int flags, char *ip, int iel) { static void acceptCommonHandler(connection *conn, int flags, char *ip, int iel) {
client *c; client *c;
char conninfo[100]; char conninfo[100];