Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Why 99% CPU Usage?

Author
Message
Rich Swan
22
Years of Service
User Offline
Joined: 7th Aug 2003
Location:
Posted: 16th Aug 2003 16:05
The attached simple code uses 99% of CPU time when it enters the main loop (note: it takes a good few seconds to get in here while setting things up). As you can see I've added a sleep command at line 24, and set it to last a whole second in this example. In most languages this would stop the program using the CPU for this duration, freeing up the processor.

I've turned the automatic screen sync off, same for testing for the escape key, incase they were what was being run, but it makes no odds.

What is the program doing with all that CPU time, and how can I stop it? Obviously for a multiplayer server its going to be unacceptable to use all the machine's processor time, as often other servers will be running alongside it.

Is this a bug, or something that can be fixed programmatically?

Thanks in advance,
Rich
David T
Retired Moderator
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 16th Aug 2003 16:16
Probably not a bug. More a "feature".

I think any DirectX program does that - I'm not totally sure though.

You are the th person to view this signature.
GRAVITY: I fought the law but the law won
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Aug 2003 17:34
The way to get DBPro to 'play nice' with the rest of the system is to put a SYNC OFF at the top of your code.
Rich Swan
22
Years of Service
User Offline
Joined: 7th Aug 2003
Location:
Posted: 16th Aug 2003 18:04
Many thanks Ian, indeed that drops the cpu usage to nothing.

Just out of interest, this is kind of the opposite of what I expected, as the system must now be refreshing that screen more than I was doing (in the Help it states: "By default, sync is set to off which allows the system to automatically handle screen refreshing. When SYNC ON is used, your program is responsible for handling
screen refreshing")

Is the help file back to front, or does allowing the system to refresh the screen have some side effects in other areas?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Aug 2003 19:00
There are now three behaviours in the SYNC system:

1) You don't specify - syncs when it wants to
2) SYNC ON - syncs when you tell it
3) SYNC OFF - syncs when it wants to, and pauses for 1 ms after doing so.

The third behaviour was introduced at patch 4. Basically, the help file is slightly out of date.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 17th Aug 2003 02:50
So, why use SYNC OFF if there is a 1ms delay after each refresh, when you can tell it to refesh and not have the delay ?


Logo design by Indi
Its better than a poke in the eye...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2003 03:02
It allows you to play nice with the system for non-game apps.

The pause does more than you think. When you issue a 'wait' (a kernel wait) you give up the rest of your timeslice to the system which allows other apps to get their fair share of the system.
heartbone
23
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 17th Aug 2003 03:08 Edited at: 17th Aug 2003 03:20
Would not this be better?

1) You don't specify - syncs when it wants to, and pauses for 1 ms after doing so.
2) SYNC ON - syncs when you tell it
3) SYNC OFF - syncs when it wants to

Without a doubt it certainly is more logical.
Would not this default be better behaviour for everyone in general?

-----edit

Actually a much better solution would be two new commands.

Call them Nice On and Nice Off.
Default to Nice On.

And remove the nice behaviour from the Sync command set.

The more you see, the more you know.
The more you know, the more you see.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2003 03:26
Changing the default behaviour would raise too many complaints, but yes, a new command would be have been better.

SYNC NICE maybe?
Dreamora
23
Years of Service
User Offline
Joined: 20th Sep 2002
Location: Switzerland
Posted: 17th Aug 2003 05:23
another question: why the hell is dbp faster with sync off??

*just tested sync on sync off in my world editor project and was shocked about the speed gain of over 50% ...*

Login to post a reply

Server time is: 2026-07-22 18:53:59
Your offset time is: 2026-07-22 18:53:59