How to reduce CPU demand from any application


D

Denis @ TheOffice

Hi,



I made a custom Browser using the IE engine.

On certain pages it uses all the CPU and prevent other session from navigating properly.

As I can see I need to reduce the CPU time slice.

I already tried to lower my application priority to the minimum without success

How do I reduce CPU demand from my application when embedding the web?
 
Ad

Advertisements

B

Ben Voigt

Denis @ TheOffice said:
Hi,



I made a custom Browser using the IE engine.

On certain pages it uses all the CPU and prevent other session from
navigating properly.

As I can see I need to reduce the CPU time slice.

I already tried to lower my application priority to the minimum without
success

How do I reduce CPU demand from my application when embedding the web?

Disable javascript.
 
B

Ben Voigt

Denis @ TheOffice said:
That does not solve much...
Unless there was a way to disable it Programmatically and temporarily?

See http://msdn.microsoft.com/workshop/browser/overview/Overview.asp

Toward the bottom of the page, it describes a DISPID_AMBIENT_DLCONTROL
property where you can set flags which include, among others:
DLCTL_NO_RUNACTIVEXCTLS
DLCTL_NO_SCRIPTS
DLCTL_NO_JAVA

These are the things that can run arbitrary code and slow down the browser a
lot. You may want to enable/disable them depending on the URL. They will
only affect your WebBrowser control, normal IE windows will use the user's
security settings. You could monitor CPU usage, but by the time it
increases it may be too late -- setting these flags probably won't make any
difference until the page refreshes and if a script is running in a tight
loop, even that may not be possible.
 
D

Denis @ TheOffice

Ben Voigt said:
See http://msdn.microsoft.com/workshop/browser/overview/Overview.asp

Toward the bottom of the page, it describes a DISPID_AMBIENT_DLCONTROL
property where you can set flags which include, among others:
DLCTL_NO_RUNACTIVEXCTLS
DLCTL_NO_SCRIPTS
DLCTL_NO_JAVA

These are the things that can run arbitrary code and slow down the browser a
lot. You may want to enable/disable them depending on the URL. They will
only affect your WebBrowser control, normal IE windows will use the user's
security settings. You could monitor CPU usage, but by the time it
increases it may be too late -- setting these flags probably won't make any
difference until the page refreshes and if a script is running in a tight
loop, even that may not be possible.

I am aware the DISPID_AMBIENT_DLCONTROL, although, it is a one way street.
Meaning, the web control ask if I want those options at the beginning of a page. I need those to be
fully working to be a full browser, what I would need is control over them and how they behaves.

What I would need is the functionality of throttling the CPU for the web browser.
Pretty much like the one for the web server IIS 5.0++.


Here is an idea for the developers of Windows:
Better yet what would be a nice feature to be added in the future OS of Windows would be to be able
to limit maximum time slice or % of CPU, instead of just Priority ("Until something better").
I think, for specific type of application like I do it would be a blast.
With a little bit of imagination one could easily estimate if the current tasks are overloading the
CPU and choose a different path. For example XP with it's bunch of goodies use too much out of most
CPU.
One could decide to remove/disable temporarily/warn user/etc... In such a case.

Regards,
Denis
 
B

Ben Voigt

Denis @ TheOffice said:
I am aware the DISPID_AMBIENT_DLCONTROL, although, it is a one way street.
Meaning, the web control ask if I want those options at the beginning of a
page. I need those to be
fully working to be a full browser, what I would need is control over them
and how they behaves.

What I would need is the functionality of throttling the CPU for the web
browser.
Pretty much like the one for the web server IIS 5.0++.


Here is an idea for the developers of Windows:
Better yet what would be a nice feature to be added in the future OS of
Windows would be to be able
to limit maximum time slice or % of CPU, instead of just Priority ("Until
something better").

Windows is pretty much designed to allocate 100% of CPU, and you just get to
change the split. If the CPU will otherwise be idle, even an idle priority
process can run. Are you trying to save battery or something? Why try to
limit the CPU usage below 100%, as long as high priority apps run fast?
I think, for specific type of application like I do it would be a blast.
With a little bit of imagination one could easily estimate if the current
tasks are overloading the
CPU and choose a different path. For example XP with it's bunch of goodies
use too much out of most
CPU.
One could decide to remove/disable temporarily/warn user/etc... In such a
case.


Well, you can certainly have another thread changing the priority of the web
browser thread or even suspending it.... There are performance counters
showing how much CPU each thread has used, such as show up in Task Manager.

Could you not just run a high priority thread, which calls SuspendThread on
your web browser, sleeps 90 ms, calls ResumeThread, sleep 10ms, etc.?
 
Ad

Advertisements

D

Denis @ TheOffice

Ben Voigt said:
Windows is pretty much designed to allocate 100% of CPU, and you just get to
change the split. If the CPU will otherwise be idle, even an idle priority
process can run. Are you trying to save battery or something? Why try to
limit the CPU usage below 100%, as long as high priority apps run fast?



Well, you can certainly have another thread changing the priority of the web
browser thread or even suspending it.... There are performance counters
showing how much CPU each thread has used, such as show up in Task Manager.

Could you not just run a high priority thread, which calls SuspendThread on
your web browser, sleeps 90 ms, calls ResumeThread, sleep 10ms, etc.?

Yes, this is what I am trying. But it seems more complicated than that.
It seems that when IE is opening an excel files using an Out of proc is starting another process
which could consume CPU. Plus it gets worse when I try to place my app in a Job and realized that
the Out of proc is outside the Job... Now I am back to square one.

Now for the sake of understanding this issue. Here is an explanation for you.

The App I am working on is meant to be used by Terminal Clients. the thing is with that poorly
design CPU priority is all those clients using my app runs at idle. as a result when one is using
more CPU than another the other clients suffer the performance lost. (Nothing compare to limiting
time slice, anyway).


For MS who design Terminal server they should have though of that. Or at least start thinking about
this.
If I was designing this, I would limit time slice of all threads in the priority of the same level.

Now I have to cope and try to overcome that flaw.

Denis
 
Ad

Advertisements

B

Ben Voigt

Denis @ TheOffice said:
Yes, this is what I am trying. But it seems more complicated than that.
It seems that when IE is opening an excel files using an Out of proc is
starting another process
which could consume CPU. Plus it gets worse when I try to place my app in
a Job and realized that
the Out of proc is outside the Job... Now I am back to square one.

Now for the sake of understanding this issue. Here is an explanation for
you.

The App I am working on is meant to be used by Terminal Clients. the thing
is with that poorly
design CPU priority is all those clients using my app runs at idle. as a
result when one is using
more CPU than another the other clients suffer the performance lost.
(Nothing compare to limiting
time slice, anyway).


For MS who design Terminal server they should have though of that. Or at
least start thinking about
this.
If I was designing this, I would limit time slice of all threads in the
priority of the same level.

Now I have to cope and try to overcome that flaw.

Denis

Ahh, yes, instead of equal timeslice for every thread, it should be equally
divided by user session.

As for out-of-process activation, that changes your problem. You are no
longer trying to limit the CPU usage of your process, but other processes
running in your session. You could set a raised thread priority plus low
process priority class, but that will only affect out-of-process activation
spawned by your app, as you have already noticed with the job objects. If
the other application is already running, or depending on DCOM invocation
internals, it is not a child of your process.

In order to control the CPU time of all processes on the system, I suggest
you
use HKLM\Software\Microsoft\Windows NT\CurrentVersion\Windows\AppInit_DLLs
to autoload a DLL into every process, which will then monitor its CPU usage
and adjust priority appropriately.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top