Skip to content

Commit 39d0904

Browse files
committed
Changed: raise MemoryHigh to 150M to fit the chardet tables
The 96M ceiling was set against a ~57M working set measured before httplint started running a charset check over response content. That check calls chardet, whose first invocation lazily loads 352 bigram models of 64K each -- a one-off +46M of RSS, taking the daemon to ~103M and straight back over MemoryHigh into reclaim throttling. Production peaks clustered at 104-117M across every crash, with and without --debug, which is what that arithmetic predicts. Concurrency is not the problem: measured at ~0.14M per in-flight request, near enough independent of body size, since content streams through the linter rather than accumulating. Twenty concurrent 5M fetches cost 2.6M in total. 150M leaves headroom for a few hundred concurrent requests over the ~103M floor; 192M hard cap still catches a runaway. Also corrects the comment's claim that --debug costs ~45M of tracemalloc overhead. That figure was never measured; it was chardet's 46M being misattributed. A crash with --debug off peaked at 107.8M, which is the base plus chardet and no tracemalloc at all.
1 parent d4fa5be commit 39d0904

1 file changed

Lines changed: 24 additions & 13 deletions

File tree

extra/redbot.service

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,33 @@ StateDirectory=redbot
6060
LogsDirectory=redbot
6161
LimitCORE=0
6262

63-
# Resource Limits. Steady-state working set is ~57M (interpreter, Jinja
64-
# templates, compiled regexes, babel's CLDR tables); MemoryHigh must stay clear
65-
# of it, or the kernel throttles the process in reclaim and the resulting
66-
# multi-second stalls trip the watchdog. Swap is disabled deliberately: with it
67-
# enabled, an overshoot became tens of seconds of thrashing instead of a prompt
68-
# OOM kill and restart.
63+
# Resource Limits. MemoryHigh must stay clear of the real working set, or the
64+
# kernel throttles the process in reclaim and the resulting multi-second stalls
65+
# trip the watchdog. Measured footprint:
6966
#
70-
# These assume the daemon is NOT running with --debug. tracemalloc's overhead
71-
# was measured at ~45M, but that was at a 25-frame capture depth; it's since
72-
# dropped to 1, which should cut most of it. The remaining cost hasn't been
73-
# re-measured, so if you enable --debug, watch memory.events for `high` events
74-
# and raise MemoryHigh until they stop.
67+
# ~57M base (interpreter, Jinja templates, compiled regexes, babel's CLDR
68+
# tables)
69+
# +46M one-off, the first time a response triggers httplint's charset check:
70+
# chardet lazily loads 352 bigram models of 64K each. 22M of that is
71+
# live tables, the rest is decompression the allocator never returns.
72+
# Paid once, on the first text/* response with a charset parameter.
73+
# +0.14M per concurrent request, near enough regardless of body size --
74+
# bodies stream through the linter rather than accumulating (20
75+
# concurrent 5M fetches cost 2.6M total).
76+
#
77+
# So ~103M before any load, and concurrency is cheap on top. 150M leaves room
78+
# for a few hundred in-flight requests; 192M hard cap catches a genuine runaway.
79+
#
80+
# Swap is disabled deliberately: with it enabled, an overshoot became tens of
81+
# seconds of thrashing instead of a prompt OOM kill and restart.
82+
#
83+
# These assume the daemon is NOT running with --debug, which adds tracemalloc
84+
# on top. If you enable it, watch memory.events for `high` events and raise
85+
# MemoryHigh until they stop.
7586
CPUQuota=60%
7687
MemoryLow=40M
77-
MemoryHigh=96M
78-
MemoryMax=128M
88+
MemoryHigh=150M
89+
MemoryMax=192M
7990
MemorySwapMax=0
8091

8192
[Install]

0 commit comments

Comments
 (0)