简体   繁体   English

如果我在after_fork中不使用$ redis = Redis.new会怎样?

[英]What happens if I don't $redis = Redis.new in after_fork?

What's the negative impact of not putting $redis = Redis.new in Unicorn's after_fork, since redis-rb is thread safe? 由于redis-rb是线程安全的,因此不将$redis = Redis.new放入Unicorn的after_fork有什么负面影响? Assuming I have more than one worker. 假设我有一个以上的工人。

As opposed to just putting that line of code in the environment.rb or an intializer? 与仅将那行代码放入environment.rb或初始化器相反?

after_fork has little to do with thread safety. after_fork与线程安全性无关。 It it used when a parent process forks a child process, not when spawning a thread. 它在父进程派生子进程时使用,而不是在生成线程时使用。

Why you should care 为什么你应该关心

If you never fork, you probably don't. 如果您从不分叉,您可能不会。

When you fork, the parent and child processes share file and socket descriptors (db connections, redis connections). 进行分叉时,父进程和子进程共享文件和套接字描述符(db连接,redis连接)。 If you don't re-open the connection to Redis in the child, data from the parent can be interleaved on the socket with data from the child. 如果不重新打开子级中与Redis的连接,则可以将父级中的数据与子级中的数据交织在套接字上。

Read A Unix Shell in Ruby Pipes for a much more detailed description of what's going on. 阅读Ruby Pipes中的Unix Shell,了解发生了什么的详细说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 redis 客户端连接数越来越等于没有。 即使没有放置 after_fork 的实例乘客叉 - No. of redis client connections is getting equals to no. of instances passenger forks even though after_fork is not being placed Puma fork 后重新连接Redis - Reconnect with Redis after Puma fork 批量完成后,sidekiq-pro批次似乎不会释放redis内存 - sidekiq-pro batches don't appear to release redis memory after batches complete phusion乘客是否使用分叉,如果是,在哪里设置after_fork配置? - Does phusion passenger use forking, and if so, where to set after_fork config? Resque工作者在after_fork中重新建立连接的性能影响 - Performance impact of Resque worker re-establishing connecting in after_fork 我应该在Rails for Redis中开设新的课程吗? - Should I make a new Class in Rails for Redis? 在Passenger fork上重新启动Rails Redis缓存存储连接 - Restarting Rails Redis Cache Store connection upon Passenger fork redis等价于存储数组吗? - What is the redis equivalent of storing an array? Redis与铁轨。 在分叉错误后,您需要重新连接到Redis - Redis with rails. You need to reconnect to Redis after forking error 无法使用Rails中的redis gem在Redis中正确保存图像 - Can't save image properly in Redis using the redis gem in Rails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM