apr_socket_recv: Connection reset by peer (104)

在使用apache ab测试apache httpd server时,提示错误:?apr_socket_recv: Connection reset by peer (104)和apr_poll: The timeout specified has expired (70007)的一些相关资料。

apr_socket_recv: Connection reset by peer (104)

一、apr_socket_recv: Connection reset by peer (104)和apr_poll: The timeout specified has expired (70007)错误提示

修改了apache配置,使用prefork模式,将最大连接数(MaxClients)由原来的256改为了2048, 注意修改Apache 最大连接数时,如果数值大于256,那么除了修改?MaxClients ,还要再加上 ServerLimit,ServerLimit 相当于水桶,MaxClients (最大连接数)相当于水,水的容量不能超过水桶,将 ServerLimit?改为2048 注意ServerLimit 此时也不宜太大,如改成4096,这样没有作用,反而会消耗过多共享内存,只要改成和MaxClients 一样就行了。

,进行ab测试,出现错误:apr_socket_recv: Connection reset by peer (104)和apr_poll: The timeout specified has expired (70007).

  • 环境
apache版本:2.2.11
linux内核版本: 2.6.18

首先将apache停止再启动,重新启动。

apachectl stop
apachectl start

然后使用ab进行测试:

[root@test bin]# ab -n 100000 -c 1000 http://192.168.254.136/hello.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.254.136 (be patient)
Completed 10000 requests
apr_socket_recv: Connection reset by peer (104)
Total of 15739 requests completed

出现错误:

apr_socket_recv: Connection reset by peer (104)

有时出现如下错误:

[root@test bin]# ab -n 100000 -c 500 http://192.168.254.136/hello.html
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 192.168.254.136 (be patient)
Completed 10000 requests
apr_poll: The timeout specified has expired (70007)
Total of 16379 requests completed

出现错误:

 apr_poll: The timeout specified has expired (70007)

解决方法

  • 修改apache源代码 – 没有效果,同样会出现错误

网上有篇文章,提示说修改apache源代码目录下的support/ab.c,大概1369行,修改为:

1367                 }
1368                 return;
1369             } else {
1370                 //apr_err("apr_socket_recv", status); //原來的
1371                 bad++;
1372                 close_connection(c);
1373                 return;
1374
1375             }
1376         }
1377     }

修改完成,重新编绎,安装,我特地将apache另外安装了一个目录,并将配置修改为与原来一样,重新运行测试,发现结果还是一样。

还是提示错误:

apr_socket_recv: Connection reset by peer (104)
  • 优化内核参数

另外还看一个解决建议:tcp_max_syn_backlog设置小了,下面贴上我的内核优化参数

# sysctl -p
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 0
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv4.tcp_max_syn_backlog = 819200
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_max_tw_buckets = 819200
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

禁用了Syncookies,因为在高并发的情况下,内核会认为系统受到了SYN flood攻击,会发送cookies(possible SYN flooding on port 80. Sending cookies),这样会减慢影响请求的速度。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>