]> git.openstreetmap.org Git - nominatim.git/commitdiff
set osm2pgsql cache memory to a default based on memory in the machine
authorBrian Quinion <openstreetmap@brian.quinion.co.uk>
Thu, 26 Apr 2012 00:35:06 +0000 (01:35 +0100)
committerBrian Quinion <openstreetmap@brian.quinion.co.uk>
Thu, 26 Apr 2012 00:35:06 +0000 (01:35 +0100)
lib/lib.php
utils/setup.php

index 1564a83cceffa45dc4a1f65ef29cce3d87cb0608..889cb2cff3fe92f80624d7bccbc2f981f4405d59 100644 (file)
                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)
        {
                if ($a['iSearchRank'] == $b['iSearchRank']) return 0;
index d7aa3bc7be97cc0ff4bf7dcc2eed6bb4f5354db8..6415ea123d843358165029d638a2aadb6eab0a31 100755 (executable)
                $iInstances = getProcessorCount();
                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']))
        {
                $sBaseFile = basename($aCMDResult['osm-file']);
@@ -83,7 +92,7 @@
 
                $oDB =& getDB();
                passthru('createlang plpgsql '.$aDSNInfo['database']);
-        $pgver = (float) CONST_Postgresql_Version;
+               $pgver = (float) CONST_Postgresql_Version;
                if ($pgver < 9.1) {
                        pgsqlRunScriptFile(CONST_Path_Postgresql_Contrib.'/hstore.sql');
                } else {
                $osm2pgsql = CONST_Osm2pgsql_Binary;
                if (!file_exists($osm2pgsql)) fail("please download and build osm2pgsql");
                $osm2pgsql .= ' -lsc -O gazetteer --hstore';
-               if (isset($aCMDResult['osm2pgsql-cache']))
-               {
-                       $osm2pgsql .= ' -C '.$aCMDResult['osm2pgsql-cache'];
-               }
-               else
-               {
-                       $osm2pgsql .= ' -C 15000';
-               }
+               $osm2pgsql .= ' -C '.$iCacheMemory;
                $osm2pgsql .= ' -d '.$aDSNInfo['database'].' '.$aCMDResult['osm-file'];
                passthru($osm2pgsql);