再会,
我希望我的 Apache Httpd 能够处理至少 7000 个(最好是 10k)并发请求。我已使用以下设置将 httpd.conf 配置为 MPM 工作器
ServerLimit 330
StartServers 25
ThreadsPerChild 25
MaxClients 7500
我的 Apache Httpd 服务器除了对 Java 应用服务器集群进行反向代理以及对一些静态项目(如 HTML/CSS/JS)进行一些(磁盘)缓存之外什么也不做。
当我尝试使用 JMeter(大约 1k 个并发请求)攻击我的系统时,几分钟后,我的服务器开始崩溃,但没有显示任何更多信息。
我的 /etc/security/limits.conf 配置为
* soft nofile 10000
* hard nofile 30000
apache soft nproc 8192
apache hard nproc 12288
* soft stack 512
* hard stack 1024
有什么想法可以让我达到 7k(或者最好是 10k)个并发请求
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Mon Apr 09 21:47:42 2012] [alert] Child 15139 returned a Fatal error... Apache is exiting!
[Mon Apr 09 21:47:42 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Mon Apr 09 21:47:46 2012] [warn] child process 14004 still did not exit, sending a SIGTERM
编辑(附加信息):
这是我尝试查看测试运行时有多少个活动的 httpd 进程(每个命令间隔约 1 秒 - 即我按下键盘上的向上键,然后按回车键)
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
5
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
5
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
8
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
8
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
8
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
9
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
10
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
10
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
10
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
10
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
10
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
11
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
11
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
13
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
13
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
17
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
17
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
25
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
25
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
41
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
41
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
39
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
37
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
37
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
36
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
1
[franz@webserver ~]$ ps -ef | grep httpd | wc -l
更新: 如果我添加 ThreadStackTrace,它就不会再崩溃:ServerLimit 330 StartServers 25 ThreadsPerChild 25 MaxClients 7500 ThreadStackSize 512
注意:在添加 ThreadStackSize 之前,我的 limits.conf 中就有堆栈条目,但我想这还不够。我必须在 limits.conf 中添加堆栈条目,并在 apache httpd.cofn 中添加 ThreadStackSize。
但是,它仍然无法处理 7500 个并发请求。当我执行 时ps -ef | grep httpd | wc -l
,我看到的最高值只有 42(由于其中一个进程是 grep 命令,这意味着大约有 41 个 apache httpd 进程)。但我已将 apache 配置为最多 330。
因此,为了查看我的 apache 配置是否真的可以超越 40 个进程,我尝试将我的 StartServers 修改为 50。
ServerLimit 330
StartServers 50
ThreadsPerChild 25
MaxClients 7500
ThreadStackSize 512
结果如下:
[Wed Apr 11 03:33:40 2012] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Apr 11 03:33:40 2012] [notice] Digest: generating secret for digest authentication ...
[Wed Apr 11 03:33:40 2012] [notice] Digest: done
[Wed Apr 11 03:33:40 2012] [warn] pid file /etc/httpd/run/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: setuid: unable to change to uid: 48
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [alert] (11)Resource temporarily unavailable: apr_thread_create: unable to create worker thread
[Wed Apr 11 03:33:40 2012] [notice] Apache/2.2.15 (Unix) DAV/2 mod_ssl/2.2.15 OpenSSL/1.0.0-fips configured -- resuming normal operations
[Wed Apr 11 03:33:40 2012] [alert] Child 55663 returned a Fatal error... Apache is exiting!
所以我猜主要问题是我无法产生超过 40 个进程。
更新2: 由于我似乎无法增加进程数,因此我尝试增加线程数。我最多只能将 ThreadsPerChild 增加到 30(从原始的 ThreadsPerChild 开始)。之后,Apache 无法启动,因为它似乎无法创建工作线程。
有人知道如何使用 Apache HTTPd 达到 10k 个并发请求吗?
为什么这不是重复的: 抱歉,我不确定为什么这被标记为重复。如果我的问题的答案是您能帮助我进行容量规划吗?,您能否重点说明如何以及在哪里?这个问题本质上是一般性的,而我的问题非常具体,更像是“向我展示如何使用 apache httpd 达到 c10k 或指出我的设置有什么问题”。
谢谢,
弗朗兹
答案1
增加操作系统对线程/进程的全局限制,并在系统“man pthread_create”中阅读有关其他潜在 EAGAIN 原因的信息。