我的应用程序正在使用redis商店,它在本地工作正常,但在生产中,使用Phusion Passenger(开源)我遇到了这个错误。
Errno::EMFILE (Too many open files - socket(2)):
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:24:in `initialize'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:24:in `initialize'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:143:in `new'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:143:in `connect_addrinfo'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:187:in `block in connect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:185:in `each'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:185:in `each_with_index'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:185:in `connect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/connection/ruby.rb:260:in `connect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:336:in `establish_connection'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:101:in `block in connect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:293:in `with_reconnect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:100:in `connect'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:364:in `ensure_connected'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:221:in `block in process'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:306:in `logging'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:220:in `process'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis/client.rb:120:in `call'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis.rb:862:in `block in get'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis.rb:58:in `block in synchronize'
/usr/local/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis.rb:58:in `synchronize'
vendor/bundle/ruby/2.2.0/gems/redis-3.3.0/lib/redis.rb:861:in `get'
vendor/bundle/ruby/2.2.0/gems/redis-store-1.1.7/lib/redis/store/interface.rb:5:in `get'
vendor/bundle/ruby/2.2.0/gems/redis-store-1.1.7/lib/redis/store/marshalling.rb:17:in `get'
vendor/bundle/ruby/2.2.0/gems/redis-activesupport-4.1.5/lib/active_support/cache/redis_store.rb:230:in `block in read_entry'
vendor/bundle/ruby/2.2.0/gems/redis-activesupport-4.1.5/lib/active_support/cache/redis_store.rb:212:in `call'
vendor/bundle/ruby/2.2.0/gems/redis-activesupport-4.1.5/lib/active_support/cache/redis_store.rb:212:in `with'
vendor/bundle/ruby/2.2.0/gems/redis-activesupport-4.1.5/lib/active_support/cache/redis_store.rb:230:in `read_entry'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/cache.rb:413:in `block in exist?'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/cache.rb:547:in `block in instrument'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/notifications.rb:166:in `instrument'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/cache.rb:547:in `instrument'
vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.6/lib/active_support/cache.rb:412:in `exist?'
vendor/bundle/ruby/2.2.0/gems/redis-activesupport-4.1.5/lib/active_support/cache/redis_store.rb:200:in `exist?'
我的缓存初始化代码是
Rails.application.configure do
Rack::MiniProfiler.config.storage_options = { host: 'redis.local.com', port: 6379 }
Rack::MiniProfiler.config.storage = Rack::MiniProfiler::RedisStore
config.cache_store = :redis_store, http://redis.local.com:6379, { expires_in: 5.minutes }
Rails.cache = ActiveSupport::Cache::RedisStore.new
end
搜遍了所有的redis-rb和redis-store宝石,根本没有找到任何东西。 在将Redis用作缓存存储时,如何确保乘客不会创建与Redis的多个连接?
答案 0 :(得分:-1)
这不是乘客的问题。这是您的应用程序达到其文件描述符限制。它为何达到极限?不知道 - 也许它应该打开很多文件描述符,或者你可能正在某处泄露文件描述符。你可以尝试的一件事是增加passenger_app_file_descriptor_ulimit,但这只有在你的应用真的应该使用许多文件描述符而不是泄漏它们时才有用。如果您的应用程序泄漏了它们,那么剩下的唯一事情就是调试您的应用程序,找出漏洞的来源。