What happens if all puma's threads are handling a request and a new connection attempt happens?

Viewed 174

I'm used to working with node, where the process will accept any number of incoming connections.

How is it different in Ruby/puma?

With puma I need to define a number of threads: does this number define the maximum number of requests the server can be processing simultaneously?

What happens if:

  1. my server has long running requests
  2. all threads are currently serving a request

and a new request comes in?

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? Or can the threads work on more than one request?

1 Answers

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

It depends the number of Workers and Threads.

the max number of requests = Workers * Threads

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

It will be blocked until there is at least one available worker thread.

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

Yes.

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

No.

Upon startup, Puma listens on a TCP or UNIX socket. And Puma is using round-robin to schedule requests across a fleet of workers and threads. So the socket is always opened after Puma started.

Or can the threads work on more than one request?

No.

One thread can handle exactly one request at a time.

For more detail, you can check https://github.com/puma/puma/blob/master/docs/architecture.md

Related