Stack size patch for Varnish allows for more threads on Linux
By sru on Nov 4, 2009 in Caching in General, Varnish
As you may or may not know, on Linux the number of threads a process can spawn is theoretically unlimited. In reality, however, you will encounter a small problem there: Since the initial stack size for every user is set to a whooping 8 MB you will run out of memory for your thread’s stacks pretty fast. In general, you won’t get more than 280 to 300 threads up and running. And that’s way too few for heavy duty caches. There are two solutions to the problem:
- You edit
/etc/init.d/varnishand put aulimit -s 256somewhere at the beginning. This will reduce the stack size for processes started in this shell to 256KB. You can possibly go lower than that since 64KB is the minimum set by the POSIX thread library but my testing showed that going below 256KB won’t allow for any more threads. With a stack size of 256KB I managed to get to 32,757 threads running which is quite enough even for installations that get an awful lot of hits. - You use Ken’s patch which allows you to set Varnish’s stack size using the runtime parameter
-p thread__pool_stacksize=256. The patch applies cleanly to Varnish 2.0.4 as well as the current trunk. It comes in handy on installations where you can not or do not want to fiddle with environment parameters.
Sidenote: On Linux systems you may also want to do a sysctl -w kernel.pid_max=4194303 to increase the number of available pids. Otherwise you may still be stuck with a much lower number of threads than technically possible.

I could not find a contact form, but if you don’t mind can you plug my Squid headers normalization patch? It greatly improves cache-hit ratios on squid. The patch redefines squid to work more like varnish. Accept-Encoding is normalized and client’s are not allowed to by-pass cache.
http://letsgetdugg.com/2009/12/06/squid-headers-normalization-patch/