Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the limit of maximum number of pthreads by an application

Tags:

limit

pthreads

Is it possible by any means to change the limit on the number of pthreads a process can create ? Currently on my linux system I can create around 380 threads but I want to increase that to say as long as memory is available.

like image 299
Sukanto Avatar asked Dec 22 '09 15:12

Sukanto


People also ask

Is it possible to increase the number of threads within processes?

Thus, the number of threads per process can be increased by increasing total virtual memory. The amount of stack size per thread is more likely to be the limit than anything else. Reducing the per-thread stack size is also a way to increase the total number of threads.

How do I change my proc sys kernel threads Max?

You can control the maximum number of threads using the thread-max kernel parameter. “file /proc/sys/kernel/threads-max” defines this parameter. Using the “cat” command, you can view this file. Here, the output 45444 shows the maximum 45444 threads the kernel can execute.

Is there a limit to the number of threads?

Thread Limits Because each thread consumes part of a process's address space, processes have a basic limit on the number of threads they can create that's imposed by the size of their address space divided by the thread stack size.

What are the two main scheduling policies available with pthreads?

The scheduling policy can either be SCHED_FIFO or SCHED_RR. FIFO is a first come first serve policy. RR is a round robin policy that might preempt threads.


2 Answers

reduce user's stack size 'ulimit -s 1024';

default: 8MB 
reduced: 1MB 

to increase number of threads.

set the stack size: pthread_attr_setstacksize(1024)

like image 150
saju Avatar answered Oct 27 '22 19:10

saju


cat /proc/sys/kernel/threads-max

may work in Linux but not other UNIX systems. I thought the right way is

Maximum number of threads per process - sysconf(_SC_THREAD_THREADS_MAX) failing

which works on some UNIX systems (like HPUX) but not on Solaris or Linux...

like image 44
Reza Toghraee Avatar answered Oct 27 '22 18:10

Reza Toghraee