[fpc-pascal] My Linux service application consumes 10% CPU when idling - why?

Bo Berglund bo.berglund at gmail.com
Sun Oct 17 15:18:43 CEST 2021

On Sun, 17 Oct 2021 12:03:44 +0200 (CEST), Michael Van Canneyt via fpc-pascal
<fpc-pascal at lists.freepascal.org> wrote:

>> Does this mean that:
>> _newselect is running for 207 ms during the 3 second test time?
>> (Which is 17 ms per call)
>> And what is _newselect in the first place?
>Select (or _newselect) checks if there is activity on a file descriptor.
>If you're working with Indy, it uses this call to check for data on a
>socket; It is called frequently.
>> I assume nanosleep is some kind of Linux API call made by fpc when it invokes
>> sleep() in my code.
>> And futex????
>Futex is used for thread synchronisation. 
>Again, if you're using Indy and threads, it is called a lot.

You are right concerning Indy usage!
This is what is used for the networking part. The application has been ported
from Delphi on Windows where it was a TService based application.

I will have to look at what is going on with the permanent increase in activity
during (expected) and after a task execution (should go back to idle).

But I will have to do a couple of more checks where I make it start a task and
while the task executes run the strace -c recording.

Some objects might not be freed properly or else do not get down to idle

The code is quite big and handles several separate aspects, like client
communication via TCP/IP socket, scheduling the tasks, running a task and
collecting the output data, mailing the result data to configured recipients.

My test done with strace was done after I have communicated with the application
as a client.
I really need to test this:
- right after the service restart
- during a client communication session
- after disconnecting a client
- after switching on scheduling
- during a task execution
- after task execution

So there will be a lot of data gathering to see what changes, but since I did
not know about strace and it seems able to do this it might actually work.

Thanks for pointing me towards it!

Bo Berglund
Developer in Sweden

More information about the fpc-pascal mailing list