搓线或不搓线。深入了解Ruby的执行模型

Deploying Ruby applications using threaded servers has become widely considered as standard practice in recent years. According to the 2022 Ruby on Rails community survey, in which over 2,600 members of the global Rails community responded to a series of questions regarding their experience using Rails, threaded web servers such as Puma are by far the most popular deployment target. Similarly when it comes to job processors, the thread-based Sidekiq seems to represent the majority of the deployments. 

近年来,使用线程服务器部署Ruby应用程序已被广泛认为是标准做法。根据2022年Ruby on Rails社区调查,全球Rails社区的2600多名成员回答了一系列关于他们使用Rails的经验的问题,到目前为止,Puma等线程网络服务器是最受欢迎的部署目标。同样,当涉及到作业处理器时,基于线程的Sidekiq似乎代表了大多数的部署情况。

In this post, I’ll explore the mechanics and reasoning behind this practice and share knowledge and advice to help you make well-informed decisions on whether or not you should utilize threads in your applications (and to that point—how many). 

在这篇文章中,我将探讨这种做法背后的机制和原因,并分享知识和建议,以帮助你在是否应该在你的应用程序中利用线程方面做出明智的决定(以及在这一点上--多少)。

Why Are Threads the Popular Default?

为什么线程是流行的默认值?

While there are certainly many different factors for threaded servers' rise in popularity, their main selling point is that they increase an application’s throughput without increasing its memory usage too much. So to fully understand the trade-offs between threads and processes, it’s important to understand memory usage.

虽然线程服务器的兴起肯定有许多不同的因素,但它们的主要卖点是在不增加内存用量的情况下增加应用程序的吞吐量。因此,为了充分了解线程和进程之间的权衡,了解内存使用情况很重要。

Memory Usage of a Web Application

网络应用程序的内存使用情况

Conceptually, the memory usage of a web application can be divided in two parts.

从概念上讲,网络应用的内存使用可以分为两部分。

Two separate text boxes stacked on top of each other, the top one containing the words "Static memory" and the bottom containing the words "Processing memory".

Static memory and processing memory are the two key components of memory usage in a web application.

静态内存和处理内存是网络应用中内存使用的两个关键组成部分。

The static memory is all the data you need to run your application. It consists of the Ruby VM itself, all the VM bytecode that was generated while loading the application, and probably some static Ruby objects such as I18n data, etc. This part is like a fixed cost, meaning whether your server runs 1 or...

开通本站会员,查看完整译文。

Accueil - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-15 12:20
浙ICP备14020137号-1 $Carte des visiteurs$