2 ms·
Does redbean fork on every request, or does it fork on start and then each process reads and handles one request at a time? It gets weird with keep-alive and tl
by toast0 3y ago
Does redbean fork on every request, or does it fork on start and then each process reads and handles one request at a time? It gets weird with keep-alive and tls, but traditional http one request per connection can be really nice in a prefork environment with proper accept filters and large socket buffers. Each process just blocks on accept, gets a fully formed get request, and does the work, responds, and then blocks on accept again. The OS kernel takes care of the socket while the client is sending the request and while the client is acking the response.
Green threads can be nice, because some software is easier written as read from socket, do work, write, loop where the context of the socket is right there. And with green threads, you can have a million on a single machine and handle a million sockets on a single machine. I haven't tried, but I don't think you can have a million OS threads or a million OS processes on a single machine.
Maybe you don't want that many sockets one one machine, or don't have that kind of traffic, or userland processing of the requests is so significant that you can't have service that many sockets on a single machine anyway...