multithreading - 如果所有 puma 线程都在处理请求并且发生新的连接尝试,会发生什么情况?

标签 multithreading ruby-on-rails-5 puma

我习惯于使用节点,其中进程将接受任意数量的传入连接。

Ruby/puma 有何不同?

对于 puma,我需要定义多个线程:这个数字是否定义了服务器可以同时处理的最大请求数?

如果发生以下情况会发生什么:

  1. 我的服务器有长时间运行的请求
  2. 所有线程当前都在处理请求

并且有新的请求进来?

套接字是否立即打开但等待直到有空闲线程? 套接字连接是否会停止直到有空闲线程为止? 或者线程可以处理多个请求吗?

最佳答案

does this number define the maximum number of requests the server can be processing simultaneously?

这取决于工作线程和线程的数量。

最大请求数 = Workers * Threads

What happens if a new request comes in when there is no free thread

它将被阻塞,直到至少有一个可用的工作线程为止。

Does the socket get opened immediately but sit waiting until there is a free thread?

是的。

Does the socket connection stall until there's a free thread?

没有。

启动后,Puma 监听 TCP 或 UNIX 套接字。 Puma 正在使用循环法来调度一组工作线程和线程的请求。 所以Puma启动后socket总是打开的。

Or can the threads work on more than one request?

没有。

一个线程一次只能处理一个请求。

更多详情,您可以查看https://github.com/puma/puma/blob/master/docs/architecture.md

关于multithreading - 如果所有 puma 线程都在处理请求并且发生新的连接尝试,会发生什么情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60968259/

相关文章:

c++ - FFmpeg C++ 在单独的线程中解码

android - 如何实现执行 AsyncTask 的 Timer/TimerTask? (安卓)

ruby-on-rails - 当我需要不同版本时,如何解决需要最新版本 gem 的 bundler 问题?

ruby-on-rails - Rails 服务器问题

c++ - 在 OpenMP 中使用共享数据结构而不是私有(private)数据结构时的性能差异

unit-testing - 如何测试 Controller 实例变量中的属性值?

ruby-on-rails - 为什么需要将 JWT 作为 Bearer Token header 发送?

ruby-on-rails - 如何使用不同的列作为外键强制 has_many 关联

ruby-on-rails - rails 4 直播不适用于 Puma

c - 线程实现