Apache 未回應所有請求

Apache 未回應所有請求

設定:我有大約 +1mio 電話正在連接我的伺服器。

伺服器看起來不錯。充足的 CPU 和 RAM - CPU 大約 90% 的時間處於閒置狀態 (1)

資料庫沒有獲得太多負載 - 每秒少於 100 個請求 (2)。

當我透過 Apache 代理(如“Android Lost”)訪問伺服器時,我遇到了超時。

當我直接在連接埠 8080 上存取應用程式伺服器時,我立即收到回覆。

到目前為止我所做的是:

  1. 重新啟動所有服務,資料庫,apache,jetty
  2. 重新啟動伺服器
  3. 嘗試安裝 nginx 而不是 apache (3)
  4. 嘗試在連接埠 80 上執行 Jetty 並跳過 Apache
  5. 嘗試調整伺服器設定 (4)

對我來說,聽起來好像有大量的請求試圖到達伺服器,而 Apache 中的某個地方需要設定一個限制。

因此,任何提示或建議將不勝感激。

廣告。 1:

top - 20:44:33 up 44 min,  2 users,  load average: 2.44, 1.86, 2.80
Tasks: 165 total,   2 running, 163 sleeping,   0 stopped,   0 zombie
Cpu(s):  1.0%us,  0.4%sy,  0.0%ni, 90.6%id,  7.5%wa,  0.0%hi,  0.5%si,  0.0%st
Mem:  12296928k total, 12154152k used,   142776k free,    83228k buffers
Swap:  6287292k total,        0k used,  6287292k free, 10461776k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                               
  447 root      20   0 7587m 841m  14m S    9  7.0   0:39.81 java                                                                   
 1287 mongodb   20   0  120g 272m 247m S    3  2.3   1:38.12 mongod                                                                 
   10 root      20   0     0    0    0 S    0  0.0   0:07.57 rcu_sched                                                              
  364 root       0 -20     0    0    0 S    0  0.0   0:00.96 kworker/0:1H                                                           
  381 www-data  20   0 1966m 8188 2164 S    0  0.1   0:00.72 apache2                                                                
15562 root      20   0 7706m 105m  11m S    0  0.9   0:13.56 java                                                                   
32636 www-data  20   0 1966m 8012 2236 S    0  0.1   0:00.72 apache2   

廣告。 2:

insert  query update delete getmore command flushes mapped  vsize    res faults locked % idx miss %     qr|qw   ar|aw  netIn netOut  conn       time 
     3     17      2      0       0       6       0  58.2g   120g   293m     11      1.7          0       0|0     0|0     3k     9k    43   20:49:40 
    11     46      8      0       0      24       0  58.2g   120g   295m      6      5.1          0       0|0     0|0    12k    21k    43   20:49:41 
    12     63     13      0       0      26       0  58.2g   120g   294m      3      1.3          0       0|0     0|0    17k    35k    43   20:49:42 
     5     45      6      0       0      12       0  58.2g   120g   296m      6      0.9          0       0|1     2|1    13k    22k    43   20:49:43 
     5     49      5      0       0      11       0  58.2g   120g   298m      5      0.1          0       0|0     0|0    13k    22k

廣告。 3:

從 nginx 錯誤日誌:

2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough

廣告。 4:

http://www.eclipse.org/jetty/documentation/current/high-load.html#d0e14090

答案1

這是由於 nginx 沒有足夠的工作連線。可以在nginx錯誤日誌中看到:

2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough 
2014/05/12 19:45:51 [alert] 9800#0: 768 worker_connections are not enough

nginx 可以服務的最大客戶端數量使用以下公式計算:

max_clients = worker_processes * worker_connections - keepalive connections

您可以在其中nginx.conf設定worker_processes和的數量worker_connections。這通常位於主設定檔頂部的某個位置(http指令之前):

worker_processes 1;
events {
    worker_connections 128
}

您很可能已經擁有這些。我建議設定worker_processes為您擁有的 cpu 核心數,並在檢查伺服器效能時增加該值,worker_connection直到找到伺服器可以/需要處理的數量。

相關內容