Skip to content

Commit

Permalink
{173076598} sqlwriter: Reduce buffer to avoid heap fragmentation
Browse files Browse the repository at this point in the history
Heap fragmentation was observed with slow clients, reading a large
number of small responses (comdb2del.tsk reading rowid and deleting rows
inline with the read operation.) This lead to sqlwriter repeatedly
buffering small payloads up to 1MB and consequently fragmenting the
heap.

Signed-off-by: Akshat Sikarwar <[email protected]>
  • Loading branch information
akshatsikarwar committed Sep 26, 2023
1 parent 9e171f1 commit 69bb46c
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions net/sqlwriter.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ static struct timeval heartbeat_time = {.tv_sec = 0, .tv_usec = MSEC(100)};
#define min_hb_time 1

//writer will block if outstanding data hits:
#define max_buf MB(1)

//once blocked, writer drains to:
#define resume_buf KB(128)

BB_COMPILE_TIME_ASSERT(resume_max_buf, resume_buf < max_buf);
#define max_buf KB(256)

struct sqlwriter {
struct sqlclntstate *clnt;
Expand Down Expand Up @@ -184,21 +179,17 @@ static void sql_flush_cb(int fd, short what, void *arg)
UNLOCK_WR_LOCK_ONLY_IF_NOT_PACKING(writer);
return;
}
const int min = (writer->done || writer->flush) ? 0 : resume_buf;
while (1) {
while (outstanding) {
if ((n = wr_evbuffer(writer, fd)) <= 0) {
break;
}
writer->sent_at = time(NULL);
outstanding -= n;
if (outstanding <= min) {
break;
}
}
if (n <= 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
writer->bad = 1;
event_del(writer->flush_ev);
} else if (outstanding <= min) {
} else {
sql_disable_flush(writer);
}
UNLOCK_WR_LOCK_ONLY_IF_NOT_PACKING(writer);
Expand Down

0 comments on commit 69bb46c

Please sign in to comment.