Ubuntu – Max number of simaltenous running process


The kernel says it can support up to 32768 process id at /proc/sys/kernel/pid_max, but how many process can my server handle simultaneously without complaining about resources or hangs my server,

I know it depends on each process behaviors and resources need, but is there some kind of equation that has some parameters like Ram, cache, cpu cores …etc?


My Server is hosted on Linode with following specifications:

RAM: 12 GB
CPU: Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz
cpu MHz     : 2499.970
cache size  : 4096 KB
Cores: 6 cores

My server has some old versions that run my application,

Apache 2.2 
mysql 5.5
php 5.3

Best Answer

There is a formula for calculating the maximum number of active PIDs or threads. Excerpt from kernel/fork.c:

 * set_max_threads
static void set_max_threads(unsigned int max_threads_suggested)

    u64 threads;

     * The number of threads shall be limited such that the thread
     * structures may only consume a small part of the available memory.
    if (fls64(totalram_pages) + fls64(PAGE_SIZE) > 64)
            threads = MAX_THREADS;
            threads = div64_u64((u64) totalram_pages * (u64) PAGE_SIZE,
                                (u64) THREAD_SIZE * 8UL);

    if (threads > max_threads_suggested)
            threads = max_threads_suggested;

    max_threads = clamp_t(u64, threads, MIN_THREADS, MAX_THREADS);

However, normally other limits will be hit first. If RAM and other resources last, then some cgroup limits will likely be first, where basically the limit is:

$ cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.max

The number, 12288, is the same on both my older 3 gigabyte server and my newer 16 gigabyte server.
And I can test by trying to spin out more than the maximum number, resulting in a message in /var/log/kern.log:

Feb 12 15:49:11 s15 kernel: [  135.742278] cgroup: fork rejected by pids controller in /user.slice/user-1000.slice

And checking the number I had at the time:

$ cat /sys/fs/cgroup/pids/user.slice/user-1000.slice/pids.current

top said about 12479

But after those processes ended, I got:

$ cat /sys/fs/cgroup/pids/user.slice/pids.current

top said about 205, and note: 12479 - 205 + 15 = 12289

Related Question