Memcached 并发与 lighttpd php

发布于 2024-07-30 17:37:09 字数 359 浏览 3 评论 0原文

我遇到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

七七 2024-08-06 17:37:09

好吧,我已经弄清楚了。 也许这会帮助其他有同样问题的人。

看来这个问题可能是多种因素的结合。

  1. 将lighttpd.conf中的sever.max-worker设置为更高的数字
    原来:16 现在:32

  2. 在lighttpd.conf中关闭keep-alive,它使连接保持打开状态的时间太长。
    server.max-keep-alive-requests = 0

  3. 将 ulimit -n 打开文件数更改为更高的数量。
    ulimit -n 65535

  4. 如果您使用的是 Linux,请使用:
    server.event-handler = "linux-sysepoll"
    server.network-backend = "linux-sendfile"

  5. 增加 max-fds
    server.max-fds = 2048

  6. 在回收之前降低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.

  1. Set the sever.max-worker in the lighttpd.conf to a higher number
    Original: 16 Now: 32

  2. Turned off keep-alive in lighttpd.conf, it was keeping the connections opened for too long.
    server.max-keep-alive-requests = 0

  3. Change ulimit -n open files to a higher number.
    ulimit -n 65535

  4. If you're on linux use:
    server.event-handler = "linux-sysepoll"
    server.network-backend = "linux-sendfile"

  5. Increase max-fds
    server.max-fds = 2048

  6. 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.

美羊羊 2024-08-06 17:37:09

我仅使用 4 字节整数,将其用作页面计数器以进行测试。 其他 php 页面即使在 5,000 个并发连接和 100,000 个请求下也能正常工作。 该服务器有大量的马力和内存,所以我知道这不是问题。

看起来死掉的页面只有 5 行代码来使用 memcached 测试页面计数器。 建立连接时出现此错误:(99) 无法分配请求的地址。

  • 这个问题从 50 个并发连接开始出现。
  • 我正在使用 -c 5000 运行 memcached 以实现 5000 个并发。
  • 一切都在一台机器上(本地主机)
  • 唯一运行的进程是 SSH、Lighttpd、PHP 和 Memcached
  • 没有用户连接到此机器(测试机器)
  • Linux -nofile 设置为 32000

这就是我现在所拥有的一切,我将当我发现更多信息时发布更多信息。 看来有这个问题的人还不少。

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.

  • This problem start to arise starting with 50 concurrent connections.
  • I'm running memcached with -c 5000 for 5000 concurrency.
  • Everything is on one machine (localhost)
  • The only process running is SSH, Lighttpd, PHP, and Memcached
  • There are no users connected to this box (test machine)
  • Linux -nofile is set to 32000

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.

往事风中埋 2024-08-06 17:37:09

我刚刚用文件测试了类似的东西;

$mc = memcache_connect('localhost', 11211);
$visitors = memcache_get($mc, 'visitors') + 1;
memcache_set($mc, 'visitors', $visitors, 0, 30);
echo $visitors;

在带有 nginx、php-fastcgi 和 memcached 的小型虚拟机上运行。

我从同一网络中的笔记本电脑运行 ab -c 250 -t 60 http://testserver/memcache.php ,没有看到任何错误。

您在哪里看到错误? 在你的 php 错误日志中?

I just tested something similar with a file;

$mc = memcache_connect('localhost', 11211);
$visitors = memcache_get($mc, 'visitors') + 1;
memcache_set($mc, 'visitors', $visitors, 0, 30);
echo $visitors;

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?

聽兲甴掵 2024-08-06 17:37:09

这就是我在 /etc/sysctl.conf 中用于 Nginx/php-fpm 的内容 @ Rackspace 专用服务器与 Memcached/Couchbase/Puppet:

# Memcached 修复

net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3

我希望它有帮助。

This is what I used for Nginx/php-fpm adding this lines in /etc/sysctl.conf @ Rackspace dedicate servers with Memcached/Couchbase/Puppet:

# Memcached fix

net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 3

I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文