koldfront

Plugging a memory leak #haskell #munin

🕗︎ - 2024-08-03

This graph tells a story:

Graph showing memory usage growing from July 19 to July 29, with a fall and then a steady level until August 2.

I have been experimenting with writing Haskell applications to run websites for a while. So far I have a website for Feedbase, a blog engine with NNTP-interface, a small wiki, and a (primarily NNTP) ActivePub server.

Annoyingly the webservers have been leaking memory, to the tune of gigabytes per week. And I haven't been able to figure out why.

I'm a Haskell novice (yes, still) so I have been looking at stuff like "do I use foldl" and switching to foldl' and stuff like that I could find by searching for "Haskell" and "memory leak".

At one point I even extracted the pages from this websites' log and redid all the requests locally on my laptop - but I was unable to reproduce the memory usage ballooning that way.

At one point somebody figured out that the Spock Haskell web framework has a leak, so I switched to Twain. My applications still leaking, though.

Earlier this week, while sitting on a long train ride, I realized that one of the differences between my server setup and the local test setup on the laptop was that the Haskell applications are proxied behind Apache.

My code, especially in Sixpence - the wiki, is quite simple, so I was at a loss to figure out where the leak was, but then I thought "How about those middleware modules I'm using?" - and I tried turning all of them off in the wiki and half in the blog-engine.

The result is what the graph shows!

My guess currently is that it's the Gzip and Brotli middleware plugins I was using that caused the leaking when behind Apache. Furthermore, testing with curl it turns out that they aren't necessary, as Apache handles the compression.

So now I have removed the middleware modules - can't wait to check the Munin graph in a couple of weeks!

A follow up some 5 weeks later:

Graph of memory usage, showing a saw tooth pattern in the beginning, and later a more level usage

I'd say that counts as fixed!

- Adam Sjøgren 🕦︎ - 2024-09-14

+=

Add comment

To avoid spam many websites make you fill out a CAPTCHA, or log in via an account at a corporation such as Twitter, Facebook, Google or even Microsoft GitHub.

I have chosen to use a more old school method of spam prevention.

To post a comment here, you need to:

¹ Such as Thunderbird, Pan, slrn, tin or Gnus (part of Emacs).

Or, you can fill in this form:

+=