2

We have a popular iPhone app where people duel each other a la Wordfeud. We have almost 1 M registered users today.

During peak hours the app gets really long response times, and there are also quite a lot of time outs. We have tried to find the bottleneck, but have had a hard time doing so. CPU, memory and I/O are all under 50 % on all servers. The problem ONLY appears during peak hours.

Our setup

1 VPS with nginx (1.1.9) as load balancer
4 front servers with Ruby (1.9.3p194) on Rails (3.2.5) / Unicorn (4.3.1)
1 database server with PostgreSQL 9.1.5

The database logs doesn't show enough long request times to explain all the timeouts shown in the nginx error log.

We have also tried to build and run the app directly against the front servers (during peak hour when all other users are running against the load balancer). The surprising thing is that the app bypassing the load balancer is quick as a bullet even under peak hours.

NGINX SETTINGS

worker_processes=16
worker_connections=4096
multi_accept=on

LINUX SETTINGS

fs.file-max=13184484
net.ipv4.tcp_rmem="4096 87380 4194304"
net.ipv4.tcp_wmem="4096 16384 4194304"
net.ipv4.ip_local_port_range="32768 61000"

Why is the app bypassing the load balancer so fast? Can nginx as load balancer be the bottle neck? Is there any good way to compare timeouts in nginx with timeouts in the unicorns to see where the problem resides?

4

2 に答える 2

5

設定によってはnginxがボトルネックになる可能性があります...

nginx で次の設定を確認/調整します。

  1. worker_processes設定 (コア/CPU の数に等しい必要があります)
  2. worker_connections設定 (ピーク時に多くの接続がある場合は非常に高くする必要があります)
  3. 設定multi_accept on;
  4. Linux の場合は、nginx で epoll ( use epoll;-directive)を使用していることを確認してください。

OS の次の設定を確認/調整します。

  1. 許可されているオープン ファイル記述子の数 ( sysctl -w fs.file-max=999999Linux の場合)
  2. tcp 読み取りおよび書き込みバッファー (sysctl -w net.ipv4.tcp_rmem="4096 4096 16777216"および sysctl - net.ipv4.tcp_wmem="4096 4096 16777216"Linux 上)
  3. ローカル ポート範囲 ( sysctl -w net.ipv4.ip_local_port_range="1024 65536"Linux の場合)

アップデート:

  • したがって、16 のワーカーと、ワーカーあたり 4096 の接続があります。
  • これは、最大 4096*16=65536 の同時接続を意味します
  • おそらくブラウザごとに複数のリクエストがあります(ajax、css、js、ページ自体、ページ上の画像など)。ブラウザごとに4つのリクエストがあるとしましょう

これは 16,000 をわずかに超える同時ユーザーを可能にしますが、それはあなたのピークには十分ですか?

于 2012-11-22T09:18:09.397 に答える
0

アップストリーム サーバー グループをどのように設定し、どのような負荷分散方法を使用していますか?

Nginx自体がボトルネックになっているとは考えにくいです。一部のアップストリーム アプリ サーバーが他のアプリ サーバーよりも多くヒットし、バックログがいっぱいになったために接続を拒否し始める可能性はありますか? Herokuでこの負荷分散の問題を参照し、さらにヘルプが得られるかどうかを確認してください。

nginx バージョン 1.2.2 以降、nginx はこれを提供しますleast_conn。それは簡単な修正かもしれません。私はまだ自分で試していません。

サーバーの重みを考慮して、アクティブな接続の数が最も少ないサーバーに要求が渡される負荷分散方法をグループが使用する必要があることを指定します。そのようなサーバーが複数ある場合は、加重ラウンド ロビン バランシング方式を使用して試行されます。

于 2013-04-05T11:49:55.600 に答える