3 ms·
I've always assumed that compiling assets into the binary meant the http.FileServer can't use sendfile. I guess this means lower performance at scale, but I've
by AYBABTME 10y ago
I've always assumed that compiling assets into the binary meant the http.FileServer can't use sendfile. I guess this means lower performance at scale, but I've never verified if this actually happened or its effect.
- vfaronov 10y agoLooking at Linux’s sendfile [1], it should be possible to use it like that in principle (but not with the standard http.FileServer, I guess). [1] http://man7.org/linux/man-pages/man2/sendfile.2.html http://man7.org/linux/man-pages/man2/sendfile.2.html
- jorams 10y agoWhen you serve files over https (which you always should) you can't use sendfile anyway. The data will have to be encrypted, so you can't have the kernel send the data straight into the socket.
- blaenk 10y agoI hadn't considered this before but it seems to make sense. If I have nginx configured with ssl and sendfile (X-Accel-Redirect) and my app sends an X-Accel-Redirect response to nginx, you're saying that it's not actually using sendfile under the hood?
- inimino 10y agoSendfile is just a kernel feature for directly sending a file to a socket. If you are doing literally anything other than just sending the raw bytes of the file over the network, it can't be used.
- blaenk 10y agoYeah I'm aware that it's a system call that only knows about file descriptors. It's just that it just now hit me that a consequence of that is that a web server configured to use ssl _and_ sendfile isn't really using sendfile, short of some hairy hack of writing/encrypting the response into a file (maybe in-memory with something like memfd_create) and using sendfile on that, which would defeat the purpose of avoiding user-space entirely.