What does HackerNews think of concurrent-ruby?

Modern concurrency tools including agents, futures, promises, thread pools, supervisors, and more. Inspired by Erlang, Clojure, Scala, Go, Java, JavaScript, and classic concurrency patterns.

Language: Ruby

#13 in Ruby
https://github.com/ruby-concurrency/concurrent-ruby has great docs if someone is looking for alternatives.
In a sense the GIL (or actually GVL as it's called in current ruby versions) has already been removed for ruby.

It's only the original MRI Ruby that still has it several over Ruby implementations already removed it. e.g. JRuby.

Concurrent-Ruby[1] is probably a good place to start if you want to work with GVL free ruby on JRuby. It's quite well supported and is currently used by Rails.

If you just want async or non-blocking IO I'd take a look at the Async Gem[2]. It looks pretty solid in Ruby > 3.0 and it's been invited by Matz to be part of the stdlib, which I think is a pretty good endorsement.

For MRI itself I don't think it's likely they'll ever remove the GVL. Ractors are probably a better solution for CPU concurrency in the long run, although I think they're pretty experimental currently.

1. https://github.com/ruby-concurrency/concurrent-ruby 2. https://github.com/socketry/async

> my rule is "if you're going to even think about threads, just use Java or go" since concurrency is so nice there.

I could see reasons for preferring Java over Ruby but concurrency isn't one of them considering that Concurrent-Ruby running on JRuby gives you access to all of Java's concurrency tooling.[1]

1. https://github.com/ruby-concurrency/concurrent-ruby

I'd suggest having a look at Concurrent Ruby[1], it's one of ActiveSupport's dependencies so you get it for "free" in Rails.

1. https://github.com/ruby-concurrency/concurrent-ruby

If you wanted to run 5000 parallel async requests in MRI ruby surely you'd just use a simple thread pool wouldn't you?

If you prefer some other paradigm then Concurrent Ruby[1] has a swiss army knife of them including event loops and Go style SCP.

I think things will improve in ruby 3 but even without ractors it's still possible to do either async IO in MRI or use JRuby for fully parallel ruby.

1. https://github.com/ruby-concurrency/concurrent-ruby

GVL is an implementation detail rather than a feature of the language (I believe the term Global VM Lock replaced GIL in the standard library, sometime around ruby 2.0ish I think).

JRuby, for example, has no GVL including for CPU based code; everything there can run in parallel.

Even in MRI Ruby though, wrapping IO operations in a thread allows you to release the GVL when the IO operation blocks.

e.g.

  5.times.map do
    Thread.new do
      Net::HTTP.get('example.com', '/index.html')
    end
  end.each(&:join)
Will perform those network requests in parallel rather than sequencially. This is how ActiveRecord can perform asynchronous database calls in parallel on MRI Ruby.

I got that HTTP example from[1], which has a good write up but it's also covered in Working with Ruby Threads by Jesse Storimer[2].

I asked the original question because in the Concurrent-Ruby Readme they discuss Ruby's mutable references and the possibility of thread safety issues because of that.[3]

1. https://pawelurbanek.com/ruby-concurrent-requests

2. https://www.goodreads.com/book/show/17826435-working-with-ru...

3. https://github.com/ruby-concurrency/concurrent-ruby

I love stuff like this thanks. It's really interesting to see that Falcon is based on the https://github.com/socketry/async library.

I've previously been looking at https://github.com/ruby-concurrency/concurrent-ruby based on its use in Rails and was wondering if there's a comparison of the two approaches anywhere that would be newbie friendly?

I was also wondering will Falcon run on JRuby? (I see that nio4r does so hopefully that also means that things like Async-Container will.)

Celluloid is great but not really maintained anymore.

You probably want to use https://github.com/ruby-concurrency/concurrent-ruby and inparticular if you are interested in the Actor model take a look at http://ruby-concurrency.github.io/concurrent-ruby/Concurrent... and https://github.com/ruby-concurrency/concurrent-ruby/blob/mas...

I don't really write Ruby much anymore professionally but this is what I have moved a lot of my Celluloid based personal projects to.

I’m working on a project right now that uses jruby for java interaction.

I’m so appreciative that we have an easy way to combine java code with ruby scripting, thanks Charles. You guys make my job possible. :D

I think particularly now that we have the excellent concurrent-ruby[0] project more developers should checkout jruby.

My suspicion is that the main pain point stopping people using jruby is around tooling and process forking.

The ruby tools I would normally use to get fast cycle times for things like running specs without restarting rails mostly rely seem to make use of forking which obviously isn't supported on the JVM.

If I can find more time and tallent that’s definitely something I look into.

[0] https://github.com/ruby-concurrency/concurrent-ruby

> Ruby has [...] likewise community gems with more robust functionality like Quasar.

https://github.com/ruby-concurrency/concurrent-ruby for those wondering. Rails uses it as of version 5.