Performance Implications of XPC polling

On my MAC, I have a XPC server running as a daemon. It also checks the clients for codesigning requirements.

I have multiple clients(2 or more).

Each of these clients periodically(say 5 seconds) poll the XPC server to ask for a particular data.

I want to understand how the performance of my MAC will be affected when multiple XPC clients keep polling a XPC server.

Answered by DTS Engineer in 823970022

I want to understand how the performance of my MAC will be affected when multiple XPC clients keep polling a XPC server.

In terms of XPC's direct impact, that really depends on how fast you're polling. Case in point:

Each of these clients periodically(say 5 seconds) poll the XPC server to ask for a particular data.

In terms of the impact XPC itself has, I think it would basically be impossible to detect or really measure the impact of a single (or even "several") XPC every 5s. There could be secondary effect that MIGHT relevant, for example:

  • The actual "work" that XPC message initiated.

  • Side effects like activity that also kept the machine awake.

...but the actual cost of a single mach IPC (what XPC actually uses) is about as heavily optimized as it can possibly. Even under HIGHLY controlled conditions, I think it would be nearly impossible to even detect the impact of 1 message every 5s.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

I want to understand how the performance of my MAC will be affected when multiple XPC clients keep polling a XPC server.

In terms of XPC's direct impact, that really depends on how fast you're polling. Case in point:

Each of these clients periodically(say 5 seconds) poll the XPC server to ask for a particular data.

In terms of the impact XPC itself has, I think it would basically be impossible to detect or really measure the impact of a single (or even "several") XPC every 5s. There could be secondary effect that MIGHT relevant, for example:

  • The actual "work" that XPC message initiated.

  • Side effects like activity that also kept the machine awake.

...but the actual cost of a single mach IPC (what XPC actually uses) is about as heavily optimized as it can possibly. Even under HIGHLY controlled conditions, I think it would be nearly impossible to even detect the impact of 1 message every 5s.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Each of these clients periodically(say 5 seconds) poll the XPC server to ask for a particular data.

I should also ask, why are you doing this? While the performance impact is minimal, polling itself is rarely the best solution and there shouldn't be any reason you should have to do this.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

In my requirement, there is a status flag in the server. Any client can change this flag and I want the other clients to know about this change when it happens.

In my requirement, there is a status flag in the server. Any client can change this flag and I want the other clients to know about this change when it happens.

Polling is the wrong way to do this.

For really simple, basic cases your clients can just call into the server with a method that has a reply and the server "holds" onto the reply blocks, calling it as soon as the flag changes (Quinn calls this "long polling").

However, XPC is also fully bidirectional and Quinn has a forum post here that's covers the other options but "Reversed connection the easy way" in particular is quite straightforward. Also, you may want to take a look at "XPC Resources" which is basically in index of other posts and resources which you may find useful

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Performance Implications of XPC polling
 
 
Q