commit 1582b5c79bb8c136d082a8162ef8ffc050fc8a78
parent bec98ea6fd1aab3ee3c4249995c3270fa9ff75b3
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Sat, 28 Feb 2026 14:51:10 +0100
Optimised connection processing order.
Newly added connections are processed first.
This may help with cache hotness (new connections processed while they
are still in CPU cache) and efficiency (newly added connection served
first as potentially short-lived, while long-lived connections are
accumulated at the end of the list).
Connections deleted starting for newest. This should help OS manage
allocated resources better.
Diffstat:
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/mhd2/daemon_add_conn.c b/src/mhd2/daemon_add_conn.c
@@ -431,7 +431,7 @@ new_connection_process_inner (struct MHD_Daemon *restrict daemon,
daemon->conns.count++;
daemon->conns.block_new =
(daemon->conns.count >= daemon->conns.cfg.count_limit);
- mhd_DLINKEDL_INS_LAST (&(daemon->conns), connection, all_conn);
+ mhd_DLINKEDL_INS_FIRST (&(daemon->conns), connection, all_conn);
mhd_conn_init_activity_timeout (connection,
daemon->conns.cfg.timeout_milsec);
diff --git a/src/mhd2/events_process.c b/src/mhd2/events_process.c
@@ -630,9 +630,9 @@ mhd_daemon_close_all_conns (struct MHD_Daemon *d)
has_upgraded_unclosed = false;
if (! mhd_D_HAS_THR_PER_CONN (d))
{
- for (c = mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn);
+ for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn);
NULL != c;
- c = mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn))
+ c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn))
{
#ifdef MHD_SUPPORT_UPGRADE
mhd_assert (mhd_HTTP_STAGE_UPGRADING != c->stage);
@@ -981,8 +981,8 @@ select_update_fdsets (struct MHD_Daemon *restrict d,
if (listen_only)
return ret;
- for (c = mhd_DLINKEDL_GET_FIRST (&(d->conns),all_conn); NULL != c;
- c = mhd_DLINKEDL_GET_NEXT (c,all_conn))
+ for (c = mhd_DLINKEDL_GET_LAST (&(d->conns),all_conn); NULL != c;
+ c = mhd_DLINKEDL_GET_PREV (c,all_conn))
{
mhd_assert (mhd_HTTP_STAGE_CLOSED != c->stage);
if (is_conn_excluded_from_http_comm (c))