From 16531e53dbd178527e677f89246fdb3bbf1fa51f Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Sat, 6 May 2023 09:23:54 +0200 Subject: [PATCH] Performance tweak to dbufs: 512 bytes -> 4K This results in less write calls (lower load) and more data per packet (more efficient network traffic). It helps for the webserver (JSON-RPC) but should also help IRC traffic when returning more than a line or so. Previously the first TCP packet was not always filled fully, eg it was close to 512 bytes instead of being close to 1500 bytes (MTU). Strange that this happened in the first place, by the way, as we don't set TCP_NODELAY. But whatever... --- include/dbuf.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/include/dbuf.h b/include/dbuf.h index 2bf2ad23a..4b0d506d5 100644 --- a/include/dbuf.h +++ b/include/dbuf.h @@ -25,8 +25,19 @@ #include "list.h" -/* 512 bytes -- 510 character bytes + \r\n, per rfc1459 */ -#define DBUF_BLOCK_SIZE (512) +/** Size of a dbuf block. + * This used to be 512 bytes, since that was max line per RFC1459. + * Bumped to 4k because lines tend to be bigger nowadays, now + * that we have message tags and all. And some other IRCd code + * uses dbuf for non-IRC data also, which also prefers larger buffers. + * Alignment details: + * We don't set it to 4096 bytes exactly because we want the + * struct 'dbufdbuf' (see further down) to be exactly 4096 bytes. + * Since it includes some other struct members, 4072 seems to do it + * on 64 bit archs. Note that there is no need to provide room + * for malloc overhead as we use mempools. + */ +#define DBUF_BLOCK_SIZE (4072) /* ** dbuf is a collection of functions which can be used to @@ -53,10 +64,8 @@ typedef struct dbuf { ** And this 'dbufbuf' should never be referenced outside the ** implementation of 'dbuf'--would be "hidden" if C had such ** keyword... -** If it was possible, this would compile to be exactly 1 memory -** page in size. 2048 bytes seems to be the most common size, so -** as long as a pointer is 4 bytes, we get 2032 bytes for buffer -** data after we take away a bit for malloc to play with. -avalon +** This is exactly a page in total, see comment at +** DBUF_BLOCK_SIZE definition further up. */ typedef struct dbufbuf { struct list_head dbuf_node;