concurrent-ruby icon indicating copy to clipboard operation
concurrent-ruby copied to clipboard

concurrent-ruby-edge Channel.select consumes full(single core) cpu

Open adityacs opened this issue 4 years ago • 1 comments

* `concurrent-ruby` version:       1.1.7
* `concurrent-ruby-edge` used:     yes 

I am running this simple code and I see that select is not blocking on the channels and instead always looping which consumes full(single core) CPU.

require 'concurrent-edge'

Channel = Concurrent::Channel
string1 = Channel.new
string2 = Channel.new

loop do
  Channel.select do |s|
    s.take(string1) {
      puts "string1"
    }
    s.take(string2) { 
      puts "string2"
    }
  end
end

adityacs avatar Aug 28 '20 07:08 adityacs

It is Ruby, not go, so it is not possible to push from another thread to the current one, like it is implemented in go's select.

As the result you can only pull, which this select is actually doing (and consuming 100% CPU).

Adding s.default { sleep 0.001 } will solve it.

kvokka avatar Nov 05 '20 09:11 kvokka