Replies: 3 comments 4 replies
-
I think I found the problem - I was ignoring the .second field from tryEnd (completely done sending), and forcing another end with ->end({},true). |
Beta Was this translation helpful? Give feedback.
-
If you want to stream huge files with ideal performance you need to use KTLS and sendfile, but uWS is not really optimized for that scenario (still beats most servers in that case, though). But ideally you let the kernel handle file streaming including TLS completely in kernel space. |
Beta Was this translation helpful? Give feedback.
-
This solution you've presented in not valid. It performs blocking disk operations mid-handler which is entirely broken and will freeze the entire server every time your disk is not immediately responding. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use the asynchronous streaming of a file, but the current bundled example of a HTTP server doesn't seem to work right with files larger than 1 MB (and the cache is extremely inefficient, pulling everything into RAM - I'd rather let Linux kernel worry about that and just use fopen/fread/fclose until it becomes a problem).
So far I came up with the following solution (not hardened for security - will get to that later, want to make it work first):
EDIT: Fixed the issue with the socket errors in the code above. Just FYI for anyone looking for a more complete sample on how to stream files directly from disk. Note, actually using synchronous I/O. If your storage backend is prone to blocking/stalling/high latency, consider running in a threadpool or use OS dependent asynchronous I/O instead.
Beta Was this translation helpful? Give feedback.
All reactions