2017-03-10 8 views
3

私は最近、HerokuからElastic Beanstalkサービスを使用して直接AWSに展開することに決めました。私はここでEBとここのHerokuで実行しているアプリを持っています(これは無料のHerokuアプリですので、開始するのに10秒かかる場合があります)。アプリはHerokuで完璧に動作しますが、EBでは時々ロードされるだけです。多分、4回のうち1回のように、私はInternal Server Errorを得ます。私のデータベースプールは5に設定されています.25にスケールアップすれば動作しますが、私はウェブサイトを使用している唯一の人です。プール5は十分ではありませんなぜ私が把握した後、どのように私はプールのサイズをスケーラブルにするために、弾性ビーンストークデータベースプールの問題

development: 
    adapter: sqlite3 
    database: db/website.db 
    pool: 5 
    timeout: 5000 
test: 
    adapter: sqlite3 
    database: db/cucumber-tests.db 
    pool: 5 
    timeout: 5000 
production: 
    adapter: postgresql 
    encoding: utf8 
    database: <%= ENV['RDS_DB_NAME'] %> 
    username: <%= ENV['RDS_USERNAME'] %> 
    password: <%= ENV['RDS_PASSWORD'] %> 
    pool: 5 
    host: <%= ENV['RDS_HOSTNAME'] %> 
    port: <%= ENV['RDS_PORT'] %> 

サイドノート:ここで

は私のdatabase.ymlのでしょうか?私が言うことから、 RDS_POOLという変数はありません。ユーザー数に基づいて規模を調整する方法はありますか?ここで

はピューマのための私のエラーログです:

------------------------------------- 
/var/log/puma/puma.log 
------------------------------------- 
/opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:225:in `context' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:220:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/nulllogger.rb:9:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/head.rb:13:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1787:in `synchronize' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/deflater.rb:35:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/configuration.rb:232:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:578:in `handle_request' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:415:in `process_client' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:275:in `block in run' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread' 
2017-03-10 03:43:14 - ActiveRecord::ConnectionTimeoutError - could not obtain a connection from the pool within 5.000 seconds (waited 5.000 seconds); all pooled connections were i 
n use: 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in wait_poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `loop' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:193:in `wait_poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:154:in `internal_poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:278:in `internal_poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `block in poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:158:in `synchronize' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:148:in `poll' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:717:in `acquire_connection' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:490:in `checkout' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:364:in `connection' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_adapters/abstract/connection_pool.rb:883:in `retrieve_connection' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_handling.rb:128:in `retrieve_connection' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/connection_handling.rb:91:in `connection' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/associations/join_dependency.rb:96:in `initialize' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:399:in `new' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:399:in `construct_join_dependency' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/relation/finder_methods.rb:321:in `exists?' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/activerecord-5.0.2/lib/active_record/querying.rb:3:in `exists?' 
     app/views/index.erb:66:in `block in singleton class' 
app/views/index.erb:-6:in `instance_eval' 
     app/views/index.erb:-6:in `singleton class' 
     app/views/index.erb:-8:in `__tilt_47116404404940' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.6/lib/tilt/template.rb:161:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.6/lib/tilt/template.rb:161:in `evaluate' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/tilt-2.0.6/lib/tilt/template.rb:100:in `render' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:823:in `render' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:667:in `erb' 
     /var/app/current/app/controllers/application_controller.rb:60:in `block in <class:ApplicationController>' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611:in `block in compile!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (3 levels) in route!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:994:in `route_eval' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:975:in `block (2 levels) in route!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015:in `block in process_route' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `catch' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013:in `process_route' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:973:in `block in route!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `each' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:972:in `route!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085:in `block in dispatch!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082:in `dispatch!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `block in call!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `block in invoke' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `catch' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067:in `invoke' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:907:in `call!' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:895:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:225:in `context' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/session/abstract/id.rb:220:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/nulllogger.rb:9:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/head.rb:13:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:182:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013:in `call' 
/opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `block in call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1787:in `synchronize' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/sinatra-1.4.8/lib/sinatra/base.rb:1487:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.5/lib/rack/deflater.rb:35:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/configuration.rb:232:in `call' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:578:in `handle_request' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:415:in `process_client' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/server.rb:275:in `block in run' 
     /opt/rubies/ruby-2.3.1/lib/ruby/gems/2.3.0/gems/puma-3.7.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread' 

- すべてのコードはオープンソースであるとhere見つけることができます -

はありがとうございます。どんな助けも大歓迎です。

更新:私はもうこのアプリケーションをダウンさせることはできません。私は今プールを25に設定しています。私はまた、old app can be found hereてDSNを変更し、かついるthe new app here

UPDATE 2:私は、この問題が関連しているので、より多くのトラクションを得るためにruby-on-railsタグを追加していますが、プロジェクトはレールのシナトラを使用していません。

+0

「[mcve]」をお読みください。問題を示すためにコードを最小限に減らし、リンクに含まれていない質問自体にコードを入れる必要があります。あなたのタグ/キーワードは主要なキーワードではありません。多くの目に質問をするには、RubyとRailsを置き換えることをお勧めします。また、挨拶(「hi」)、評価(「ありがとう」)、または署名を使用しないでください。 SOはディスカッションリストではありません。オンラインリファレンスブックです。最後に、「編集」タグおよび「更新」タグは望ましくない。変更されたテキストを最初にあるかのように質問に組み込みます。いつ変化したのかを見ることができます。 –

答えて

0

スレッドサーバーのPumaを使用しているようです。 Pumaは1つのプロセスで複数のルビスレッドを開始し、同時に要求を処理します。プールで作成しているスレッドの数は、プールにあるデータベース接続の数よりも多い場合があります(database.ymlで定義されています)。

ActiveRecordは自然にデータベース接続のプールを開いたままにして、新しい接続を遅延して作成します。 database.ymlは最大プールサイズが5に設定されているようです。つまり、ActiveRecordはプール内に5つ以上の接続を作成せず、プールが空で接続が要求された場合にのみ新しい接続を作成します。

私はあなたのリポジトリにpuma設定を見つけることができなかったので、私はpumaがデフォルトを使用していると仮定します。 The default max threads for Puma is 16。これはあなたのWebサーバーが16スレッドを実行していることを示している可能性があります(最悪の場合)。そして、5番目以降のすべてのスレッドは、プールを使用してプールに戻すのを待ちます。これは、あなたの16スレッドの間で共有される5つの接続です。ベストプラクティスとして、私は常にデータベースプールのサイズがn+1であることを確認します。nはアプリケーションで実行されるスレッドの最大数です。

私はこの問題が英雄にも存在しない理由を推測できません。