Skip to content

Instantly share code, notes, and snippets.

@flaneur2020
Created July 16, 2014 07:39
Show Gist options
  • Save flaneur2020/d77071e02b2314d5008b to your computer and use it in GitHub Desktop.
Save flaneur2020/d77071e02b2314d5008b to your computer and use it in GitHub Desktop.
# 线程池最小为 1,最大为 8
threads 1, 8
# 进程池大小为 3,即应用服务器的 CPU 数 + 1
workers 3
# == 线程安全性:
#
# - ActiveRecord 会通过连接池保证线程安全,在没有 preload_app 时,不需要重新连接。
#
# - redis-rb 会通过每次请求上锁保证线程安全。
#
# == preload_app
#
# preload_app! 与 phased restart 不兼容,所以关闭了。关闭它的话,每个 worker 进程
# 会重新跑一遍 Rails 的初始化流程,因此不需要在 on_worker_reboot 进行重连 redis,
# ActiveRecord。
#
# == on_restart
#
# on_restart 会在每次重启 worker 之前调用,进行资源的清理。如果忘记,会在多次重启
# 之后吃光文件描述符。
#
on_restart do
$redis.client.disconnect if $redis
ActiveRecord::Base.connection.disconnect! if defined?(ActiveRecord::Base)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment