Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adityacs opened this issue Aug 28, 2020 · 1 comment
Open

Comments

@adityacs
Copy link

adityacs commented Aug 28, 2020

* `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 adityacs changed the title concurrent-ruby-edge Channel.select consumes full cpu on single core system concurrent-ruby-edge Channel.select consumes full(single core) cpu Aug 30, 2020
@kvokka
Copy link

kvokka commented Nov 5, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants