Tag: 连接汇集

Rails Puma用完了Redis连接

我已经在SO上查看了其他类似的问题但是不能很好地将事情拼凑在一起。 我有一个Rails应用程序(在Heroku上),它使用Puma同时具有多个进程和多个线程。 我的应用程序还使用Redis作为辅助数据存储(除了SQL数据库),直接查询Redis(通过connection_pool gem)。 这是我的Puma配置文件: workers Integer(ENV[“WEB_CONCURRENCY”] || 4) threads_count = Integer(ENV[“MAX_THREADS”] || 5) threads threads_count, threads_count preload_app! rackup DefaultRackup port ENV[“PORT”] || 3000 environment ENV[“RACK_ENV”] || “development” on_worker_boot do # Worker specific setup for Rails 4.1+ ActiveRecord::Base.establish_connection redis_connections_per_process = Integer(ENV[“REDIS_CONNS_PER_PROCESS”] || 5) $redis = ConnectionPool.new(size: redis_connections_per_process) do Redis.new(url: ENV[“REDIS_URL”] || “redis://localhost:6379/0”) end end 我的Redis实例的连接限制为20,我发现自己经常超过这个限制,尽管应该是(据我所知)每个进程只有5个连接分布在4个工作进程中。 […]