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 / Lowering CPU usage.

Author
Message
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 25th Jul 2005 08:03 Edited at: 25th Jul 2005 08:04
I know by default DBPro is a DirectX(DX) app and DX use 100% of CPU time by default. Is there a way to limit or reduce this for less intensive apps. For example:

I'm making an app that will also have smaller less graphically intensive standalone apps that come with it. Like a game and an editor. I need a way to reduce the effects of the less graphically instensive app on the one that is more so. Ex:
Game: 60FPS
open 2nd App
Game = 30FPS, but 2nd app=600FPS (only needs<60)
at the moment cpu time is divided evenly between the 2.

Is there a way to devote me CPU/DX time to the primary app or reduce the 2nd app's CPU usage?

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 25th Jul 2005 08:09
oui ce serait intéressant
Surtout pour les ordinateurs portables

Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 25th Jul 2005 08:18
Il sauverait la vie de batterie, mais n'est pas ce pour ce que j'ai besoin de lui.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 25th Jul 2005 09:28
omlette du fromage
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 25th Jul 2005 09:33
Sorry Dex, that answer won't solve this problem.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Jul 2005 10:03
look into sync off rather than on That only uses whats needed, rather than slaughtering your CPU for 1fps when it can do 2000

My Website:
the_winch
22
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 25th Jul 2005 10:27
You have to manage it manually. Dbpro isn't intelligent enough to know which commands to use more cpu on and which commands not to.
If you need some commands to run quickly just use SYNC ON before them and then SYNC OFF afterwards.
dark coder
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 25th Jul 2005 10:39
i find using 'end' is great for freeing up cpu usage, also using 'x rotate object 1,361' they both free up all the cpu strange


Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 25th Jul 2005 10:40
Sounds go to me I think you've solved my problem. I'm using multiple windows so I can just only turn on the editor's sync on when I'm using that window. I'm will experiment and check it out.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Jul 2005 18:21
if you use sync off, even if you do sync then tell it to wait for half a second.. or wait for keys or something - it'll still eat 100% of the CPU. sync on is good. If you make a spinning cube and sync rate it to say 30 then use sync on - you'll notice your CPUI usage will be VERY low (assuming your PC can handle a spinning cube )

My Website:
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 25th Jul 2005 22:13
SYNC OFF does two things -

1. Switches on the checking in the DBPro runtime to do automatic syncs - can result in 'funny things' happening in your game.
2. Sleep for 1 ms during the sync.

You can continue to use SYNC ON to keep your display under control, and just put a sleep into your main game loop to give other processes a chance to run.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Jul 2005 23:45
I've tried that (on V5.7) and I'm sure it just sat there eating 100% of the CPU, but just "doing" less...

My Website:
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 25th Jul 2005 23:47


Wow this runs at only 1% cpu usage. Never new that was possible! Would this be a good idea to use in a multiplayer server app where there are no 3d graphics or text just mp commands in use? And I'm using bluegui so I don't think I need to sync at all really.

I tried the sleep but it stays at 100% even with sleep 5000

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 25th Jul 2005 23:49
thats what i thought happened...

And yes - Sync off is the best way to make a DBP based server app - I played about with it before, works smegging well. The nice things is, you can run bothe client and server app on your PC without either one dying a horrible death due to both wanting the whole processor to themselves!!

My Website:
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 26th Jul 2005 00:08
Yeah you're right I just tried it, seems to work like a charm. Now I can leave my server app running much longer. Whohoo

the_winch
22
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 26th Jul 2005 00:25 Edited at: 26th Jul 2005 00:26
Quote: "Would this be a good idea to use in a multiplayer server app where there are no 3d graphics or text just mp commands in use?"


Like IanM said with SYNC OFF it syncs automatically when it feels it is required and the sync includes a 1ms sleep with each sync. This works fine when the program isn't doing much.
However it means the program is going to be sleeping for (num of syncs a second * 1 ms) per second even if it has lots of work to do.
This puts a cap on the maximum amount of work the program can do in a set period of time. If you need to do more work than the limit you need to use SYNC ON to switch back to normal then use SYNC OFF to switch back.

