forked from hans/Nominatim
set osm2pgsql cache memory to a default based on memory in the machine
This commit is contained in:
14
lib/lib.php
14
lib/lib.php
@@ -57,6 +57,20 @@
|
|||||||
return sizeof($aMatches[0]);
|
return sizeof($aMatches[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getTotalMemoryMB()
|
||||||
|
{
|
||||||
|
$sCPU = file_get_contents('/proc/meminfo');
|
||||||
|
preg_match('#MemTotal: +([0-9]+) kB#', $sCPU, $aMatches);
|
||||||
|
return (int)($aMatches[1]/1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCacheMemoryMB()
|
||||||
|
{
|
||||||
|
$sCPU = file_get_contents('/proc/meminfo');
|
||||||
|
preg_match('#Cached: +([0-9]+) kB#', $sCPU, $aMatches);
|
||||||
|
return (int)($aMatches[1]/1024);
|
||||||
|
}
|
||||||
|
|
||||||
function bySearchRank($a, $b)
|
function bySearchRank($a, $b)
|
||||||
{
|
{
|
||||||
if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
|
if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
|
||||||
|
|||||||
@@ -50,6 +50,15 @@
|
|||||||
$iInstances = getProcessorCount();
|
$iInstances = getProcessorCount();
|
||||||
echo "WARNING: resetting threads to $iInstances\n";
|
echo "WARNING: resetting threads to $iInstances\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Assume we can steal all the cache memory in the box (unless told otherwise)
|
||||||
|
$iCacheMemory = (isset($aCMDResult['osm2pgsql-cache'])?$aCMDResult['osm2pgsql-cache']:getCacheMemoryMB());
|
||||||
|
if ($iCacheMemory > getTotalMemoryMB())
|
||||||
|
{
|
||||||
|
$iCacheMemory = getCacheMemoryMB();
|
||||||
|
echo "WARNING: resetting cache memory to $iCacheMemory\n";
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($aCMDResult['osm-file']) && !isset($aCMDResult['osmosis-init-date']))
|
if (isset($aCMDResult['osm-file']) && !isset($aCMDResult['osmosis-init-date']))
|
||||||
{
|
{
|
||||||
$sBaseFile = basename($aCMDResult['osm-file']);
|
$sBaseFile = basename($aCMDResult['osm-file']);
|
||||||
@@ -83,7 +92,7 @@
|
|||||||
|
|
||||||
$oDB =& getDB();
|
$oDB =& getDB();
|
||||||
passthru('createlang plpgsql '.$aDSNInfo['database']);
|
passthru('createlang plpgsql '.$aDSNInfo['database']);
|
||||||
$pgver = (float) CONST_Postgresql_Version;
|
$pgver = (float) CONST_Postgresql_Version;
|
||||||
if ($pgver < 9.1) {
|
if ($pgver < 9.1) {
|
||||||
pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
|
pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
|
||||||
} else {
|
} else {
|
||||||
@@ -109,14 +118,7 @@
|
|||||||
$osm2pgsql = CONST_Osm2pgsql_Binary;
|
$osm2pgsql = CONST_Osm2pgsql_Binary;
|
||||||
if (!file_exists($osm2pgsql)) fail("please download and build osm2pgsql");
|
if (!file_exists($osm2pgsql)) fail("please download and build osm2pgsql");
|
||||||
$osm2pgsql .= ' -lsc -O gazetteer --hstore';
|
$osm2pgsql .= ' -lsc -O gazetteer --hstore';
|
||||||
if (isset($aCMDResult['osm2pgsql-cache']))
|
$osm2pgsql .= ' -C '.$iCacheMemory;
|
||||||
{
|
|
||||||
$osm2pgsql .= ' -C '.$aCMDResult['osm2pgsql-cache'];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$osm2pgsql .= ' -C 15000';
|
|
||||||
}
|
|
||||||
$osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
|
$osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
|
||||||
passthru($osm2pgsql);
|
passthru($osm2pgsql);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user