robotconscience / ofxLibwebsockets

[Deprecated] openFrameworks wrapper of libwebsockets for WebSocket client and server functionality
Other
171 stars 68 forks source link

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

Open ofZach opened 8 years ago

ofZach commented 8 years ago

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.

robotconscience commented 8 years ago

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.

ofZach commented 8 years ago

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!

robotconscience commented 8 years ago

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.