[Haskell-cafe] "too many open files" using snap

Gregory Collins greg at gregorycollins.net
Sun Jan 8 15:27:47 CET 2012


On Sun, Jan 8, 2012 at 7:25 AM, Eric Wong <wsysdu at gmail.com> wrote:

> Hi haskellers,
>
> I wrote a web server using snap framework. Basically, it's an API server
> using hdbc-mysql to connect to a mysql server. But it also serves some
> static web pages and images, using the serveDirectory function in
> snap-core. The program eats more and more memory slowly, but I couldn't
> spot the leak. It uses less than 10MB memory when starting. Sometimes, it
> can grow to 60-70MB and stop working correctly. Then I find that the log
> file is full of "too many open files" error. As I don't have any code open
> any files, I suspect it's the serveDirectory leaking. But I don't have any
> expertise on the core of snap, so, could some one give me some advice on
> this problem?
>

I'm fairly certain there's no leak in Snap in this code, although I will
gladly accept evidence to the contrary -- I've been load-testing
"serveDirectory" at 20,000 qps for a couple of minutes now, with no
increase in the memory resident size.

A "too many open files" error is usually due to running out of file
descriptors for network sockets. On my Linux machine the per-process limit
for file descriptors defaults to 1024, and on my Mac the default is 256.
You can see your current limit by running "ulimit -a" from the terminal.

Each incoming socket occupies a file descriptor, as does every open
connection to your database and every open file. When these run out, calls
to accept() or to open files start failing and you get this error message.

Memory profiling should help you find the leak.

G
-- 
Gregory Collins <greg at gregorycollins.net>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120108/7c3e9a42/attachment.htm>


More information about the Haskell-Cafe mailing list