Re: when to force an app to consume less resources
On Wed, 14 Jan 2009, alexandre_paterson@yahoo.fr wrote:
The only "problem" is that my workstation, running Linux (Debian etch),
starts to become kinda unresponsive when running the optimized version
of our parser, while everything was fine using the old, unoptimized
parser (except that the app was one order of magnitude slower to parse
the text files, of course).
The same, optimized, app on MacOS X acts much nicer : I can see that
both cores (on a Core 2 Duo / Mac Mini) are being fully used, but I can,
say, play videos fine (it was just a test to see how the app was
responding).
I think this is because Apple's media-playing apps (and possibly some
third-party ones - maybe it happens through the quicktime framework or
something) grab themselves a higher priority, to make sure they can meet
their realtimey guarantees. I guess the window manager does the same.
Seen that some OSes *shall* start to become laggy when one application
consumes a lot of resources (we've *all* seen that behavior at least
once) and seen that I've got no control over how the OS runs the app
(e.g. I can't ask the user to "nice" the Linux app to lower its
priority), should I artifically limit the resources used by my app?
On non-OS X unix, nice/renice really is the way to go here. Put it in a
startup script, run it in a subshell, write a native method that calls
getpid/setpriority, whatever. A launch script would be easiest; if you
can't do that, the native method is fairly easy and nice and clean.
There's probably a comparable API call on windows.
I don't know of a portable way to do it through java, though - that would
be a nice feature.
For example I noticed that by forcing every worker thread to sleep for a
few milliseconds every 'x' files parsed I could both obtain a very high
troughput and have my workstation stay responsive.
Stated in another way : once I've optimized my application so that it's
not stupidly unnecessarily bound to some resources, should I start
"freeing some of that resource" to make the OS happy?
If you're not prepared to use a system-specific mechanism to achieve this,
then yes, i think this is the way to go. Thread.sleep() FTW.
I could see other cases where you would be hard disk bound once you've
optimized the way your app work, would you then start "giving the hard
disk a breath" ?
Or network usage ?
Sleeping works for those too, i guess.
tom
--
The Impossible is True