我习惯于使用节点,其中进程将接受任意数量的传入连接。
Ruby/puma 有何不同?
对于 puma,我需要定义多个线程:这个数字是否定义了服务器可以同时处理的最大请求数?
如果发生以下情况会发生什么:
- 我的服务器有长时间运行的请求
- 所有线程当前都在处理请求
并且有新的请求进来?
套接字是否立即打开但等待直到有空闲线程? 套接字连接是否会停止直到有空闲线程为止? 或者线程可以处理多个请求吗?
最佳答案
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/