Project

General

Profile

[Solved] Big proxy requests store-and-forward problem

Added by kab00m 11 months ago

I am using Lighttpd as my production front web server and it does well. Latest tested version is lighttpd/1.4.69 (ssl) on NetBSD 9.2_STABLE.

All sites are HTTPS and some of them produce big files by PHP backends, both FastCGI via PHP-FPM and plain HTTP Apache with php module.

When such an URL is requested Lighttpd start downloading file giving client 0 bytes until big portion of the file is loaded in buffer or cache. For a 200Mb file lighttpd will take all of it before starting to stream it to client. Even if client is faster than backend server the delay is quite big and browser do not show file downloading because it have no header until lighty buffer will be filled enough to start streaming. Chrome will do the job after all, but Firefox can produce incomplete files.

I've tried most of solutions I could find:
1. Disabling HTTP2 protocol makes no difference. The only difference is: with http2 client canceling download make lighttpd to stop getting it from backend, without HTTP2 lighttpd will continue (this may need attention).
2. server.stream-request-body and ssl.read-ahead do not help for downloading, only for uploading files.
3. Changing server.network-backend from sendfile to writev does not help.
4. cache.enable = "disable" and server.stat-cache-engine = "simple" makes no difference.
5. disabling deflate does nothing as well.
6. server.max-worker = 16 not having any influence.

My question is: is that stream is intended to be downloaded and stored before giving client or there are options I missed or it can be an OS issue? I believe that should not happen.

My config is very big, so I left only site I have problems with. The rest is just lot of other vhosts without global configuration.

https://paste.lighttpd.net/nC#mQKamGfv5uli2AAf8kPWCpHs

[root@star kab00m]$ lighttpd -tt -f /usr/pkg/etc/lighttpd/lighttpd.conf
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: cache.enable (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: url.redirect-code (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: setenv.add-response-header (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: ssl.dh-file (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: ssl.ec-curve (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: setenv.add-response-header (ignored)
2023-05-18 04:37:57: (configfile.c.1289) WARNING: unknown config-key: url.redirect (ignored)


Replies (3)

RE: Big proxy requests store-and-forward problem - Added by gstrauss 11 months ago

When such an URL is requested Lighttpd start downloading file giving client 0 bytes until big portion of the file is loaded in buffer or cache.

This is by design. lighttpd performs request and response offloading by default.

You can modify the default behavior with:
server.stream-request-body
server.stream-response-body

You seem to have overlooked server.stream-response-body in the documentation.

For your use, you probably want server.stream-response-body = 1
Note: streaming the response disables lighttpd mod_deflate for those streamed dynamic responses, but if you are streaming responses from your backend, then your backend PHP should apply your deflate policy.


Regarding all the warnings, you should review that your config works as you intend.

url.redirect is being ignored, suggesting that you are missing server.modules += ("mod_redirect")
setenv.add-response-header is being ignored, suggesting that you are missing server.modules += ("mod_setenv")

ssl.dh-file and ssl.ec-curve were deprecated a long time ago and removed, suggesting you have not read the lighttpd TLS docs in a long time.

cache.enable suggests a typo to me. Perhaps it was truncated from a different directive, or other non-existent lighttpd module.

server.max-worker = 16 not having any influence.

You should use server.max-worker = 0 unless you test and measure that a single lighttpd process is the bottleneck and that using a non-zero server.max-worker is beneficial to your setup. Unless your server is very busy, server.max-worker = 0 is recommended. Your PHP is more likely your bottleneck. If your LDAP server is your bottleneck, then you might consider trying mod_auth caching e.g. auth.cache = ("max-age" => "600")

RE: [Solved] Big proxy requests store-and-forward problem - Added by kab00m 11 months ago

Thank you for the input, I will try server.stream-response-body today. As for old directives they were just left after multiple lighttpd upgrades, and max-worker was added recently solving this particular problem.

Thanks for mod_auth caching hint, thats valuable, I will try this too.

And thank you for participating in such a great project, I love lighttpd very much.

During solving that problem I got some more issues and I will start another topics for them, I hope its alright.

RE: [Solved] Big proxy requests store-and-forward problem - Added by gstrauss 11 months ago

During solving that problem I got some more issues and I will start another topics for them, I hope its alright.

Yes, though please do try reading/searching through the documentation before posting.
WikiStart
Configuration: Options

    (1-3/3)