mailman3 nightly script(s) are leaking memory + mitigation
So as I mentioned in another thread, I have a shiny new install of mailman3 latest using venv (thanks, Brian!). It’s running on ubuntu 20.04 using python 3.8.2, django 2.2.12, nginx, postgres, and memcached.
The only functions this server runs are 1) postfix and dovecot for a small number of personal email accounts, and 2) mailman3 for a couple of mailing lists (one of which is fairly high traffic).
Not long after install, I saw a couple of instances of the OOM killer activating in the logs. I set up a 1GB swapfile (discouraged on Digital Ocean instances because they don’t like their flash drives to take that kind of pounding) as a safety net. Then I saw the free swap space eroding over time, so I started collecting some data.
Initial evening stats:
top - 23:29:16 up 15 days, 9:20, 1 user, load average: 0.07, 0.16, 0.17 Tasks: 200 total, 1 running, 199 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.0 us, 1.7 sy, 0.0 ni, 96.3 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st MiB Mem : 3936.2 total, 264.9 free, 1651.4 used, 2019.9 buff/cache MiB Swap: 1000.0 total, 811.2 free, 188.8 used. 1854.5 avail Mem
Stats the next morning:
top - 08:42:15 up 13 days, 18:33, 1 user, load average: 0.29, 0.27, 0.19 Tasks: 204 total, 1 running, 203 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.5 us, 1.4 sy, 0.0 ni, 96.0 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st MiB Mem : 3936.2 total, 214.7 free, 2244.8 used, 1476.7 buff/cache MiB Swap: 1000.0 total, 500.3 free, 499.7 used. 1318.8 avail Mem
Stats the next evening:
top - 23:26:00 up 14 days, 9:17, 1 user, load average: 0.10, 0.06, 0.08 Tasks: 209 total, 1 running, 208 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.6 us, 1.7 sy, 0.0 ni, 95.2 id, 0.3 wa, 0.0 hi, 0.3 si, 0.1 st MiB Mem : 3936.2 total, 206.0 free, 2253.6 used, 1476.6 buff/cache MiB Swap: 1000.0 total, 485.9 free, 514.1 used. 1305.5 avail Mem
Stats the following morning:
top - 08:09:32 up 14 days, 18:01, 1 user, load average: 0.01, 0.07, 0.14 Tasks: 194 total, 1 running, 193 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.0 us, 1.4 sy, 0.0 ni, 96.6 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st MiB Mem : 3936.2 total, 270.6 free, 1974.5 used, 1691.2 buff/cache MiB Swap: 1000.0 total, 266.5 free, 733.5 used. 1545.1 avail Mem
As you can see, something during the night is eating memory and not letting it go.
If I restart gunicorn, I get the memory back:
sudo systemctl restart gunicorn
top - 08:52:29 up 14 days, 18:44, 1 user, load average: 0.71, 0.49, 0.25 Tasks: 243 total, 1 running, 242 sleeping, 0 stopped, 0 zombie %Cpu(s): 6.1 us, 3.0 sy, 0.0 ni, 90.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st MiB Mem : 3936.2 total, 936.3 free, 1277.1 used, 1722.9 buff/cache MiB Swap: 1000.0 total, 804.8 free, 195.2 used. 2242.5 avail Mem
I did a little googling and a mitigation that seems to mostly work is to have gunicorn retire its workers periodically to free up memory.
gunicorn.cf: max_requests = 1000 max_requests_jitter = 50
That restarts a worker after 1000 requests and adds some jitter so they don’t all get restarted at the same time.
I am still seeing the erosion of a couple of MB of swap each day, but it’s WAY better than losing 250MB-350MB overnight.
FYI for others who may see this.
- Mark
mark@pdc-racing.net | 408-348-2878
On 7/24/20 5:51 PM, Mark Dadgar wrote:
top - 08:09:32 up 14 days, 18:01, 1 user, load average: 0.01, 0.07, 0.14 Tasks: 194 total, 1 running, 193 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.0 us, 1.4 sy, 0.0 ni, 96.6 id, 0.0 wa, 0.0 hi, 0.1 si, 0.0 st MiB Mem : 3936.2 total, 270.6 free, 1974.5 used, 1691.2 buff/cache MiB Swap: 1000.0 total, 266.5 free, 733.5 used. 1545.1 avail Mem
Hi Mark,
I am not seeing that on my Debian 10 server and I did your installation in the same manner as I did that server. I am running some pretty busy lists on that server now.
top - 19:56:23 up 21 days, 4:23, 1 user, load average: 0.08, 0.14, 0.11 Tasks: 159 total, 1 running, 158 sleeping, 0 stopped, 0 zombie %Cpu(s): 2.2 us, 1.2 sy, 0.0 ni, 96.5 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st MiB Mem : 3946.8 total, 281.5 free, 2049.0 used, 1616.3 buff/cache MiB Swap: 1024.0 total, 861.5 free, 162.5 used. 1456.3 avail Mem
-- Please let me know if you need further assistance.
Thank you for your business. We appreciate our clients. Brian Carpenter EMWD.com
-- EMWD's Knowledgebase: https://clientarea.emwd.com/index.php/knowledgebase
EMWD's Community Forums http://discourse.emwd.com/
participants (2)
-
Brian Carpenter
-
Mark Dadgar