热门标签 | 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

在这里看到类似的问题


推荐阅读
  • mysqldinitializeconsole失败_mysql03误删除了所有用户解决办法
    误删除了所有用户解决办法第一种方法(企业常用)1.将数据库down掉[rootdb03mysql]#etcinit.dmysqldstopShuttingdownMySQL..SU ... [详细]
  • 生成式对抗网络模型综述摘要生成式对抗网络模型(GAN)是基于深度学习的一种强大的生成模型,可以应用于计算机视觉、自然语言处理、半监督学习等重要领域。生成式对抗网络 ... [详细]
  • Linux重启网络命令实例及关机和重启示例教程
    本文介绍了Linux系统中重启网络命令的实例,以及使用不同方式关机和重启系统的示例教程。包括使用图形界面和控制台访问系统的方法,以及使用shutdown命令进行系统关机和重启的句法和用法。 ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • 本文介绍了九度OnlineJudge中的1002题目“Grading”的解决方法。该题目要求设计一个公平的评分过程,将每个考题分配给3个独立的专家,如果他们的评分不一致,则需要请一位裁判做出最终决定。文章详细描述了评分规则,并给出了解决该问题的程序。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • 本文讨论了在openwrt-17.01版本中,mt7628设备上初始化启动时eth0的mac地址总是随机生成的问题。每次随机生成的eth0的mac地址都会写到/sys/class/net/eth0/address目录下,而openwrt-17.01原版的SDK会根据随机生成的eth0的mac地址再生成eth0.1、eth0.2等,生成后的mac地址会保存在/etc/config/network下。 ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • Oracle优化新常态的五大禁止及其性能隐患
    本文介绍了Oracle优化新常态中的五大禁止措施,包括禁止外键、禁止视图、禁止触发器、禁止存储过程和禁止JOB,并分析了这些禁止措施可能带来的性能隐患。文章还讨论了这些禁止措施在C/S架构和B/S架构中的不同应用情况,并提出了解决方案。 ... [详细]
  • 本文介绍了贝叶斯垃圾邮件分类的机器学习代码,代码来源于https://www.cnblogs.com/huangyc/p/10327209.html,并对代码进行了简介。朴素贝叶斯分类器训练函数包括求p(Ci)和基于词汇表的p(w|Ci)。 ... [详细]
  • 本文概述了JNI的原理以及常用方法。JNI提供了一种Java字节码调用C/C++的解决方案,但引用类型不能直接在Native层使用,需要进行类型转化。多维数组(包括二维数组)都是引用类型,需要使用jobjectArray类型来存取其值。此外,由于Java支持函数重载,根据函数名无法找到对应的JNI函数,因此介绍了JNI函数签名信息的解决方案。 ... [详细]
  • 本文是一篇翻译文章,介绍了async/await的用法和特点。async关键字被放置在函数前面,意味着该函数总是返回一个promise。文章还提到了可以显式返回一个promise的方法。该特性使得async/await更易于理解和使用。本文还提到了一些可能的错误,并希望读者能够指正。 ... [详细]
  • PeopleSoft安装镜像版本及导入语言包的方法
    本文介绍了PeopleSoft安装镜像的两个版本,分别是VirtualBox虚拟机版本和NativeOS版本,并详细说明了导入语言包的方法。对于Windows版本,可以通过psdmt.exe登录进入,并使用datamover脚本导入语言包。对于Linux版本,同样可以使用命令行方式执行datamover脚本导入语言包。导入语言包后,可以实现多种语言的登录。参考文献提供了相关链接以供深入了解。 ... [详细]
  • Question该提问来源于开源项目:react-native-device-info/react-native-device-info ... [详细]
  • 移动传感器扫描覆盖摘要:关于传感器网络中的地址覆盖问题,已经做过很多尝试。他们通常归为两类,全覆盖和栅栏覆盖,统称为静态覆盖 ... [详细]
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社区 版权所有