commit 1ac677f7e995bd41b12d494c275059d6da7299509971ca2589b898cfc7b7ba57 from: Tracey Emery date: Tue Nov 10 16:31:58 2026 UTC start under a dedicated login class Every client connection costs one descriptor in one sockets worker, and each process raises its open file soft limit to the hard limit of the login class the rc script started it under. Until now that was the stock daemon class, so client capacity was whatever its default happened to be. Ship /etc/login.conf.d/mqttd, start the daemon under that class from the rc script, and document the sizing rule: about workers times the class maximum, with kern.maxfiles raised to match. commit - 4af73d3b7ab2f607d9116ad9e5691ded0d1b2112520a501a03ccffd085f95015 commit + 1ac677f7e995bd41b12d494c275059d6da7299509971ca2589b898cfc7b7ba57 blob - 98e930e577b97f059609cedffc4e0acc5b02a469ee71eb2206d691c04e180d7b blob + 1a60cde5900ca7ea5c7c385f0fece4fd978845cf4814a5584bba94ad830735e7 --- README.md +++ README.md @@ -28,6 +28,7 @@ Files * `/etc/examples/mqttd.conf` * `/usr/local/man/man5/mqttd.conf.5` * `/etc/rc.d/mqttd` +* `/etc/login.conf.d/mqttd` * `/usr/local/sbin/mqttctl` * `/usr/local/man/man8/mqttctl.8` @@ -41,9 +42,15 @@ Compile and install. doas groupadd _mqttd doas useradd -d /var/empty -L daemon -g _mqttd -s /sbin/nologin _mqttd doas cp mqttd/examples/etc/rc.d/mqttd /etc/rc.d/ + doas cp mqttd/examples/etc/login.conf.d/mqttd /etc/login.conf.d/ doas cp mqttd/examples/etc/mqttd.conf /etc/examples/ doas install -d -o _mqttd -g _mqttd -m 700 /var/db/mqttd +The login class sets the open file limit every process runs with; each +client connection costs one descriptor in one sockets worker, so the +daemon carries about `workers` times that limit in connections. Size +the class for the fleet and raise `kern.maxfiles` to match. + Create password hashes with `encrypt -b 10`, write `/etc/mqttd.conf` according to `man mqttd.conf`, then `rcctl enable mqttd` and `rcctl start mqttd`. Run `mqttd -d` to stay in the foreground, and blob - /dev/null blob + aee19eb2007cf33d5039999e267a5a738da1f864f88e230767b7c626e7b34bd1 (mode 644) --- /dev/null +++ mqttd/examples/etc/login.conf.d/mqttd @@ -0,0 +1,17 @@ +# Login class for mqttd(8). Install as /etc/login.conf.d/mqttd; the rc +# script starts the daemon under it. +# +# Every process raises its open file soft limit to openfiles-max when it +# starts, and every client connection holds one descriptor in one +# sockets worker. The daemon therefore carries about +# +# workers * (openfiles-max - 32) +# +# connections, where workers is the setting in mqttd.conf(5). The +# default below with two workers is good for roughly 8000 clients. +# Raise kern.maxfiles in sysctl.conf(5) when the total over all workers +# approaches it. +mqttd:\ + :openfiles-cur=4096:\ + :openfiles-max=4096:\ + :tc=daemon: blob - 98890b2a475ca6dbde03804b95c9b5a72bbb4424753d1eb421ab4a12a986f6cc blob + 25b703a06366f685b5b66c8468e3bfc32989c3c15ebcb9a5804d65fefde230c1 --- mqttd/examples/etc/rc.d/mqttd +++ mqttd/examples/etc/rc.d/mqttd @@ -2,6 +2,9 @@ daemon="/usr/local/sbin/mqttd" +# resource limits come from /etc/login.conf.d/mqttd +daemon_class="mqttd" + . /etc/rc.d/rc.subr rc_pre() { blob - c6c31160370218d60e19973b6b0a85f172f46419bbefe81289d1aa8c007cd078 blob + 563c0839c26ddb12f7b6cf3b245cc9a9d96f7da0283b4afe875e1ae4063154c1 --- mqttd/mqttd.8 +++ mqttd/mqttd.8 @@ -94,6 +94,24 @@ user with reduced .Xr pledge 2 promises. .Pp +Every client connection holds one descriptor in one sockets worker, and +each process raises its open file limit to the maximum of the login +class it was started under. +The rc script starts +.Nm +under the +.Dq mqttd +class, whose limits are set in +.Pa /etc/login.conf.d/mqttd . +The daemon carries about +.Ic workers +times that maximum in connections, so size the class for the expected +fleet and raise +.Va kern.maxfiles +in +.Xr sysctl.conf 5 +when the total approaches it. +.Pp Connection events are logged as .Dq key=value lines starting with @@ -170,9 +188,11 @@ Session state survives a restart only with enabled in .Xr mqttd.conf 5 . .Sh FILES -.Bl -tag -width "/var/run/mqttd.sockXX" -compact +.Bl -tag -width "/etc/login.conf.d/mqttdXX" -compact .It Pa /etc/mqttd.conf Default configuration file. +.It Pa /etc/login.conf.d/mqttd +Login class with the daemon's resource limits. .It Pa /etc/ssl/mqttd.crt Default TLS server certificate. .It Pa /etc/ssl/private/mqttd.key @@ -185,6 +205,7 @@ socket used for communication with Default persistence database. .El .Sh SEE ALSO +.Xr login.conf 5 , .Xr mqttd.conf 5 , .Xr mqttctl 8 .Sh STANDARDS blob - 7f4393bb862be5c2d156e9f2e8c0a25ad7e68e7235e6210a4468f91df270a816 blob + cb80f87240723b2fd9d016483baff07d4b03ede0fdcebc98cbe0d7906bb08cf8 --- mqttd/mqttd.conf.5 +++ mqttd/mqttd.conf.5 @@ -243,6 +243,9 @@ Publishes per second for this user, overriding Run the specified number of sockets worker processes. The listen process hands each new connection to the worker with the fewest connections. +Each worker holds its connections' descriptors, so the daemon carries +about this many times the open file limit of its login class; see +.Xr mqttd 8 . The default is 2, the maximum 32. .Ic prefork is accepted as a deprecated alias.