When trying to run an intensive Ruby method, I noticed it's only using 25% of the CPU resources while 70% sits idle. Is there any way to configure this to use more? I'm on Windows 7, ruby 2.0.0
-
9Do you have quad-core CPU? :) – Sergio Tulentsev Sep 23 '14 at 18:00
-
Pretty sure the default implementation of Ruby only has green threads. Wouldn't this make it only able to work from one core? – Dan Sep 23 '14 at 18:00
-
3@DanPantry: nope, 1.9 and higher don't use green threads. They use real threads with a global lock. – Sergio Tulentsev Sep 23 '14 at 18:01
2 Answers
You probably have 4 CPU cores. You're running 1 Ruby process. 1 Ruby process = 1 thread = can use max 1 CPU core. The MRI (default) implementation of Ruby currently cannot run more than 1 thread in parallel. For that, you may want to try JRuby or some other implementation like Rubinius that allows parallel threads. I'm guessing you'll need to learn a bit about multi-threading to understand this wholly, start by reading some basic tutorials and then questions like "Does ruby have real multithreading?".
-
1It's not just JRuby. *All* Ruby implementations except MRI and YARV support running multiple Ruby threads in parallel. And even MRI and YARV support running *C* threads in parallel, just not Ruby threads. Note, however, that you will still have to re-architect your code to use multiple threads in the first place, of course. – Jörg W Mittag Sep 23 '14 at 21:17
-
1@JörgWMittag: really, *all* of them? :) https://github.com/cogitator/ruby-implementations/wiki/List-of-Ruby-implementations – Sergio Tulentsev Sep 24 '14 at 16:11
When the process is running, go to the task manager, right click on the program, click "go to process," right click on the process, go to select priority, and check off "high."
Important: never set application to "realtime" it may cause several problems.
references:
http://www.tomshardware.com/forum/57576-63-maximum-capacity-application

- 226,338
- 43
- 373
- 367

- 11
-
1This doesn't make it go beyond 25%, I think the other answers are correct in that it won't use more than one core by default. – Major Major Sep 23 '14 at 18:36