高负载下薄悬挂

发布于 01-07 22:58 字数 1920 浏览 2 评论 0原文

我们有一个带有 ActiveRecord + memcached + Postgres 的 Thin + RoR 应用程序,它使用 pg gem 访问 Postgres 数据库。

我们观察到,在高负载下,瘦进程会突然变得无响应,并且当负载减弱时永远不会恢复。与此同时,我们的数据库服务器运行良好——我们可以查询数据并在预期的时间内获得响应。

我们观察到的事情:

  • 在进入不良状态之前,我们没有看到响应时间缓慢增加——转变是突然的。
  • 我们可以通过一个或多个瘦进程进入这种状态,这似乎消除了它们在负载下相互死锁的可能性。
  • 当负载减弱时,精简进程不会恢复并继续无响应。
  • 一旦挂起,瘦进程似乎不会向数据库发出任何请求。
  • gdp 指出,当处于挂起状态时,我们有处于 sleep_forever 状态的瘦线程:0x00007f75c78c85d2 in sleep_forever (arg=) at thread.c:848

请记住,这是 95% 的读取应用程序,具有或多或少的积极缓存策略(即我们没有可能导致死锁的数据库事务),我们正在寻找有关在哪里查找的建议。

非常感谢您的帮助!额外信息:

Gems:

  • gem 'rails'、'2.3.11'
  • gem 'thin'、'1.2.7'
  • gem 'pg'

环境:

  • psql (PostgreSQL) 9.1.2
  • Thin 1.2.7
  • Ruby 1.9.2-p290
  • Rails 2.3 .11
  • Apache 2.2.14(详情如下)
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Feb 14 2012 16:42:27
Server's Module Magic Number: 20051115:23
Server loaded:  APR 1.3.8, APR-Util 1.3.9
Compiled using: APR 1.3.8, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/worker"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT=""
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
root@a17:~# /usr/sbin/apache2 -v
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Feb 14 2012 16:42:27

We have a Thin + RoR with ActiveRecord + memcached + Postgres application that is using a pg gem to access the Postgres database.

We are observing that under high load thin processes suddenly become unresponsive one by one and never recover when the load subsides. Our database server, in the meantime, is doing fine – we can query the data and get response in expected time.

Things we have observed:

  • We do not see slow increase in response time before we get in a bad state – the transition is sudden.
  • We can get into that state with one or with multiple thin processes, which seems to eliminate the possibility of them deadlocking each other under load.
  • When the load subsides, thin processes do not recover and continue to be unresponsive.
  • Once hung, a thin process does not seem to issue any requests to the DB.
  • gdp points out that when in the hung state, we have thin threads in sleep_forever state: 0x00007f75c78c85d2 in sleep_forever (arg=) at thread.c:848

Keeping in mind that this is 95% read application with more or less aggressive caching strategy (i.e. we do not have database transactions that can cause deadlocks), we are looking for suggestions on where to look.

Thanks so much for your help! Extra info:

Gems:

  • gem 'rails', '2.3.11'
  • gem 'thin', '1.2.7'
  • gem 'pg'

Environment:

  • psql (PostgreSQL) 9.1.2
  • Thin 1.2.7
  • Ruby 1.9.2-p290
  • Rails 2.3.11
  • Apache 2.2.14 (details below)
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Feb 14 2012 16:42:27
Server's Module Magic Number: 20051115:23
Server loaded:  APR 1.3.8, APR-Util 1.3.9
Compiled using: APR 1.3.8, APR-Util 1.3.9
Architecture:   64-bit
Server MPM:     Worker
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/worker"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT=""
-D SUEXEC_BIN="/usr/lib/apache2/suexec"
-D DEFAULT_PIDLOG="/var/run/apache2.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="/etc/apache2/mime.types"
-D SERVER_CONFIG_FILE="/etc/apache2/apache2.conf"
root@a17:~# /usr/sbin/apache2 -v
Server version: Apache/2.2.14 (Ubuntu)
Server built:   Feb 14 2012 16:42:27

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

灰色世界里的红玫瑰2025-01-14 22:58:55

这是 ruby​​ 中 TCP 堆栈的问题:
http://bugs.ruby-lang.org/issues/5343

尝试升级到 ruby 1.9.3 或更好。

This was an issue with the TCP stack in ruby:
http://bugs.ruby-lang.org/issues/5343

Try upgrading to ruby 1.9.3 or better.

っ左2025-01-14 22:58:55

我们最终从 Thin 转向 Unicorn。问题就消失了。

We ended up switching away from Thin to Unicorn. The issues went away.

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