Por que meu aplicativo Rails está suspenso?

3

Eu tenho um aplicativo Rails de complexidade moderada em execução no Apache / Passenger, que deixa de responder após períodos de ociosidade. Leva vários minutos para responder, mas pode ser revivido temporariamente com uma reinicialização do servidor da Web.

A carga do servidor é insignificante e, como é um aplicativo interno, raramente há mais do que alguns usuários simultâneos.

Eu também tentei o nginx, então não é o Apache que está causando o problema.

Não há nada de útil nos logs do Apache ou Rails. De acordo com os documentos do Passenger, enviei um SIGABRT e tenho um stacktrace (abaixo). Seu banco de dados não está muito carregado, e eu tentei desativar qualquer processamento em segundo plano que poderia estar causando bloqueios.

SignalException (SIGABRT):
  passenger (3.0.17) lib/phusion_passenger/abstract_request_handler.rb:443:in 'block in install_useful_signal_handlers'
  activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:73:in 'call'
  activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:73:in 'ping'
  activerecord (3.2.8) lib/active_record/connection_adapters/mysql2_adapter.rb:73:in 'active?'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract_adapter.rb:219:in 'verify!'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:327:in 'block in checkout_and_verify'
  activesupport (3.2.8) lib/active_support/callbacks.rb:403:in '_run__352340970312725798__checkout__1600727162984137669__callbacks'
  activesupport (3.2.8) lib/active_support/callbacks.rb:405:in '__run_callback'
  activesupport (3.2.8) lib/active_support/callbacks.rb:385:in '_run_checkout_callbacks'
  activesupport (3.2.8) lib/active_support/callbacks.rb:81:in 'run_callbacks'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:326:in 'checkout_and_verify'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:247:in 'block (2 levels) in checkout'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in 'loop'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:236:in 'block in checkout'
  /home/uuuuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in 'mon_synchronize'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:233:in 'checkout'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:96:in 'block in connection'
  /home/uuuuu/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/monitor.rb:211:in 'mon_synchronize'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:95:in 'connection'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:404:in 'retrieve_connection'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:170:in 'retrieve_connection'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_specification.rb:144:in 'connection'
  activerecord (3.2.8) lib/active_record/query_cache.rb:61:in 'call'
  activerecord (3.2.8) lib/active_record/connection_adapters/abstract/connection_pool.rb:473:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:28:in 'block in call'
  activesupport (3.2.8) lib/active_support/callbacks.rb:405:in '_run__1086758471249540907__call__1600727162984137669__callbacks'
  activesupport (3.2.8) lib/active_support/callbacks.rb:405:in '__run_callback'
  activesupport (3.2.8) lib/active_support/callbacks.rb:385:in '_run_call_callbacks'
  activesupport (3.2.8) lib/active_support/callbacks.rb:81:in 'run_callbacks'
  actionpack (3.2.8) lib/action_dispatch/middleware/callbacks.rb:27:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/remote_ip.rb:31:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/debug_exceptions.rb:16:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/show_exceptions.rb:56:in 'call'
  railties (3.2.8) lib/rails/rack/logger.rb:26:in 'call_app'
  railties (3.2.8) lib/rails/rack/logger.rb:16:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/request_id.rb:22:in 'call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in 'call'
  rack (1.4.1) lib/rack/runtime.rb:17:in 'call'
  activesupport (3.2.8) lib/active_support/cache/strategy/local_cache.rb:72:in 'call'
  rack (1.4.1) lib/rack/lock.rb:15:in 'call'
  actionpack (3.2.8) lib/action_dispatch/middleware/static.rb:62:in 'call'
  rack-cache (1.2) lib/rack/cache/context.rb:136:in 'forward'
  rack-cache (1.2) lib/rack/cache/context.rb:245:in 'fetch'
  rack-cache (1.2) lib/rack/cache/context.rb:185:in 'lookup'
  rack-cache (1.2) lib/rack/cache/context.rb:66:in 'call!'
  rack-cache (1.2) lib/rack/cache/context.rb:51:in 'call'
  railties (3.2.8) lib/rails/engine.rb:479:in 'call'
  railties (3.2.8) lib/rails/application.rb:223:in 'call'
  railties (3.2.8) lib/rails/railtie/configurable.rb:30:in 'method_missing'
  rack-pjax (0.6.0) lib/rack/pjax.rb:12:in 'call'
  passenger (3.0.17) lib/phusion_passenger/rack/request_handler.rb:96:in 'process_request'
  passenger (3.0.17) lib/phusion_passenger/abstract_request_handler.rb:516:in 'accept_and_process_next_request'
  passenger (3.0.17) lib/phusion_passenger/abstract_request_handler.rb:274:in 'main_loop'
  passenger (3.0.17) lib/phusion_passenger/rack/application_spawner.rb:206:in 'start_request_handler'
  passenger (3.0.17) lib/phusion_passenger/rack/application_spawner.rb:171:in 'block in handle_spawn_application'
  passenger (3.0.17) lib/phusion_passenger/utils.rb:470:in 'safe_fork'
  passenger (3.0.17) lib/phusion_passenger/rack/application_spawner.rb:166:in 'handle_spawn_application'
  passenger (3.0.17) lib/phusion_passenger/abstract_server.rb:357:in 'server_main_loop'
  passenger (3.0.17) lib/phusion_passenger/abstract_server.rb:206:in 'start_synchronously'
  passenger (3.0.17) lib/phusion_passenger/abstract_server.rb:180:in 'start'
  passenger (3.0.17) lib/phusion_passenger/rack/application_spawner.rb:129:in 'start'
  passenger (3.0.17) lib/phusion_passenger/spawn_manager.rb:253:in 'block (2 levels) in spawn_rack_application'
  passenger (3.0.17) lib/phusion_passenger/abstract_server_collection.rb:132:in 'lookup_or_add'
  passenger (3.0.17) lib/phusion_passenger/spawn_manager.rb:246:in 'block in spawn_rack_application'
  passenger (3.0.17) lib/phusion_passenger/abstract_server_collection.rb:82:in 'block in synchronize'
  :10:in 'synchronize'
  passenger (3.0.17) lib/phusion_passenger/abstract_server_collection.rb:79:in 'synchronize'
  passenger (3.0.17) lib/phusion_passenger/spawn_manager.rb:244:in 'spawn_rack_application'
  passenger (3.0.17) lib/phusion_passenger/spawn_manager.rb:137:in 'spawn_application'
  passenger (3.0.17) lib/phusion_passenger/spawn_manager.rb:275:in 'handle_spawn_application'
  passenger (3.0.17) lib/phusion_passenger/abstract_server.rb:357:in 'server_main_loop'
  passenger (3.0.17) lib/phusion_passenger/abstract_server.rb:206:in 'start_synchronously'
  passenger (3.0.17) helper-scripts/passenger-spawn-server:99:in ''

