uhttpd / ucode streaming buffers small chunks until ~1 KB before flushing #8654
-
|
Hi everyone, I have a question regarding a live text stream implementation using ucode inside LuCI. To avoid polling every few seconds, I keep a request open until shortly before timeout and then immediately restart it again (long-polling/streaming). Conceptually this works well, but I am running into an annoying buffering issue and I am wondering whether this behavior can be configured somewhere. The problemData only appears in the LuCI request once the streamed chunks from ucode reach roughly 1,152 bytes. It seems like some layer in the pipeline buffers the output before flushing it to the client, but I cannot figure out where this happens. What makes this more confusing is that I am fairly sure this behavior did not exist in 24.10, so it feels like something changed recently. I already spent quite some time digging through commits but could not identify the cause. Current workaroundI am streaming data from the Podman API. Most chunks returned by Podman are significantly smaller than 1 KB. My current workaround is to artificially pad the chunked response with dummy bytes until it crosses the ~1 KB threshold, which forces the stream to flush immediately. Obviously this feels very hacky. Questions
You can see my actual code here: Are there any plans to support streaming within the jsapi? I do not like the "Poll every second if maybe something happened" - i more like "do something if something happened" 😉 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
|
The best options around this problem include using WebSocket. I've tried integrating one solution but kept hitting various problems. If you're feeling brave, you can look at what I did for dockerman: talking directly with the API, and not via http anything, to avoid problems like these, e.g. consume API response, create sink, prepare own response and headers to permeate the uhttpd proxy, fill buffers, empty sink into consumer.... The most instant response available is using the WS console to a container, but this works well because docker's WS implementation is solid. Otherwise if you have something that works, stick with that and see what real-world usage/testing reveals. |
Beta Was this translation helpful? Give feedback.
The best options around this problem include using WebSocket. I've tried integrating one solution but kept hitting various problems.
If you're feeling brave, you can look at what I did for dockerman: talking directly with the API, and not via http anything, to avoid problems like these, e.g. consume API response, create sink, prepare own response and headers to permeate the uhttpd proxy, fill buffers, empty sink into consumer....
The most instant response available is using the WS console to a container, but this works well because docker's WS implementation is solid. Otherwise if you have something that works, stick with that and see what real-world usage/testing reveals.