线程安全的Rails

Thread Safe Rails? 关于线程安全的Rails,请大家慎重采用,具体看这篇文章:http://m.onkey.org/thread-safety-for-your-rails

 

上一个项目我们怀着战战兢兢的心情开启了多线程,结果是出乎意料得好。开启多线程后没遇到什么困难,可能会遇到的问题有两点:

 

1. 去掉class variable (当然,基本上你不应该使用类变量)

 

2. 另外一件事情,就是在multiple threads下面Rails需要eager load libs。请移步:http://gigix.thoughtworkers.org/2009/7/17/move-to-multi-threaded-rails

 

 

多线程的Rails对于performance有极大提升,请再次移步:http://blog.headius.com/2008/08/qa-what-thread-safe-rails-means.html   (请自行fan qiang)

 

基本上意思是内存使用量的锐减和数据库连接资源的优化:

 

写道
In a typical Mongrel setup, handling 10 concurrent requests means you have to have 10 copies of Rails loaded, 10 copies of your application loaded, 10 in-memory data caches, 10 database connections...everything has to be scaled in lock step for every additional request you want to handle concurrently.

 

写道
Instead of a single database connection for a given Rails instance, there will be a pool of connections, allowing N database connections to be used by the M requests executing concurrently. It also means allowing requests to potentially execute without consuming a connection, so the number of live, active connections usually will be lower than the number of requests you can handle concurrently.
 

References:

 

教程: http://m.onkey.org/2008/10/23/thread-safety-for-your-rails

Slides:  http://www.slideshare.net/Naoto.Takai/jruby-on-rails-and-thread-safety-presentation 
Q & A: http://stackoverflow.com/questions/647642/ruby-rails-thread-safety

 

----EOF----

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值