client-sleep

I have seen this in a few panda3d examples around and I was wondering what it does.
loadPrcFileData(’’, ‘client-sleep 0.001’)

The only explanation that the manual gives for “client-sleep” is that it’s a double with 0 default and “DConfig” description.

As a matter of fact numerous entries on the manual have “DConfig” in it’s description:
panda3d.org/manual/index.php … _Variables

Are those config variables related to DirectX only or something like that?

It adds 1 millisecond of wait time every frame to take a lot of load off the CPU, so that other tasks can be done more smoothly while the application is running. It is not specific to DirectX.

Then Isn’t this the same as forcing a max framerate?

loadPrcFileData(’’, ‘client-sleep 0.1’)
would force a max framerate of 10 fps? Testing it I actually get ~8.5 fps which I supose is some kind of overhead.

No, limiting the FPS is not the same as adding an overhead every frame. 0.1 means that it adds 100 milliseconds every frame. So if your ms/frame is, say, 25 (which equals 40 FPS), and set client-sleep to 0.1, then the amount of ms/frame gets 125, which translates to 8 FPS.

Aren’t tasks normally run once per frame? So this is only useful for asynchronous tasks?

I don’t know what you mean there. Tasks are indeed normally run once per frame. Setting client-sleep has the effect of adding an additional task, which does just one thing: sleep(timeout). This adds the requested wait time to the overall frame.

You don’t have to do client-sleep at all. The reason you would do this (if you choose to do it at all) is to allow the CPU to do some things for other processes between calculating frames of your Panda process. Even if you don’t do client-sleep, the CPU can still handle other processes, of course, but it will be less effective at this.

Put another way, if you don’t do client-sleep, your CPU utilization will peg at 100%. If you do add a client-sleep, it will be considerably less.

It has nothing to do with synchronous or asynchronous tasks. The point is just to yield the CPU timeslice periodically.

David

Thanks now I get it, when rdb said “so that other tasks can be done more smoothly” I assumed he meant panda tasks that was the cause of my confusion. This client-sleep should be useful for computers with only one core.