Memcached 并发与 lighttpd php
我遇到了 memcached 的问题。 不确定它是 memcached、php 还是 tcp 套接字,但每次我尝试对带有 memcached 的页面进行 50 或更多并发的基准测试时,其中一些请求使用 apache ab 会失败。 我收到 (99) 无法分配请求的地址错误。
当我对常规 phpinfo() 页面进行 5000 并发测试时。 一切安好。 没有失败的请求。
看来memcached不能支持高并发,还是我遗漏了什么? 我正在使用 -c 5000 标志运行 memcached。
服务器:(2) 四核 Xeon 2.5Ghz、64GB 内存、4TB Raid 10、64 位 OpenSUSE 11.1
I'm having an issue with memcached. Not sure if it's memcached, php, or tcp sockets but everytime I try a benchmark with 50 or more concurrency to a page with memcached, some of those request failed using apache ab. I get the (99) Cannot assign requested address error.
When I do a concurrency test of 5000 to a regular phpinfo() page. Everything is fine. No failed requests.
It seems like memcached cannot support high concurrency or am I missing something? I'm running memcached with the -c 5000 flag.
Server: (2) Quad Core Xeon 2.5Ghz, 64GB ram, 4TB Raid 10, 64bit OpenSUSE 11.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我已经弄清楚了。 也许这会帮助其他有同样问题的人。
看来这个问题可能是多种因素的结合。
将lighttpd.conf中的sever.max-worker设置为更高的数字
原来:16 现在:32
在lighttpd.conf中关闭keep-alive,它使连接保持打开状态的时间太长。
server.max-keep-alive-requests = 0
将 ulimit -n 打开文件数更改为更高的数量。
ulimit -n 65535
如果您使用的是 Linux,请使用:
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
增加 max-fds
server.max-fds = 2048
在回收之前降低tcp TIME_WAIT,这样可以更快地关闭连接。
在/etc/sysctl.conf中添加:
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3
确保使用以下命令强制重新加载:/sbin/sysctl -p
进行更改后,我的服务器现在正在运行 30,000 个并发连接和 1,000,000 个并发请求,没有任何问题、失败的请求或使用 apache ab 写入错误。
用于基准测试的命令: ab -n 1000000 -c 30000 http://localhost/test.php
我的 Apache 可以'甚至无法接近这个基准。 Lighttd 现在让我嘲笑 Apache。 Apache 以 200 左右的并发度爬行。
Ok, I've figured it out. Maybe this will help others who have the same problem.
It seems like the issue can be a combination of things.
Set the sever.max-worker in the lighttpd.conf to a higher number
Original: 16 Now: 32
Turned off keep-alive in lighttpd.conf, it was keeping the connections opened for too long.
server.max-keep-alive-requests = 0
Change ulimit -n open files to a higher number.
ulimit -n 65535
If you're on linux use:
server.event-handler = "linux-sysepoll"
server.network-backend = "linux-sendfile"
Increase max-fds
server.max-fds = 2048
Lower the tcp TIME_WAIT before recycling, this keep close the connection faster.
In /etc/sysctl.conf add:
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3
Make sure you force it to reload with: /sbin/sysctl -p
After I've made the changes, my server is now running 30,000 concurrent connections and 1,000,000 simultaneous requests without any issue, failed requests, or write errors with apache ab.
Command used to benchmark: ab -n 1000000 -c 30000 http://localhost/test.php
My Apache can't get even close to this benchmark. Lighttd make me laugh at Apache now. Apache crawl at around 200 concurrency.
我仅使用 4 字节整数,将其用作页面计数器以进行测试。 其他 php 页面即使在 5,000 个并发连接和 100,000 个请求下也能正常工作。 该服务器有大量的马力和内存,所以我知道这不是问题。
看起来死掉的页面只有 5 行代码来使用 memcached 测试页面计数器。 建立连接时出现此错误:(99) 无法分配请求的地址。
这就是我现在所拥有的一切,我将当我发现更多信息时发布更多信息。 看来有这个问题的人还不少。
I'm using just a 4 byte integer, using it as a page counter for testing purposes. Other php pages works fine even with 5,000 concurrent connections and 100,000 requests. This server have alot of horsepower and ram, so I know that's not the issue.
The page that seems to die have nothing but 5 lines to code to test the page counter using memcached. Making the connection gives me this error: (99) Cannot assign requested address.
That's all I have for now, I'll post more information as I found more. It seems like there are alot of people with this problem.
我刚刚用文件测试了类似的东西;
在带有 nginx、php-fastcgi 和 memcached 的小型虚拟机上运行。
我从同一网络中的笔记本电脑运行
ab -c 250 -t 60 http://testserver/memcache.php
,没有看到任何错误。您在哪里看到错误? 在你的 php 错误日志中?
I just tested something similar with a file;
running on a tiny virtual machine with nginx, php-fastcgi, and memcached.
I ran
ab -c 250 -t 60 http://testserver/memcache.php
from my laptop in the same network without seeing any errors.Where are you seeing the error? In your php error log?
这就是我在 /etc/sysctl.conf 中用于 Nginx/php-fpm 的内容 @ Rackspace 专用服务器与 Memcached/Couchbase/Puppet:
我希望它有帮助。
This is what I used for Nginx/php-fpm adding this lines in /etc/sysctl.conf @ Rackspace dedicate servers with Memcached/Couchbase/Puppet:
I hope it helps.