- 浏览: 589866 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
kangh:
转载的也拿出来 都不试一下 完全错误
Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解 -
wangtxlz:
#cd builders/cmake#cmake .系统提示命 ...
crtmpserver流媒体服务器的介绍与搭建 -
hnraysir:
支持支持支持
手机Android音视频采集与直播推送,实现单兵、移动监控类应用 -
wuent:
把web服务器和php框架绑定到一起?真不建议这样。。。
Swoole(PHP高级Web开发框架) -
wuent:
有更详细的性能比较吗?php,python,java
PHP中的(伪)多线程与多进程
This document describes how to modify the per-process file descriptor limit and task limit of the Linux version 2.2 kernel to increase the number of sockets and threads that a Java server application can create. In particular, it describes the socket and thread requirements of the VOLANO® chat server, but similar requirements are likely to exist in any server application written for the Java platform. Note that the current Linux kernel version is 2.6, so this information is unlikely to apply to any recent Linux distribution.
File descriptors and tasks
When running on the Linux 2.2 kernel, each process is limited by default to 1,024 file descriptors. Since the VolanoChat server requires one file descriptor for each person chatting through a VolanoChat applet, you are limited by default to a maximum of 1,024 simultaneous users when using the Linux 2.2 kernel.
Some Java virtual machines, such as the IBM Developer Kit for Linux, Java Technology Edition, use native threads on Linux which require one task for each Java thread. Since VolanoChat requires two Java threads for each connection, you may need to increase the maximum number of tasks per user for such virtual machines. The default maximum number of tasks in a Linux 2.2 system is 512, with a maximum of 256 tasks per user. So by default, a VolanoChat server running under IBM JDK 1.1.6 for Linux can support a maximum of 128 people chatting at the same time.
You can increase the limits testing the the number of file descriptors and the number of tasks in the Linux 2.2 kernel by following the steps below. These steps were performed on a Red Hat Linux 6.0 system using Linux kernel 2.2.5-15. The instructions may be different for your Linux system.
To increase the maximum file descriptors per process to 4,096 (from 1,024) and the maximum tasks per user to 4,090 (from 256) on Linux 2.2, do the following steps.
-
Change the following C header files.
In
/usr/include/linux/tasks.h
, change:NR_TASKS 512 to 4090 MAX_TASKS_PER_USER (NR_TASKS/2) to NR_TASKS
In
/usr/include/linux/limits.h
, change:NR_OPEN 1024 to 4096 OPEN_MAX 256 to 4096
In
/usr/include/linux/posix_types.h
, change:__FD_SETSIZE 1024 to 4096
In
/usr/include/bits/types.h
, change:__FD_SETSIZE 1024 to 4096
-
To allow users to increase their file descriptor limits, change the following configuration files:
In
/etc/security/limits.conf
, add the lines:* soft nofile 1024 * hard nofile 4096
In
/etc/pam.d/login
, add:session required /lib/security/pam_limits.so
- To increase the system-wide file descriptor limit, add the following three lines to the
/etc/rc.d/rc.local
startup script:# Increase system-wide file descriptor limit. echo 8192 > /proc/sys/fs/file-max echo 24576 > /proc/sys/fs/inode-max
-
Change to the directory
/usr/src/linux
and set up the kernel sources with:make mrproper
-
Make any other kernel configuration changes, such as setting the processor family type, by entering the command below. Save your changes and exit the configuration panel when you are done.
make xconfig
-
Prepare for the kernel build by entering:
make dep make clean
-
Rebuild your kernel with the commands:
make bzImage make modules
-
Backup your old modules directory by entering (for example):
mv /lib/modules/2.2.5-15 /lib/modules/2.2.5-15.old
-
Create a new set of kernel modules with the command:
make modules_install
-
Backup your old kernel by entering (for example):
mv /boot/vmlinuz /boot/vmlinuz.old
-
Copy over your new kernel image with:
cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz
-
Edit the Linux loader configuration in
/etc/lilo.conf
so that your new kernel is the default and your old kernel is still available from the boot prompt, as in the example shown below:boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 image=/boot/vmlinuz label=linux root=/dev/hda1 read-only image=/boot/vmlinuz.old label=linux.old root=/dev/hda1 read-only
-
Generate the new Linux loader configuration by running:
/sbin/lilo
-
Shutdown and reboot with your new kernel by entering:
shutdown -r now
-
After rebooting, verify that the changes were effective as shown in the sections below.
LinuxThreads 0.7 limits
Even after you rebuild your Linux 2.2 kernel to increase the maximum number of threads per Linux user from 256 to 4,090, there are still definitions in the thread library itself which limit the number of threads per process to less than 1,000. The VolanoChat server requires two threads for each person chatting through a VolanoChat applet, so the LinuxThreads implementation creates a limit of 500 people to a single VolanoChat server.
You can increase this limit to 8,192 threads with the following steps. Even though the thread library will allow 8,192 threads per process after these changes, you'll still be limited by the Linux 2.2 kernel to a maximum of 4,090 threads for the Linux user account running the VolanoChat server after the changes in the previous section. The steps below are shown for a Red Hat Linux 6.0 system, so they may be different for your Linux distribution.
-
Install the Glibc 2.1.1 source package from
/mnt/cdrom/SRPMS/glibc-2.1.1-6.src.rpm
on the Red Hat Linux CD-ROM #2. -
Unpack the source archive
/usr/src/redhat/SOURCES/glibc-990416.tar.gz
so that you can modify two of the files. -
Change the following C header files.
In
/usr/src/redhat/SOURCES/glibc/linuxthreads/internals.h
, change the size of the thread stack reserve from 2 megabytes down to 256 kilobytes (with a page size of 4,096 bytes):STACK_SIZE (2 * 1024 * 1024) -> (64 * PAGE_SIZE)
In
sysdeps/unix/sysv/linux/bits/local_lim.h
under/usr/src/redhat/SOURCES/glibc/linuxthreads
, change the Posix thread implementation limit from 1,024 per process to 8,192 per process:PTHREAD_THREADS_MAX 1024 -> 8192
-
Rebuild the source archive,
/usr/src/redhat/SOURCES/glibc-990416.tar.gz
, to include your changes, replacing the original copy. -
Change to the RPM specification directory,
/usr/src/redhat/SPECS
, and enter the command:rpm -ba glibc-2.1.spec
-
After a few hours, the new LinuxThreads library will be found as
libpthread.so
under:/usr/src/redhat/BUILD/glibc/build-i386-linux/linuxthread
-
Copy the new thread library into your own
lib
subdirectory:cd /usr/src/redhat/BUILD/glibc/build-i386-linux cp linuxthread/libpthread.so ~/lib cd ~/lib ln -s libpthread.so libpthread.so.0
-
Define the environment variable
LD_LIBRARY_PATH
to include the subdirectory containing the new thread librarylibpthread.so
. -
Verify the new thread limits as instructed below.
Verifying the new file descriptor limit
Increase your new limits to their maximum by entering "ulimit -n 4096"
for the Bash shell or "unlimit"
for the C shell. You can then check whether your changes were effective by running the following C program:
#include <sys/types.h> #include <fcntl.h> #include <stdio.h> void main(void) { int k = 3; while (dup(0) != -1) k++; printf("Opens = %d Fdsize = %d\n", k, sizeof(fd_set) * 8); }
Both numbers printed should give your new file descriptor limit.
Verifying the new thread limit
You can use the following program to verify your new thread limits in the modified Linux 2.2 kernel and in the modified LinuxThreads library.
#include <stdio.h> #include <unistd.h> #include <pthread.h> #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); }
Compile the program with:
gcc -lpthread -o count count.c
Running with the original LinuxThreads library will print:
blue:/home/john> count Creating threads ... Address of c = 3137535 KB Address of c = 3135487 KB Address of c = 3133439 KB Address of c = 3131391 KB Address of c = 3129343 KB Address of c = 3127295 KB Address of c = 3125247 KB Address of c = 3123199 KB Address of c = 3121151 KB 1000 threads so far ... Failed with return code 11 creating thread 1023.
while running with the modified LinuxThreads library will print:
blue:/home/john> count Creating threads ... Address of c = 3144703 KB Address of c = 3144447 KB Address of c = 3144191 KB Address of c = 3143935 KB Address of c = 3143679 KB Address of c = 3143423 KB Address of c = 3143167 KB Address of c = 3142911 KB Address of c = 3142655 KB 1000 threads so far ... 2000 threads so far ... 3000 threads so far ... 4000 threads so far ...
You may need to enter Ctrl-C
to exit the program.
Notice that the thread stack addresses are spaced apart by 256 kilobytes instead of the earlier reserve of 2 megabytes per stack. Also notice that the program can create threads right up to the Linux 2.2 kernel limit of 4,090 for the system rather than the earlier LinuxThreads limit of 1,024 per process.
http://www.volano.org/articles/linux-2.2-sockets-threads/
发表评论
-
select、poll、epoll之间的区别总结
2015-04-02 11:49 0select,poll,epoll都是IO多路复用的机制。I ... -
TCP状态转移图学习总结 (转)
2015-04-02 11:37 0TCP状态转移图学习总结 (转) 这是网络编程的基础,t ... -
(原)CentOS Linux 下安装Samba
2015-01-21 10:18 0一、Samba简介 samba ... -
Java 通过JNI调用C或者CPP代码
2014-10-22 18:20 1187网上搜罗到一个JNI的例子,不错。用cygwin的环境搞了下 ... -
CentOS配置mencoder和ffmpeg flv视频转码总结
2013-11-15 22:04 11521、安装yum的fpmforge源 rpm - ... -
用ffmpeg打造linux转码服务器
2013-11-15 21:54 1332linux在系统资源利用上确实要比windows强很多,所以 ... -
Linux下文件的三种时间标记:访问时间、修改时间、状态改动时间
2012-11-16 16:01 1299在windows下,一个文件有:创建时间、修改时间、访问 ... -
常用awk命令(转)
2012-11-16 13:54 952awk 用法:awk ' pattern {action ... -
php写后端运行程序总结
2012-03-21 23:44 20021、定时执行 就crontab了,li ... -
PHP调用Linux系统的常用函数
2012-03-14 00:10 0PHP调用Linux系统的常用函数 1、exec函数 ... -
删除Linux环境中的默认JDK安装版本
2012-02-29 19:23 1823下面以Fedora8为例: [root@fc8 bin ... -
linux tr命令详解
2012-02-28 22:06 1235通过使用 tr,您可以非常容易地实现 sed 的许多最 ... -
cannot restore segment prot after reloc错误的解决方法
2012-02-21 01:33 1603最近用到gearman。由于C语言的server一直编译不过去 ... -
Linux(CentOS)下更改/转移MySQL数据库目录
2012-02-19 00:16 1047由于MySQL的 ... -
centos安装中文支持
2012-02-15 16:39 3526默认安装为英文的 现在想设置成中文yumgroupinstal ... -
安装及配置eaccelerator-0.9.5加速PHP-5.2.1
2012-02-11 09:37 1173操作系统:Linux ... -
Linux EXT3文件系统下成功恢复误删的mysl数据库
2012-02-09 12:18 1313环境:CentOS 5.3 x86_64下,/dev/sd ... -
Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器[转载]
2012-02-09 12:18 1278[文章作者:张宴 本文版本:v6.3 最后修改:2010. ... -
Centos 开起自动启动设置
2012-02-06 09:08 1429CentOS下添加程序到服务并且设置服务自动启动的两种方法 ... -
linux增加根目录的磁盘空间(LVM)
2012-02-06 09:08 6181第一步:添加磁盘 第二步:使用Linux下的fdis ...
相关推荐
文档介绍了一.基础知识:线程和进程,二.Linux 2.4内核中的轻量进程实现,三.LinuxThread的线程机制,1.线程描述数据结构及实现限制,2....嵌入式linux开发教程:线程的创建,6.LinuxThreads的不足
LinuxThreads所采用的是线程-进程"一对一"模型,调度交给核心,而在用户级实现一个包括信号处理在内的线程管理机制。 本文描述Linux-LinuxThreads的运行机制
请大家多看看,下载,是好资料是嵌入式必须的工具
NPTL[2] 使用内核的新特性重写了 Linux 的线程库,取代历史悠久而备受争议的 LinuxThreads [3] 成为 glibc 的首选线程库。NPTL 的性能究竟如何?相对 LinuxThreads 又有哪些明显的改进?在对 NPTL 进行全面分析之前...
read-glibc-linuxthreads-2.3 linuxthreads多线程源码分析
read-linuxthreads-2.0.1-code:linux线程的实现源码分析
Linux 线程浅析
gnu安装包
SystemSim_x86_rhel3_2.0.tar.bz2是一个linux下的AIX模拟器 工具之一
glibc-linuxthreads-2.3.2.tar.gz
glibc-linuxthreads-2.3.5.tar.gz
安装glibc必备的linux下辅助安装包
这是Libc用于支持Posix线程而单独发布的一个压缩包。
glibc-linuxthreads-2.3.3.tar.gz
一个进程池的服务器程序 ... 流程大概如下: 1,父进程listen,创建pipe(下面所有父子进程之间的通信都用该pipe) 2,父进程预fork n个子进程 3,各个子进程accept(listenfd),即所有子进程竞争accept请求。...
嵌入式交叉编译环境,libc用于支持Posix线程单独发布的压缩包.
它目前不需修改就可以在 GNU Hurd,Linux i386, m68k, 以及 alpha 系统上执行,而 2.1 版中将加入对 Linux PowerPC, MIPS, Sparc, Sparc 64 与 Arm 等系统的支持。未来将加入对其它架构及作业系统的支持。 在...
修改src/base/linuxthreads.cc static void SignalHandler(int signum, siginfo_t *si, void *data) 其中 siginfo_t *si 改成 siginfo *si echo "please modify the src/debugallocation.cc" echo " DEFINE_bool...
gnu安装包
gnu安装包