ofxLibwebsockets icon indicating copy to clipboard operation
ofxLibwebsockets copied to clipboard

ofxLibwebsockets::Server::threadedFunction needs to chill (sleep)

Open ofZach opened this issue 9 years ago • 3 comments

in a multi-threaded context ofxLibwebsockets::Server is pretty aggressive since it doesn't have any sleeping going on (as far as I can see). I don't know the best solution, but in profiling in a project that involves lots of pieces I found I was spending alot of time in this function. adding a tiny sleep helps a ton, but if the sleep is too long you can also get lags on sending.

just thought I'd point out that it seems a bit agressive.

ofZach avatar Mar 25 '16 22:03 ofZach

Hey Zach! Sounds totally reasonable. I was just wrestling with a similar issue (#82 I think?) and it helped to tweak lws' waitMillis as well. (Last PR exposed the ability to do so)

Do you think a sleep or yield() would be better? I'll experiment with both once I'm back on my comp.

robotconscience avatar Mar 25 '16 23:03 robotconscience

I'm not sure what is better! to make things lighter on myself I wound up implementing something using node / socket.io and node osc (via this https://github.com/automata/osc-web but with some mods for https) which seems snappy for what I needed to do but feels a little less rigid than if I am running it in OF (ie, now there's three pieces / OF / node / browser instead of two) but overall feels like it's doing the right thing in terms of being friendly thead wise.

when I have some more time I'll try to do more testing!

ofZach avatar Mar 26 '16 23:03 ofZach

All good! I added yield() to both; that + the waitMillis fix from @natxopedreira make it definitely chill more. Let me know if you end up testing further, will do some more experiments on my end as well.

robotconscience avatar Mar 28 '16 17:03 robotconscience