Bullets Ruby 1.9

As I understand it, Ruby 1.9 uses OS threads, but only one thread will still be running at a time (although one thread can block IO and another thread is processing). In the thread examples I saw, just use Thread.new to start a new thread. Based on the Java background, I usually use thread pools to not start many new threads, as they are "heavyweight."

Is there a thread pool built into ruby? I have not seen this in the default language libraries. Or is there a standard stone that is commonly used? Since OS level threading is a new ruby ​​feature, I don’t know how mature the libraries are for it.

+6
source share
1 answer

You are correct that the default Ruby C interpreter only runs one thread at a time (other dynamic C-based languages ​​like Python have similar limitations). Due to this limitation, threads are actually not so common in Ruby, and as a result there is no threadpool library by default. If there are tasks that need to be performed in parallel, people usually use processes, because processes can scale on multiple servers.

If you need to use threads, I would recommend you use https://github.com/meh/ruby-threadpool on the JRuby platform, which is a Ruby interpreter running on the JVM. This should be right up your walkway, and since it runs on a virtual machine, it will have true threading.

+6
source

Source: https://habr.com/ru/post/919982/


All Articles