[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Maximum number of threads



I'm trying to investigate the maximum load a thread-intensive application can take. I discovered that the attached test program can't seem to create more than 6050 threads on a test machine with 384M memory. I'm running the program with stack size lowered to 48K and the maximum process count raised to a high value (100,000):

{frost}[~/c]$ ulimit -s 48
{frost}[~/c]$ ulimit -u 100000
{frost}[~/c]$ ./a.out 10000
Creating 10000 threads...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
[...]
6046 6047 6048 6049 6050 pthread_create: Resource temporarily unavailable


Before death the application consumes ~300M virtual size, and ~30M resident. The former figure is consistent with ~6000 threads multiplied with a 48K stack for each. There was free swap too, although that shouldn't matter, as thanks to overcommitting the machine didn't even start to swap. In fact, I'm not at all sure that the problem is memory-related, it was a mere first guess.

The error message doesn't specify which resource is unavailable, which makes it harder to diagnose the problem. Is there a system limit I forgot to raise?

I'm running linux 2.5.60 with what I assume is a fairly recent build of NPTL (glibc-2.3.1-43 from rawhide).

#include <pthread.h>
#include <stdio.h>

static void *
startup(void *arg_ignored)
{
  poll (NULL, 0, -1);
  return NULL;
}

int
main (int argc, char **argv)
{
  int num;
  int i = 0;
  if (argc != 2)
    {
      fprintf (stderr, "Usage: %s NUMBER\n", argv[0]);
      exit (2);
    }
  num = atoi (argv[1]);
  printf("Creating %d threads...\n", num);
  for (i = 0; i < num; i++)
    {
      pthread_t dummy;
      int res = pthread_create (&dummy, NULL, startup, NULL);
      if (res != 0)
        {
	  perror ("pthread_create");
	  sleep (100);
	  exit (1);
	}
      printf ("%d ", i + 1);
      fflush (stdout);
    }
  sleep (31);
  return 0;
}

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]