セットアップ: 私のサーバーにアクセスする携帯電話は約 100 万台あります。
サーバーは問題なさそうです。CPU と RAM はどちらも十分です。CPU は 90% の時間アイドル状態です (1)
データベースの負荷はそれほど高くなく、1秒あたりのリクエスト数は100件未満です(2)。
「Android Lost」のような Apache プロキシ経由でサーバーにアクセスすると、タイムアウトが発生します。
ポート 8080 でアプリケーション サーバーに直接アクセスすると、すぐに応答が返されます。
これまでに行ったことは次のとおりです。
- すべてのサービス、データベース、Apache、Jettyを再起動します
- サーバーを再起動しました
- Apacheの代わりにnginxをインストールしようとしました(3)
- ポート80でJettyを実行し、Apacheをスキップしてみました
- サーバー設定を微調整してみた (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
お勧めします。