Date: Thu, 17 Apr 2003 10:48:13 +0300 (EEST) From: Denis Fedorishenko To: oops@lists.paco.net В принципе можно включить в документацию: Основные требуемые tweaks для Linux: /usr/include/bits/types.h /* Number of descriptors that can fit in an `fd_set'. */ #define __FD_SETSIZE 32768 32768 - поменять на необходимое число файлдескрипторов, желательно максимальное количество нитей x 2; Если количество TCP клиентов не более 512, ничего трогать не нужно. Далее, по умолчанию в glibc с LinuxThreads (не с NPTL), установлено ограничение в 256 нитей. Его возможно увеличить до необходимых значений. Первый патч, как я понимаю определяет начальный размер стека, его необходимо уменьшить, иначе памяти не напасешься. *** glibc-2.2.5.org/linuxthreads/internals.h Thu Nov 29 08:44:16 2001 --- glibc-2.2.5/linuxthreads/internals.h Tue May 21 10:51:53 2002 *************** *** 343,349 **** THREAD_SELF implementation is used, this must be a power of two and a multiple of PAGE_SIZE. */ #ifndef STACK_SIZE ! #define STACK_SIZE (2 * 1024 * 1024) #endif /* The initial size of the thread stack. Must be a multiple of PAGE_SIZE. */ --- 343,349 ---- THREAD_SELF implementation is used, this must be a power of two and a multiple of PAGE_SIZE. */ #ifndef STACK_SIZE ! #define STACK_SIZE (128 * 1024) #endif /* The initial size of the thread stack. Must be a multiple of PAGE_SIZE. */ Второй патч, собственно снятие ограничителя на количество нитей. *** glibc-2.2.5.org/linuxthreads/sysdeps/unix/sysv/linux/bits/local_lim.h Thu Jun 8 21:49:49 2000 --- glibc-2.2.5/linuxthreads/sysdeps/unix/sysv/linux/bits/local_lim.h Tue May 21 10:52:58 2002 *************** *** 64,70 **** /* The number of threads per process. */ #define _POSIX_THREAD_THREADS_MAX 64 /* This is the value this implementation supports. */ ! #define PTHREAD_THREADS_MAX 1024 /* Maximum amount by which a process can descrease its asynchronous I/O priority level. */ --- 64,70 ---- /* The number of threads per process. */ #define _POSIX_THREAD_THREADS_MAX 64 /* This is the value this implementation supports. */ ! #define PTHREAD_THREADS_MAX 8192 /* Maximum amount by which a process can descrease its asynchronous I/O priority level. */ Затем пересобираете glibc, желательно пропатчить архивчик glibc*.tar.gz из src.rpm , затем положить его на место, и сделать rpmbuild -ba glibc.spec , не забыв подправить подверсию на единичку больше. После - всего лишь, проинсталлировать новый RPM. Это наиболее безопасный путь, таким образом я собрал glibc для RedHat 7.3, которые работают полгода безукоризненно. Пересобираете oops, и в путь. Реально, при одном гиге оперативной памяти у меня получалось около 3000-4000 нитей oops без нареканий. Далее kernel scheduler совместно с LinuxThreads на 2.4.20 начинают отчаянно хромать. С надеждой ждем NPTL + 2.6, и проводим тесты на 2.5 :) Программа для тестирования максимального количества нитей (соответственно обслуживаемых TCP клиентов в один момент времени). #include #include #include #define MAX_THREADS 10000 int i; void run(void) { char c; if (i < 10) printf("Address of c = %u KB\n", (unsigned int) &c / 1024); sleep(60 * 60); } int main(int argc, char *argv[]) { int rc = 0; pthread_t thread[MAX_THREADS]; printf("Creating threads ...\n"); for (i = 0; i < MAX_THREADS && rc == 0; i++) { rc = pthread_create(&(thread[i]), NULL, (void *) &run, NULL); if (rc == 0) { pthread_detach(thread[i]); if ((i + 1) % 1000 == 0) printf("%i threads so far ...\n", i + 1); } else printf("Failed with return code %i creating thread %i.\n",rc, i + 1); } exit(0); }