1
votes

I reading high frequency data through tcp and with following code

 while (1) {
    lrev = recv(fd, buff, 80, MSG_WAITALL);
    dowork();
 }

I am running this code through a thread and assigned this thread to a specific CPU core. I can see that the particular core using 100% CPU. Is it because while(1) loop ? Is it good or bad for the latency purpose ?

My process have 5 threads and each thread is running on separate core. My total cpu usage is around 400%.

Thanks

1
Check the value returned by recv :/ - Captain Obvlious

1 Answers

3
votes
  • I can see that the particular core using 100% CPU. Is it because while(1) loop ?

We don't see all your code, but a while(1) processing non blocking functions will usually spin at 100% on the CPU to which it is bounded

  • Is it good or bad for the latency purpose ?

For very latency sensitive systems, it is usually good (if you want to minimize the time/latency between the arrival of a packet on the network card and the time when you started processing it)

However your call to receive with MSG_WAITALL might block, which would be bad for your latency

This flag requests that the operation block until the full request is satisfied.

The only definitive answer to say if it is good or bad is : measure your latency in all scenarios.

EDIT:

As commented by @ Captain Obvlious, you must check the value returned by recv