evgenido / stomp

STOMP client library written in C
GNU Lesser General Public License v3.0
15 stars 15 forks source link

High CPU usage #7

Closed dmelo closed 1 year ago

dmelo commented 6 years ago

I'm using callgrind to tell why my program is consuming all CPU and it turns out select is being called tens of thousands of times a second. I wonder it would be a good idea to place a usleep inside the while(s->run).

Here is a snippet of callgrind_control called a few seconds after process start:

  Frame: Backtrace for Thread 2
   [ 0]  select (361723 x)
   [ 1]  stomp_run (2 x)
   [ 2]  thread_stomp (2 x)
   [ 3]  start_thread (4 x)
   [ 4]  clone

https://github.com/evgenido/stomp/blob/fd6145ff234fa1ecd11ba41a0f171ff0fc6eb1e5/src/stomp.c#L795

lukcuc commented 6 years ago

move

tv.tv_sec = t / 1000; tv.tv_usec = (t % 1000) * 1000;

into the while loop