5

For network apps that create one thread per connection (like Pound), threadcount can become a bottleneck on the number of concurrent connections you can server.

I'm running FreeBSD 8 x64:

$ sysctl kern.maxproc
kern.maxproc: 6164

$ sysctl kern.threads.max_threads_per_proc
kern.threads.max_threads_per_proc: 1500

$ limits
Resource limits (current):
  cputime              infinity secs
  filesize             infinity kB
  datasize             33554432 kB
  stacksize              524288 kB
  coredumpsize         infinity kB
  memoryuse            infinity kB
  memorylocked         infinity kB
  maxprocesses             5547
  openfiles              200000
  sbsize               infinity bytes
  vmemoryuse           infinity kB
  pseudo-terminals     infinity
  swapuse              infinity kB

I want to increase kern.threads.max_threads_per_proc to 4096. Assuming each thread starts with a stack size of 512k, what else do I need to change to ensure that I don't hose my machine?

masegaloeh
  • 17,978
  • 9
  • 56
  • 104
sh-beta
  • 6,756
  • 7
  • 46
  • 65
  • For a sane application you shouldn't be running into the max_threads limit. But then, scaling applications is rarely sane. Performance suffers when you have thousands of threads. Instead of screwing with the limits, that are pretty high, it's worth considering replacing Pound with Pen, or another load balancer with is select() based. That will get you a bit further before you run into the OS limits. – pehrs Apr 21 '10 at 21:13
  • select() has fairly low limits as well, though you'll see much better performance when you've got a thousand connections going. On the BSDs kqueue is the way to go, on Linux epoll. But this is a discussion for the developers (whom you should be contacting, and requesting they change their app, thread-per-connection is old-school). – Chris S Apr 21 '10 at 23:01
  • Let's assume that Pound is in there for a reason (it is) and can't be trivially replaced (it can't). – sh-beta Apr 21 '10 at 23:18

1 Answers1

1

FWIW, I set kern.threads.max_threads_per_proc to 4096 without modifying any other settings and haven't seen any ill effects. Pound even got there a couple times (eating up 2GB of RAM while doing so).

sh-beta
  • 6,756
  • 7
  • 46
  • 65