热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

多线程ruby程序只使用100%cpu[重复]-Multithreadedrubyprogramonlyuses100%cpu[duplicate]

Thisquestionalreadyhasananswerhere:这个问题在这里已有答案:Doesrubyhaverealmultithreading

This question already has an answer here:

这个问题在这里已有答案:

  • Does ruby have real multithreading? 9 answers
  • ruby有真正的多线程吗? 9个答案

I'm using ruby-head and Debian wheezy x64. When I run a multithreaded ruby script, htop shows that it's using multiple cores visually with the bars at the top, and that it's using 100% CPU on the process list but it's only using 100% of the capacity of one core. I assume it's possible to have multiple cores running at 100% and this number seems too convenient to be bottle-necked by either the program logic or another hardware aspect. Is the OS limiting the amount of available instructions I'm using, if so how do I stop this?

我正在使用ruby-head和Debian wheezy x64。当我运行多线程ruby脚本时,htop显示它在视觉上使用多个核心,顶部有条形图,并且它在进程列表中使用100%CPU,但它只使用100%的一个核心容量。我认为有可能让多个内核以100%运行,这个数字似乎太方便了,无法通过程序逻辑或其他硬件方面进行瓶颈。操作系统是否限制了我正在使用的可用指令数量,如果是这样,我该怎么做呢?

EDIT more info:

编辑更多信息:

When I mean visually using multiple cores e.g.: 47% core 1, 29% core 2, and 24% core 3. These percentages are constantly shifting up and down and to different sets of cores, but always collectively add up to 100%-102%. More than 3(/8 total) cores are being used, but any cores other than the three most burdened only utilize 2% or less capacity. I guess I should also mention this is a linode VPS.

当我的意思是直观地使用多个核心时,例如:47%核心1,29%核心2和24%核心3.这些百分比不断地上下移动到不同的核心集合,但总是总计达到100%-102 %。使用的核心数超过3个(每个/ 8个),但除了三个核心以外的任何核心仅使用2%或更少的容量。我想我还应该提一下这是一个linode VPS。

EDIT:

编辑:

Well it looks like I was reading promises that 2.0 would feature true parallel threads, and not actual release information. Time to switch to Jruby...

好吧,看起来我正在阅读承诺2.0将具有真正的并行线程,而不是实际的发布信息。是时候切换到Jruby ......

2 个解决方案

#1


10  

You failed to mention which Ruby implementation you are using. Not all Ruby implementations are capable of scheduling Ruby threads to multiple CPUs.

您没有提到您正在使用的Ruby实现。并非所有Ruby实现都能够将Ruby线程调度到多个CPU。

In particular:

尤其是:

  • MRI implements Ruby threads as green threads inside the interpreter and schedules them itself; it cannot schedule more than one thread at a time and it cannot schedule them to multiple CPUs
  • MRI将Ruby线程实现为解释器内的绿色线程并自行调度;它不能一次调度多个线程,也无法将它们安排到多个CPU
  • YARV implements Ruby threads as native OS threads (POSIX threads or Windows threads) and lets the OS schedule them, however it puts a Giant VM Lock (GVL) around them, so that only one Ruby thread can be running at any given time
  • YARV将Ruby线程实现为本机操作系统线程(POSIX线程或Windows线程),并允许操作系统安排它们,但是它会围绕它们放置一个巨型VM锁(GVL),以便在任何给定时间只能运行一个Ruby线程
  • Rubinius implements Ruby threads as native OS threads (POSIX threads or Windows threads) and lets the OS schedule them, however it puts a Global Interpreter Lock (GIL) around them, so that only one Ruby thread can be running at any given time; Rubinius 2.0 is going to have fine-grained locks so that multiple Ruby threads can run at any given time
  • Rubinius将Ruby线程实现为本机操作系统线程(POSIX线程或Windows线程),并允许操作系统安排它们,但是它会围绕它们设置全局解释器锁(GIL),以便在任何给定时间只能运行一个Ruby线程; Rubinius 2.0将具有细粒度锁,因此可以在任何给定时间运行多个Ruby线程
  • JRuby implements Ruby threads as JVM threads and uses fine-grained locking so that multiple threads can be running; however, whether or not those threads are scheduled to multiple CPUs depends on the JVM being used, some allow this, some don't
  • JRuby将Ruby线程实现为JVM线程,并使用细粒度锁定,以便可以运行多个线程;但是,这些线程是否被调度到多个CPU取决于所使用的JVM,有些允许这样做,有些则不允许
  • IronRuby implements Ruby threads as CLI threads and uses fine-grained locking so that multiple threads can be running; however, whether or not those threads are scheduled to multiple CPUs depends on the VES being used, some allow this, some don't
  • IronRuby将Ruby线程实现为CLI线程,并使用细粒度锁定,以便可以运行多个线程;但是,这些线程是否被调度到多个CPU取决于所使用的VES,有些允许这样做,有些则不允许
  • MacRuby implements Ruby threads as native OS threads and uses fine-grained locking so that multiple threads can be running on multiple CPUs at the same time
  • MacRuby将Ruby线程实现为本机操作系统线程,并使用细粒度锁定,以便多个线程可以同时在多个CPU上运行

I don't know enough about Topaz, Cardinal, MagLev, MRuby and all the others.

我不太了解Topaz,Cardinal,MagLev,MRuby和其他所有人。

#2


4  

MRI implements Ruby Threads as Green Threads within its interpreter. Unfortunately, it doesn't allow those threads to be scheduled in parallel, they can only run one thread at a time.

MRI在其解释器中将Ruby Threads实现为绿色线程。不幸的是,它不允许并行调度这些线程,它们一次只能运行一个线程。

See similar question here

在这里看到类似的问题


推荐阅读
author-avatar
蘑菇雪雪_585
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有