robotconscience/ofxLibwebsockets

osx of0.9 abnormal CPU usage

natxopedreira opened this issue · 7 comments

Hi

I want to use your addon to communicate an oF app with a node socket server. But im having issues on CPU usage.

To discard errors in my code i use the client_hello_world example to test and have the same issue, just with the example:

  • if the socket not connect i get a CPU usage of 4%
  • if the socket connect i get 105% of CPU

Im on a macbook pro 2,6Ghz i5 8Gb ram

Its normal???? I tried on several computers and get the same result

WITH CONNECTION
with_internet

NO CONNECTION
no_internet

Hey @natxopedreira! That is indeed strange, let me look into it.

@mattfelsen what do you think? Could be from us not yielding in the thread and/or the more aggressive wait times you and Oriol went for? Other ideas?

Maybe helps, just begin to test previous versions of your fork

  • THIS WORKS version 13 November
  • THIS NOT WORK version 11 december

Also oriol branch works

Hey, so the issue is with the "waitMillis" in Client.cpp. For super high performance, we have that set to '0', which will run the thread as fast and as often as it can.

If you set it to anything else–even 1–CPU usage drops to ~5% instead of 95%. I need to set up a method that exposes waitMillis for those who want the high performance (streaming video, etc), and default to at least 1, maybe 5-10.

Try changing this line here to 1 or higher, should be a good temp fix for you for now!
https://github.com/labatrockwell/ofxLibwebsockets/blob/master/libs/ofxLibwebsockets/src/Client.cpp#L38

Yes, it works ok now!!!!

I set waitMillis=1 and get a low CPU, thanks!!!

What its the value for?check socket for new data"?

P.D. I will do that method

It's a libwebsocket internal timeout for checking for new data, yep!

Thanks!

Sorry I was absent on this yesterday but you guys rock! 😄