Deep Dive Into Ruby Concurrency and Parallelism Execution

Gokul
6 min readSep 10
Deep Dive Into Ruby Concurrency and Parallelism Execution

What?

Concurrency

Concurrency is a fundamental aspect that empowers a program to gracefully manage and execute multiple tasks or processes in a seemingly simultaneous manner. In the realm of Ruby on Rails architecture, it is important to note that these tasks may not necessarily execute concurrently, but rather they are orchestrated in a manner that allows for overlapping and interleaving of their execution.

Concurrency is a commonly applied technique in the realm of software architecture, aimed at enhancing the responsiveness of applications. By leveraging concurrency, applications are empowered to efficiently manage multiple input or event-driven tasks, all the while ensuring that the overall program flow remains unobstructed. In the Ruby on Rails ecosystem, concurrency is commonly achieved through the utilization of powerful mechanisms such as threads and fibers.

Why Concurrency?

Responsiveness: Concurrency is crucial for building responsive applications. In scenarios where a program needs to handle multiple tasks concurrently, such as responding to user input while performing background operations, concurrency ensures that the program can switch between tasks quickly, giving the appearance of simultaneous execution.

Resource Sharing: Concurrent programs can efficiently share resources. For example, in a web server, multiple incoming requests can be handled concurrently without waiting for one request to complete before processing the next. This efficient resource sharing leads to better resource utilization and improved application performance.

I/O-Bound Tasks: Concurrency is well-suited for I/O-bound tasks, where most of the time is spent waiting for external resources like databases, network requests, or user input. Instead of blocking and waiting, a program can switch to another task while one is waiting for I/O, maximizing overall throughput.

Parallelism

Parallelism, on the other hand, encompasses the unified execution of numerous tasks or processes across multiple CPU cores or processors. The primary objective is to optimize hardware utilization and enhance performance by executing tasks…

Gokul

Consultant | Freelancer | Ruby on Rails | ReactJS