database.yml:

production:
  adapter: mysql2
  encoding: utf8
  database: [db]
  host: [host]
  pool: 5
  username: [user]
  password: [pass]
  timeout: 2000

Estou executando o Ubuntu 12.04.1 LTS, o Ruby 1.9.3p194 via RVM e o Passenger 3.0.18.

Nunca experimentei este problema no modo de desenvolvimento da WEBrick.

    
por Tim 09.11.2012 / 13:01

2 respostas

1

Estou enfrentando o mesmo problema com o ruby 2.0.0-p0.

../bundle/ruby/2.0.0/gems/activerecord-3.2.13/lib/active_record/connection_adapters/mysql2_adapter.rb:73:in 'ping'

Eu tentei com unicórnio, magro e passageiro. Isso não muda nada.

production:
  adapter: mysql2
  database: ***
  username: ***
  password: ***
  host: an IP
  reconnect: true
  wait_timeout: 3 # I've tried with this option and without

Alguma idéia?

libmysqlclient 5.1.66-0 + squeeze1
mysql-server 5.1.66-0 + squeeze1

EDITAR

Parece ser um problema de firewall com o TCP Keepalive. Se o TCP Keepalive do cliente MySQL for maior que o keepalive do firewall, o problema pode aparecer.

Detalhes: link

    
por 21.03.2013 / 16:44
1

Estou usando o Google Compute Engine e atingi exatamente esse mesmo problema de forma consistente. Após cerca de 10 minutos de ociosidade, as solicitações para meu aplicativo Rails seriam interrompidas sem registros óbvios ou indicação do problema.

Depois de muita depuração e rastreamento, os tempos limite do firewall acabaram - as conexões TCP das instâncias do GCE são expiradas automaticamente após 10 minutos de inatividade. Eu consertei isso com êxito configurando o TCP keepalive para enviar sua primeira análise em 60 segundos ociosos (em vez das 2 horas padrão) para que as conexões TCP de longa duração para o banco de dados permaneçam ativas. Isso também é mencionado aqui: link

# Set tcp_keepalive_time to 60 seconds and make it permanent across reboots.
$ echo 'net.ipv4.tcp_keepalive_time = 60' | sudo tee -a /etc/sysctl.conf
    
por 16.04.2015 / 19:17