Skip to content

Commit 6857c4c

Browse files
committed
Latency fixes
1 parent 52897f8 commit 6857c4c

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

src/connection.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ static int connSocketWrite(connection *conn, const void *data, size_t data_len)
164164
int ret = write(conn->fd, data, data_len);
165165
if (ret < 0 && errno != EAGAIN) {
166166
conn->last_errno = errno;
167-
conn->state = CONN_STATE_ERROR;
167+
conn->state.store(CONN_STATE_ERROR, std::memory_order_relaxed);
168168
}
169169

170170
return ret;
@@ -173,10 +173,10 @@ static int connSocketWrite(connection *conn, const void *data, size_t data_len)
173173
static int connSocketRead(connection *conn, void *buf, size_t buf_len) {
174174
int ret = read(conn->fd, buf, buf_len);
175175
if (!ret) {
176-
conn->state = CONN_STATE_CLOSED;
176+
conn->state.store(CONN_STATE_CLOSED, std::memory_order_release);
177177
} else if (ret < 0 && errno != EAGAIN) {
178178
conn->last_errno = errno;
179-
conn->state = CONN_STATE_ERROR;
179+
conn->state.store(CONN_STATE_ERROR, std::memory_order_release);
180180
}
181181

182182
return ret;
@@ -253,14 +253,14 @@ static void connSocketEventHandler(struct aeEventLoop *el, int fd, void *clientD
253253
UNUSED(fd);
254254
connection *conn = (connection*)clientData;
255255

256-
if (conn->state == CONN_STATE_CONNECTING &&
256+
if (conn->state.load(std::memory_order_relaxed) == CONN_STATE_CONNECTING &&
257257
(mask & AE_WRITABLE) && conn->conn_handler) {
258258

259259
if (connGetSocketError(conn)) {
260260
conn->last_errno = errno;
261-
conn->state = CONN_STATE_ERROR;
261+
conn->state.store(CONN_STATE_ERROR, std::memory_order_release);
262262
} else {
263-
conn->state = CONN_STATE_CONNECTED;
263+
conn->state.store(CONN_STATE_CONNECTED, std::memory_order_release);
264264
}
265265

266266
if (!conn->write_handler) aeDeleteFileEvent(serverTL->el,conn->fd,AE_WRITABLE);
@@ -407,7 +407,7 @@ int connRecvTimeout(connection *conn, long long ms) {
407407
}
408408

409409
int connGetState(connection *conn) {
410-
return conn->state;
410+
return conn->state.load(std::memory_order_relaxed);
411411
}
412412

413413
void connSetThreadAffinity(connection *conn, int cpu) {

src/networking.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,9 +1928,12 @@ int handleClientsWithPendingWrites(int iel, int aof_state) {
19281928
}
19291929
}
19301930

1931-
AeLocker locker;
1932-
locker.arm(nullptr);
1933-
ProcessPendingAsyncWrites();
1931+
if (listLength(serverTL->clients_pending_asyncwrite))
1932+
{
1933+
AeLocker locker;
1934+
locker.arm(nullptr);
1935+
ProcessPendingAsyncWrites();
1936+
}
19341937

19351938
return processed;
19361939
}

0 commit comments

Comments
 (0)