# Ruby Processes and Threads - Configuring a Web Server

DevFeed: [Ruby Processes and Threads - Configuring a Web Server](<https://devfeed.tech/articles/ruby-processes-and-threads-configuring-a-web-server-21076.md>)

Original publisher: [Read original article](<https://jakeyesbeck.com/2019/06/18/ruby-processes-and-threads/>)

Published: 2019-06-18T12:00:00Z

Content type: article

Language: en

Sources: [Jake Yesbeck](<https://devfeed.tech/sources/jake-yesbeck.md>)

Topics: [Ruby](<https://devfeed.tech/topics/ruby.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Server](<https://devfeed.tech/topics/server.md>), [Rails](<https://devfeed.tech/topics/rails.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrent-programming](<https://devfeed.tech/tags/concurrent-programming.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [database](<https://devfeed.tech/tags/database.md>), [processes](<https://devfeed.tech/tags/processes.md>), [rails](<https://devfeed.tech/tags/rails.md>), [ruby](<https://devfeed.tech/tags/ruby.md>), [server](<https://devfeed.tech/tags/server.md>)

## AI overview

This article explains how Ruby web servers use threads and processes to handle concurrent requests. It covers I/O blocking, Ruby's Global Interpreter Lock, process-based parallelism, and the CPU, memory, and database-connection tradeoffs involved in server configuration.

## Source excerpt

Multiple popular Ruby web servers exist. Each Ruby application is different and the ultimate tl;dr for configuring a web server is: it depends. This post will not prescribe one web server or configuration over another and will instead explain internal components most popular servers contain. In order to facilitate more than one request at a time, a Ruby web server implements Threads, Processes, or both. These tools are used to enable concurrency and are beneficial in different ways. Threads Threads in Ruby are a solution for concurrent programming and can alleviate slow downs due to blocking code. This blocking is usually referred to as "I/O" or Input/Output blocking and occurs when a program must reach out for additional information. External API calls, reading from disk, and querying a database are all examples of blocking operations. When using multiple Threads, an application can continue to function while one Thread is waiting. Most Ruby code in the wild is running on MRI (if you're not sure what you're using, there is a good chance this is what you use). Because of this, Ruby Threads are subject to the Global Interpreter Lock or GIL. The GIL prevents any two threads in the same process from running at exactly the same time making true parallelism not possible. Processes One way to allow for true parallelism in Ruby is to use multiple Processes. A Ruby Process is the instance of an application or a forked copy. In a traditional Rails application, each Process contains all the build up, initialization, and resource allocation the app will need. Running multiple Proccesses can enable more efficient usage of some server resources like the CPU but is not without its downsides. Because each process must boot and provision an entire app, memory usage or database connection saturation can become a limiting factor. Tempering the Metal When configuring on a web server, an application's request shape is the most important factor to consider. Web application requests can