-
All example code can be found here. Note that we don't actually need Rails, but I used it for examples because Sidekiq is usually used with Rails.
-
Stream
Stream - Scalable APIs for Chat, Feeds, Moderation, & Video. Stream helps developers build engaging apps that scale to millions with performant and flexible Chat, Feeds, Moderation, and Video APIs and SDKs powered by a global edge network and enterprise-grade infrastructure.
-
Async is a composable asynchronous I/O framework for Ruby. It allows you to do things concurrently using Fibers. Since 3.0, Ruby has a fiber scheduler and Ruby core supports it. This means you can have non-blocking I/O without much effort, for example, when using Net::HTTP. If you perform a blocking operation, such as an HTTP call, inside a fiber, it will immediately yield so that another fiber can become active and do some useful work instead of blocking and waiting for the HTTP call to complete.
-
Besides Ruby's support for the fiber scheduler, for some I/O operations, you might use specific gems, like Async::Redis. You can still use other Ruby gems that use native Ruby I/O with Async and they will give you non-blocking I/O as well, but there are two reasons to prefer Async::Redis:
-
Okay, back to our Rails app. In our app, the lifetime should be the whole Sidekiq process. Luckily, Sidekiq has internal documentation on how it runs. I won't copy the entire documentation here, just the part we are interested in:
Related posts
-
Exploring concurrent rate limiters, mutexes, semaphores
-
Async Ruby is the Future of AI Apps (And It's Already Here)
-
Go Tool: tudo o que ninguem pediu
-
Building a Multi-Connection Redis Server with Ruby's Async Library [Part 1]
-
What are some popular background job processing libraries for Rails (e.g., Sidekiq, Delayed Job)?