Lighttpd

lighttpd:後端超載

  • January 14, 2013

我有一個高流量的網站,我正在努力維護,但有時會遇到高峰卡住:

(mod_fastcgi.c.2900) backend is overloaded; we'll disable it for 2 seconds and send the request to another backend instead: reconnects: 0 load: 2541

目前的統計數據是:

absolute (since start)
Requests    15 kreq
Traffic 20.02 Mbyte
average (since start)
Requests    81 req/s
Traffic 106.24 kbyte/s
average (5s sliding average)
Requests    94 req/s
Traffic 99.23 kbyte/s

3952 connections

該站點本身是一個非常簡單的 PHP 站點,不涉及 MySQL。我確實安裝並配置了 APC。

我在 /etc/sysctl.conf 中添加了建議的更改:

# These ensure that TIME_WAIT ports either get reused or closed fast.
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1

# TCP memory
net.core.rmem_max = 16777216
net.core.rmem_default = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144

net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_max_orphans = 262144

我的 lighttpd.conf 看起來像:

server.max-fds = 12000
server.max-keep-alive-requests = 0
server.event-handler = "linux-sysepoll"
server.max-connections = 10000

fastcgi 配置:

## Start an FastCGI server for php (needs the php5-cgi package)
fastcgi.server    = ( ".php" =>
   ((
           "bin-path" => "/usr/bin/php-cgi",
           "socket" => "/tmp/php.socket",
           "max-procs" => 14,
           "bin-environment" => (
                   "PHP_FCGI_CHILDREN" => "30",
                   "PHP_FCGI_MAX_REQUESTS" => "100000"
           ),
           "bin-copy-environment" => (
                   "PATH", "SHELL", "USER"
           ),
           "broken-scriptfilename" => "enable"
   ))
)

伺服器使用率:

top - 08:04:26 up 97 days, 15:14,  1 user,  load average: 0.10, 0.08, 0.04
Tasks: 570 total,   3 running, 567 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.9%us,  0.2%sy,  0.0%ni, 98.5%id,  0.3%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   4056176k total,  3716120k used,   340056k free,   631600k buffers
Swap:   995988k total,    15544k used,   980444k free,  1631236k cached

我嘗試了各種各樣的事情。我知道擁有高 mac procs 通常不好,但是如果我把它放低,伺服器會立即開始拋出 500 錯誤。

有沒有人有什麼建議可以嘗試調整以保持網站穩定?在單個伺服器上支持這種級別的流量是否合理?

“後端超載” - 這意味著 14 個後端之一超載(lighttpd通過附加“-”max-procs為每個後端創建不同的套接字max-procs

$$ number $$" 到套接字文件名)。 我會選擇較低的 max-procs 數字,而是增加 PHP_FCGI_CHILDREN,例如"max-procs" => 2and "PHP_FCGI_CHILDREN" => "210",或 4 和 100(或 1 和 400)。

這應該會減少其中一個後端“已滿”而另一個仍然可以接受請求的機會。我不確定 APC 是否隨著 PHP_FCGI_CHILDREN 的數量而擴展。

另一種方法是將spawn-fcgimultiwatch結合使用(multiwatch 執行 ‘max-procs’ 部分) - 在此解決方案中,所有 php 後端都在同一個套接字上,因此您不會遇到平衡問題。

引用自:https://serverfault.com/questions/466620