Regarding the working of lighttpd
Hi, I was going through the lighttpd source code to figure out as to how exactly it services the connections which are made and for that I was going through the source code and I had some questions about it.
1) I was going through the main function in server.c and had a question about the main event loop inside it[_while(!srv_shutdown)_] and it's function exactly because before this main event loop I see a bunch of sockets being made for listening and binded to using network_init and then a call to network_register_fdevents that registers event handlers(handlers which accept all incoming connections) for all the sockets. My question was where inside the main-loop does the processing of the events actually happen, where is it that the event handlers are actually called? I see a fdevent_poll inside the main-loop which dereferences the handler pointers, is this where the processing done?
2) Also, if I am to understand correctly, Lighttpd's frameowrk is similar to nginx where Lighttpd spawns a number of worker processes that are responsible listening on the sockets, servicing requests and calling the appropriate handlers asynchronously. Is this general high-level idea correct or am I missing something?
RE: Regarding the working of lighttpd - Added by carpii over 5 years ago
Lighttpd's framework is similar to nginx where Lighttpd spawns a number of worker processes
Don't take this as gospel as I'm not a lighttpd developer...
But I believe lighttpd is single threaded by default.
You can create more worker threads by setting server.max-worker, but generally its considered a bad idea as it can adversely affect access logs, stats pages, and perhaps a bunch of other stuff.
I run a high traffic site using lighttpd, but still I keep server.max-worker set to 1 (but of course lots of fast cgi backends being spawned for dynamic content)
Benchmarking my latest servers (using blitz.io), I found no compelling reason to increase server.max-worker, even during heavy load (although its probably fair to say my site is optimised quite heavily anyway)
More recently I've moved to haproxy as the main front end, with lighty running serving the background. Its working very well for me, so you could consider this if you want more control