]> Sergey Matveev's repositories - public-inbox.git/commit
nntp: reduce memory overhead of zlib
authorEric Wong <e@80x24.org>
Fri, 5 Jul 2019 22:53:39 +0000 (22:53 +0000)
committerEric Wong <e@80x24.org>
Sat, 6 Jul 2019 04:33:39 +0000 (04:33 +0000)
commita3c054cbbf2a51be121b3237c5d223acc5c8a2f4
tree7ea4e22652ad3063d6cc84c39a3aec4cacbf4eb6
parent77c66b4cdb1d52321ed3cb6352fe0b72312cbb71
nntp: reduce memory overhead of zlib

Using Z_FULL_FLUSH at the right places in our event loop, it
appears we can share a single zlib deflate context across ALL
clients in a process.

The zlib deflate context is the biggest factor in per-client
memory use, so being able to share that across many clients
results in a large memory savings.

With 10K idle-but-did-something NNTP clients connected to a
single process on a 64-bit system, TLS+DEFLATE used around
1.8 GB of RSS before this change.  It now uses around 300 MB.
TLS via IO::Socket::SSL alone uses <200MB in the same situation,
so the actual memory reduction is over 10x.

This makes compression less efficient and bandwidth increases
around 45% in informal testing, but it's far better than no
compression at all.  It's likely around the same level of
compression gzip gives on the HTTP side.

Security implications with TLS?  I don't know, but I don't
really care, either...  public-inbox-nntpd doesn't support
authentication and it's up to the client to enable compression.
It's not too different than Varnish caching gzipped responses
on the HTTP side and having responses go to multiple HTTPS
clients.
lib/PublicInbox/DS.pm
lib/PublicInbox/NNTP.pm
lib/PublicInbox/NNTPdeflate.pm
t/nntpd-validate.t