Hi folks, Attached is a patch that simplifies how nice is done. Instead of prefixing all external programs with a call to "nice -n10", it calls POSIX::nice near where tilesGen.pl starts, and all child processes inherit its niceness automatically.
It works fine for me here, but I'd appreciate a second pair of eyes, and also that somebody with Windows can confirm it fails gracefully. Thanks, Andrew
Index: tilesGen.pl
===================================================================
--- tilesGen.pl (revision 9419)
+++ tilesGen.pl (working copy)
@@ -36,6 +36,7 @@
use English '-no_match_vars';
use GD qw(:DEFAULT :cmp);
use AppConfig qw(:argcount);
+use POSIX;
#---------------------------------
@@ -71,6 +72,14 @@
my $Layers = $Config->get("Layers");
+# Be nice. Reduce program priority
+if ($Config->get("Niceness")) {
+ my $success=POSIX::nice($Config->get("Niceness"));
+ if ($success==undef) {
+ printf STDERR "WARNING: Unable to apply Niceness. Will run at normal priority";
+ }
+}
+
# Get version number from version-control system, as integer
my $Version = '$Revision$';
$Version =~ s/\$Revision:\s*(\d+)\s*\$/$1/;
@@ -1038,16 +1047,14 @@
{
# Pre-process the data file using maplint
# TODO may put this into a subroutine of its own
- my $Cmd = sprintf("%s \"%s\" tr %s %s > \"%s\"",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("\"%s\" tr %s %s > \"%s\"",
$Config->get("XmlStarlet"),
"maplint/lib/run-tests.xsl",
"$inputFile",
"tmp.$PID");
statusMessage("Running maplint", $currentSubTask, $progressJobs, $progressPercent,0);
runCommand($Cmd,$PID);
- $Cmd = sprintf("%s \"%s\" tr %s %s > \"%s\"",
- $Config->get("Niceness"),
+ $Cmd = sprintf("\"%s\" tr %s %s > \"%s\"",
$Config->get("XmlStarlet"),
"maplint/lib/convert-to-tags.xsl",
"tmp.$PID",
@@ -1058,8 +1065,7 @@
}
elsif ($preprocessor eq "close-areas")
{
- my $Cmd = sprintf("%s perl close-areas.pl $X $Y $Zoom < %s > %s",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("perl close-areas.pl $X $Y $Zoom < %s > %s",
"$inputFile",
"$outputFile");
statusMessage("Running close-areas", $currentSubTask, $progressJobs, $progressPercent,0);
@@ -1067,8 +1073,7 @@
}
elsif ($preprocessor eq "mercator")
{
- my $Cmd = sprintf("%s perl mercatorize.pl %s > %s",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("perl mercatorize.pl %s > %s",
"$inputFile",
"$outputFile");
statusMessage("Running Mercatorization", $currentSubTask, $progressJobs, $progressPercent,0);
@@ -1455,8 +1460,7 @@
$XslFile = "osmarender/osmarender.xsl";
- my $Cmd = sprintf("%s \"%s\" tr --maxdepth %s %s %s > \"%s\"",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("\"%s\" tr --maxdepth %s %s %s > \"%s\"",
$Config->get("XmlStarlet"),
$Config->get("XmlStarletMaxDepth"),
$XslFile,
@@ -1469,8 +1473,7 @@
elsif($Config->get("Osmarender") eq "orp")
{
chdir "orp";
- my $Cmd = sprintf("%s perl orp.pl -r %s -o %s",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("perl orp.pl -r %s -o %s",
$MapFeatures,
$TSVG);
@@ -1500,8 +1503,7 @@
#-----------------------------------------------------------------------------
if (!$NoBezier)
{ # do bezier curve hinting
- my $Cmd = sprintf("%s perl ./lines2curves.pl %s > %s",
- $Config->get("Niceness"),
+ my $Cmd = sprintf("perl ./lines2curves.pl %s > %s",
$TSVG,
$SVG);
statusMessage("Beziercurvehinting zoom level $zoom", $currentSubTask, $progressJobs, $progressPercent,0);
@@ -1561,9 +1563,8 @@
if ($Config->get("Batik") == "1") # batik as jar
{
- $Cmd = sprintf("%s%s java -Xms256M -Xmx%s -jar %s -w %d -h %d -a %f,%f,%f,%f -m image/png -d \"%s\" \"%s%s\" > %s",
+ $Cmd = sprintf("%s java -Xms256M -Xmx%s -jar %s -w %d -h %d -a %f,%f,%f,%f -m image/png -d \"%s\" \"%s%s\" > %s",
$Config->get("i18n") ? "LC_ALL=C " : "",
- $Config->get("Niceness"),
$Config->get("BatikJVMSize"),
$Config->get("BatikPath"),
$SizeX,
@@ -1576,9 +1577,8 @@
}
elsif ($Config->get("Batik") == "2") # batik as executable (wrapper of some sort, i.e. on gentoo)
{
- $Cmd = sprintf("%s%s \"%s\" -w %d -h %d -a %f,%f,%f,%f -m image/png -d \"%s\" \"%s%s\" > %s",
+ $Cmd = sprintf("%s \"%s\" -w %d -h %d -a %f,%f,%f,%f -m image/png -d \"%s\" \"%s%s\" > %s",
$Config->get("i18n") ? "LC_ALL=C " : "",
- $Config->get("Niceness"),
$Config->get("BatikPath"),
$SizeX,
$SizeY,
@@ -1601,9 +1601,8 @@
}
else
{
- $Cmd = sprintf("%s%s \"%s\" -z -w %d -h %d --export-area=%f:%f:%f:%f --export-png=\"%s\" \"%s%s\" > %s",
+ $Cmd = sprintf("%s \"%s\" -z -w %d -h %d --export-area=%f:%f:%f:%f --export-png=\"%s\" \"%s%s\" > %s",
$Config->get("i18n") ? "LC_ALL=C " : "",
- $Config->get("Niceness"),
$Config->get("Inkscape"),
$SizeX,
$SizeY,
@@ -1855,8 +1854,7 @@
elsif ($Config->get("PngQuantizer") eq "pngnq") {
if ($EnvironmentInfo{"pngnq"})
{
- $Cmd = sprintf("%s \"%s\" -e .png%s -s1 -n256 %s %s",
- $Config->get("Niceness"),
+ $Cmd = sprintf("\"%s\" -e .png%s -s1 -n256 %s %s",
$Config->get("pngnq"),
$Filename2_suffix,
$Filename,
@@ -1886,8 +1884,7 @@
if ($Config->get("PngOptimizer") eq "pngcrush")
{
- $Cmd = sprintf("%s \"%s\" -q %s %s %s",
- $Config->get("Niceness"),
+ $Cmd = sprintf("\"%s\" -q %s %s %s",
$Config->get("Pngcrush"),
$Filename2,
$Filename,
@@ -1895,8 +1892,7 @@
}
elsif ($Config->get("PngOptimizer") eq "optipng")
{
- $Cmd = sprintf("%s \"%s\" %s -out %s %s", #no quiet, because it even suppresses error output
- $Config->get("Niceness"),
+ $Cmd = sprintf("\"%s\" %s -out %s %s", #no quiet, because it even suppresses error output
$Config->get("Optipng"),
$Filename2,
$Filename,
@@ -1993,9 +1989,8 @@
}
statusMessage("Starting BatikAgent\n", $currentSubTask, $progressJobs, $progressPercent,0);
- my $Cmd = sprintf("%s%s java -Xms256M -Xmx%s -cp %s org.tah.batik.ServerMain -p %d > /dev/null&",
+ my $Cmd = sprintf("%s java -Xms256M -Xmx%s -cp %s org.tah.batik.ServerMain -p %d > /dev/null&",
$Config->get("i18n") ? "LC_ALL=C " : "",
- $Config->get("Niceness"),
$Config->get("BatikJVMSize"),
$Config->get("BatikClasspath"),
$Config->get("BatikPort")
Index: tilesAtHome.conf.linux
===================================================================
--- tilesAtHome.conf.linux (revision 9419)
+++ tilesAtHome.conf.linux (working copy)
@@ -7,7 +7,7 @@
WorkingDirectory=/tmp/
Inkscape=inkscape
XmlStarlet=xmlstarlet
-Niceness=nice -n10
+Niceness=10
Pngcrush=pngcrush
Optipng=optipng
Subversion=svn
Index: config.defaults
===================================================================
--- config.defaults (revision 9419)
+++ config.defaults (working copy)
@@ -21,7 +21,7 @@
ProcessLogFile = /tmp/tah.log
WorkingDirectory = tmp/
-Niceness = nice -n10
+Niceness = 10
DownloadTimeout = 1800
KeepDataFile = 0
signature.asc
Description: Digital signature
_______________________________________________ Tilesathome mailing list [email protected] http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/tilesathome
