多少个 Ruby 线程太多了?
我正在编写一个 Merb 应用程序,它使用 SimpleDB 和 Tokyo Tyrant 的组合进行存储。对于这两个数据存储,我通过为 list 中的每个值旋转一个线程,然后合并结果集来实现 IN (list) 类型功能。请记住,这是一个 Web 应用程序,我应该创建的线程数量是否有限制? Ruby 1.8.7,所以它们不是内核线程。
I'm coding a Merb application which uses a combination of SimpleDB and Tokyo Tyrant for storage. For both of these data stores I'm implementing IN (list) type-functionality by spinning up a thread for each value in list and then merging the result sets. Bearing in mind that this is a web application, is there a limit to the number of threads I should be creating? Ruby 1.8.7, so they're not kernel threads.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于您在这里尝试做的事情来说,线程似乎是一个糟糕的方法,如果您不能使用 JRuby,我会完全放弃线程。但是,您可以创建一个加载数据库的 ruby 文件并使用 基准库 对哪个数字最快进行一些基准测试。您可能还想查看所使用的内存。
Threads seems like a bad approach for what you're trying to do here, and if you can't use JRuby, I'd just drop the threads altogether. However, you could create a ruby file loading the database and use the benchmark library to do some benchmarking on which number is the fastest. You probably want to look at the memory used too.
对我来说,你的问题听起来是 IO 限制,所以单核多线程可能会有所帮助。
大多数时候,在主 Ruby 循环中,您可能会等待 tokyo tyrant 和 simple DB,它们在单独的多线程进程中运行。
那么有多少线程呢?谁知道?您必须进行基准测试和衡量。
To me your problem sounds IO bound, so multi threading a single core may help out.
Most of the time in your main Ruby loop you will probably be waiting on tokyo tyrant and simple DB which are running in separate multi-threaded process.
So how many threads? Who knows? You are going to have to benchmark and measure.
如果您使用 MRI,那么在这种情况下使用线程不会有太大帮助,因为 MRI 使用绿色线程,这在计算操作方面没有帮助。我相信使用 JRuby(本机线程)将会有所帮助。
我一直听说,对于本机线程,最好使用(核心数 + 1)来利用可用核心。
If you are using MRI then using threads in such cases won't be of a big help as MRI uses green threads that are not helpful when it comes to computational operations. I believe using JRuby(native threads) will be helpful then.
I keep hearing that for native threads it's best to use (number of cores + 1) to make use of the available cores.