nodemcu-httpserver icon indicating copy to clipboard operation
nodemcu-httpserver copied to clipboard

Efficient static serving

Open Fractal147 opened this issue 7 years ago • 4 comments

Simple changes focussed on static file serving: Drops the req table when it's never used by the fileServeFunctions, (-static and -error) by setting it to nil. Uses the socket directly in the bulk of httpserver-static.lua to avoid using buffers. Will reduce amount sent per packet to 1024 bytes from 1400, but will save at least that amount of active memory, or probably more since buffer manipulation, etc. And makes bufferedConnection local, to prevent it being a global (to save memory - anything that uses it has a local copy anyway)

Fractal147 avatar Jan 05 '18 22:01 Fractal147

Good findings! I would prefer to keep the coroutine stuff visible in as few places as possible and maybe add another function to BufferedConnection. Maybe DirectSend which would first flush the old buffer and then send the new buffer. I also thought about automatically letting Send decide whether to fragment the new buffer or if it is long enough first flush the connection and then send the new (big) buffer. Let's say if a buffer of 900 bytes rolls in and we already have 300 bytes buffered then first send the 300 and then the 900 instead of chopping the 900 bytes apart.

That way also other applications that pump data could benefit.

HHHartmann avatar Jan 07 '18 09:01 HHHartmann

@Fractal147 do you care to fix the merge conflicts and test? I will merge.

marcoskirsch avatar Nov 18 '19 19:11 marcoskirsch

@marcoskirsch Err, I've completely forgotten about this! I'm still pretty new to github - what do you need me to do?

Fractal147 avatar Nov 19 '19 20:11 Fractal147

There is a built-in online conflict editor which is enough if the conflicts are simple.

marcoskirsch avatar Nov 19 '19 22:11 marcoskirsch