Bit of a pain for server programming.
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 26th Jul 2005 01:04
If the program syncs automatically with sync off will the screen refresh like a normal sync? If so it will be easy to check for it. Although I imagine it would be just commands that effect the diplay or 3d objects updating etc. that would cause an automatic sync. I doubt standard maths commands, memblocks etc. would cause a sync. Anyways my program seems to be running fine but I'll bear it in mind and keep an eye out for any pauses or lag.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 01:38
apart from the statement above - how do we actually know it sleeps for 1ms?

My Website:
AndyUK
22
Years of Service
User Offline
Joined: 2nd Apr 2003
Location: United Kingdom
Posted: 26th Jul 2005 01:57 Edited at: 26th Jul 2005 02:00
good point nic, i managed to get a dbp app to use 85% of my overclocked athlon64 with sync off. if there was a 1ms delay in the loop, would the usage be this high? i just thought with sync off, dbp let windows sort the timing. i think the 1ms delay may be a myth, i hope someone out there can prove it eitherway, at least we would know.

| AMD Athlon XP 2000+ | 512DDR(400) | GF4Ti4200 128MB | WinXP Pro | Cup of Coffee |
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 02:06
well if there was a 1ms delay the framerate would max out at 1000fps (wouldn't even get to that because that assumes everything else apart from the 1ms sleep take 0ms, techincaly impossible for something to take no time ). So if someone with an Über PC (Like you andy) you make a sync-ed off app go at 1500fps, thats the 1ms sleep thing proved wrong, imho...

My Website:
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Jul 2005 02:11
If you look at the CPU usage when using SYNC ON/SLEEP, you will indeed see it using 99% ... right up until the point where you actually run something else alongside it. You'll see then that the DBP app will actually allow other programs to steal CPU time from the DBP app at will.

The cpu usage column in task manager is sometimes just as misleading as the memory usage column.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 02:13
Hmmmmm.. Intruiging!!! I've never tried it THAT way.. I might do that tonight...

My Website:
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 02:29 Edited at: 26th Jul 2005 02:46
Thanks for all the info. In my current project only only one part uses 3D or graphics of any sort. So now I'm using sync off except when that window is displayed and then switching back when it gets closed. It's for the IDE I'm making which doesn't really need sync on except for the media viewer. Thanks for all the help.

P.S. For the multiple app scenerio above I will try using a bigger sleep in the 2nd and a smaller in the first to balance CPU time.(I hope that works.)

[edit]Update: In the multiple app case it didn't divide they way it should.
App1:

App2:

App 2 went at 5 FPS vs App 1 @ 500, but both used 50% CPU Time.
App3:

Only uses 1%, but the text blinks. I gets worse if I add a sleep command.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 26th Jul 2005 03:04
IanM that seems to happen anyway without using the sleep command in the program. But I suppose that's because the DBPro app doesn't actually need the 99% but with a bigger program that does you would probably need to force it to sleep. Which means is there any real advantage in sync off? Well it does seems to make a difference with my laptops fan, with sync off and 1% cpu it's quiet, but with sync on and 99% it's noisy and gets hot as hell. I suppose for certain apps sync off is good as there is no point running the processor at full speed if the program is only small.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 04:07
It all depends what your doing. If its a full on FPS with shaders and GFX killing models - use Sync On and manually sync the app. If its a dedicated server app the only needs to print "Players connected: 0" every 2 seconds, then sync off will be fine!

BTW: I used sync off in my bezier screensaver app - its much better as the screensaver can be tuned to only use 10-20% CPU rather than the screensaver saving the Screen but blowing up the CPU.

My Website:
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Jul 2005 04:16
Sorry too

It may be cool for my laptop computer.
I have another strange result of this.

When I launch compiler, I get the CPU fan of my laptop to start running and it stop on compilatino ending ...

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 04:18
thats because on laptops they try to conserve power by only cooling when its thinking. When you're typing, as good as you may be, you CPU is doing next to nothing and so doesn't need much cooling - however compiling is a pretty heavy process and so you laptop will need to fan itself a little to stop itself going bang...

My Website:
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 04:27
I'm was mainly trying to lower the cpu usage in my new DBPro editor. I'm going to release the latest beta with the changes a little later today. This thread has helped so thanks guys, especially Nick.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 26th Jul 2005 06:03
no no no, after you use sync off use always active off and then check cpu usage
xtom
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Ireland
Posted: 26th Jul 2005 06:21
Always active off isn't used in DBPro.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 07:32
@Xperiment 627: Eh?

My Website:
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 07:33
@xtom
Xperiment 627 has been sarcastic from his first post about the "Omlette with cheese".

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Jul 2005 07:51
After a bit of experimentation, it looks like the DBPro SLEEP/WAIT commands don't work exactly as specified. However, but using the Sleep function from Kernel.dll, you can get the control of SYNC ON, with the low cpu usage of SYNC OFF.

Here's some quick/dirty code:



Hold down the space key to activate the sleep.

The benefit of doing this extra work is that you still maintain control over when rendering takes place, you can keep the CPU usage rock bottom when needed, but can also allow the app to run full speed too.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 07:59 Edited at: 26th Jul 2005 08:10
Sweet another credit to you for my IDE. P.S. I added the search string function to the codebase for others who might want it. I commented it and modified it a little, but I left a credit to you on it. But anyway thanks again IanM.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 08:03
Ooooo nice code IanM!!! *Bows down*

My Website:
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 08:12
IanM Do you know a site that list these little Dll functions, so I might find others accessible by DBPro.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 08:38 Edited at: 26th Jul 2005 08:39
Update: With IanM's code just DoSleep(1) is enough to make resource usage go rock bottom. As my app isn't performance critical. Also I plan to increase my apps sleep state to only get about 1 FPSn or less while a users app is running after compile which means the only resource issues from this point should be memory related. Does any one know where to find a list of the media types DBPro handles(I'm building in a media viewer). I need to know what the different load commands can handle. I will get what I can from the help files and from the help website, but if anyone knows something not listed (like gif as an animation).

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 26th Jul 2005 08:39
wrong. after 5.7 always active does work and lowers the cpu usage to zero. and the omlette with cheese is the only french i know so i thought it might help
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 08:42
Thx 627 I will use always active off after compile. Another reason the help files need to be updated.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 26th Jul 2005 08:44
what is active off? It wont accept it as a command and I use 5.8...

My Website:
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 08:46 Edited at: 26th Jul 2005 08:49
ALWAYS ACTIVE OFF
ALWAYs ACTIVE ON

You app stops running whenever another app is active w/ALWAYS ACTIVE OFF

Still using DoSleep(1) while the app is active and ALWAYS ACTIVE OFF when it's not. So, thx IanM and Xperiment 627.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 26th Jul 2005 19:51
An additional question may be :

If I use ALWAYS ACTIVE OFF and my app run in fullscreen mode.
If another APP is active.
and, if after this I switch back to my APP
Will I have to reload all or will the sleep prevent from this problem ?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 26th Jul 2005 21:37
Quote: "Do you know a site that list these little Dll functions"


Unfortunately, just MSDN, or if you have visual studio, then the VS documentation - there are 1000's of functions available, and you have to know what you are looking for.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Keaz
21
Years of Service
User Offline
Joined: 22nd Sep 2003
Location: Somewhere in south Texas
Posted: 26th Jul 2005 23:22
@Freddix I don't know I'm using windowed mode so not an issue for me.

@IanM Thx anyway. I guess if I need it then I'll go hunting.

Breaking Stuff=Fun!,Bug Testing<>Fun!, Bug Testing=Breaking Stuff, so...
Bug Testing=Fun! Hmmmm....
DOES NOT COMPUTE! SYSTEM MALFUNTION!
Xolatron old
21
Years of Service
User Offline
Joined: 25th Jan 2004
Location: The Star Forge Language: DBpro
Posted: 27th Jul 2005 01:26 Edited at: 28th Jul 2005 05:34
Keaz, see my Ion Extension Pack Thread for some more dll calls. There is some useful stuff like exactly how big your app will be when maximized - I uses this to keep maximize/restore settings stored in my IDE (not actually announced yet).
http://forum.thegamecreators.com/?m=forum_view&t=57481&b=1

[EDIT]Here is my IDE (WIP):
http://forum.thegamecreators.com/?m=forum_view&t=57888&b=8

Thanks everyone for the CPU info, it will be very helpful!

-Xol

Login to post a reply

Server time is: 2025-08-08 10:43:06
Your offset time is: 2025-08-08 10:43:06