diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index 4b887bb..ba497d2 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -782,7 +782,7 @@ public class RoutingEngine extends Thread addToOpenset( startPath1 ); addToOpenset( startPath2 ); } - ArrayList openBorderList = new ArrayList(); + ArrayList openBorderList = new ArrayList(4096); boolean memoryPanicMode = false; boolean needNonPanicProcessing = false; @@ -793,8 +793,6 @@ public class RoutingEngine extends Thread throw new IllegalArgumentException( "operation killed by thread-priority-watchdog after " + ( System.currentTimeMillis() - startTime)/1000 + " seconds" ); } - - if ( maxRunningTime > 0 ) { long timeout = ( matchPath == null && fastPartialRecalc ) ? maxRunningTime/3 : maxRunningTime; @@ -803,11 +801,11 @@ public class RoutingEngine extends Thread throw new IllegalArgumentException( operationName + " timeout after " + (timeout/1000) + " seconds" ); } } - OsmPath path = null; - synchronized( openSet ) - { - path = openSet.popLowestKeyValue(); + synchronized( openSet ) + { + + OsmPath path = openSet.popLowestKeyValue(); if ( path == null ) { if ( openBorderList.isEmpty() ) @@ -823,7 +821,6 @@ public class RoutingEngine extends Thread needNonPanicProcessing = true; continue; } - } if ( path.airdistance == -1 ) { @@ -835,14 +832,13 @@ public class RoutingEngine extends Thread { if ( !memoryPanicMode ) { - if ( !nodesCache.nodesMap.isInMemoryBounds( openSet.getSize() ) ) + if ( !nodesCache.nodesMap.isInMemoryBounds( openSet.getSize(), false ) ) { +// System.out.println( "collecting..." ); int nodesBefore = nodesCache.nodesMap.nodesCreated; int pathsBefore = openSet.getSize(); nodesCache.nodesMap.collectOutreachers(); - synchronized( openSet ) - { for(;;) { OsmPath p3 = openSet.popLowestKeyValue(); @@ -852,14 +848,14 @@ public class RoutingEngine extends Thread openBorderList.add( p3 ); } } + nodesCache.nodesMap.clearTemp(); for( OsmPath p : openBorderList ) { openSet.add( p.cost + (int)(p.airdistance*airDistanceCostFactor), p ); } - } openBorderList.clear(); logInfo( "collected, nodes/paths before=" + nodesBefore + "/" + pathsBefore + " after=" + nodesCache.nodesMap.nodesCreated + "/" + openSet.getSize() + " maxTotalCost=" + maxTotalCost ); - if ( !nodesCache.nodesMap.isInMemoryBounds( openSet.getSize()) ) // TODO + if ( !nodesCache.nodesMap.isInMemoryBounds( openSet.getSize(), true ) ) { if ( maxTotalCost < 1000000000 || needNonPanicProcessing || fastPartialRecalc ) { @@ -1133,16 +1129,14 @@ public class RoutingEngine extends Thread } bestPath.treedepth = path.treedepth + 1; link.addLinkHolder( bestPath, currentNode ); - synchronized( openSet ) - { - addToOpenset( bestPath ); - } + addToOpenset( bestPath ); } } } } path.unregisterUpTree( routingContext ); + } } if ( nodesVisited < MAXNODES_ISLAND_CHECK && islandNodePairs.getFreezeCount() < 5 ) diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNodesMap.java b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNodesMap.java index 4a9360f..4ffb103 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNodesMap.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/OsmNodesMap.java @@ -21,6 +21,7 @@ public final class OsmNodesMap public int nodesCreated; public long maxmem; + private long currentmaxmem = 4000000; // start with 4 MB public int lastVisitID = 1000; public int baseID = 1000; @@ -127,11 +128,27 @@ public final class OsmNodesMap - public boolean isInMemoryBounds( int npaths ) + public boolean isInMemoryBounds( int npaths, boolean extend ) { // long total = nodesCreated * 76L + linksCreated * 48L; long total = nodesCreated * 95L + npaths * 200L; - return total <= maxmem; + + if ( extend ) + { + total += 100000; + + // when extending, try to have 1 MB space + long delta = total + 1900000 - currentmaxmem; + if ( delta > 0 ) + { + currentmaxmem += delta; + if ( currentmaxmem > maxmem ) + { + currentmaxmem = maxmem; + } + } + } + return total <= currentmaxmem; } private void addActiveNode( ArrayList nodes2check, OsmNode n ) @@ -147,7 +164,7 @@ public final class OsmNodesMap { boolean sawLowIDs = false; lastVisitID++; - ArrayList nodes2check = new ArrayList(); + nodes2check.clear(); nodes2check.add( n0 ); while ( !nodes2check.isEmpty() ) { @@ -191,12 +208,18 @@ public final class OsmNodesMap return false; } + + private ArrayList nodes2check; + public void clearTemp() + { + nodes2check = null; + } + public void collectOutreachers() { + nodes2check = new ArrayList(nodesCreated); nodesCreated=0; - - ArrayList nodes2check = new ArrayList(); for( OsmNode n : hmap.values() ) { addActiveNode( nodes2check, n ); diff --git a/brouter-server/src/main/java/btools/server/BRouter.java b/brouter-server/src/main/java/btools/server/BRouter.java index 33a96b3..299f361 100644 --- a/brouter-server/src/main/java/btools/server/BRouter.java +++ b/brouter-server/src/main/java/btools/server/BRouter.java @@ -127,7 +127,6 @@ public class BRouter { wplist.add( readPosition( args, 3, "to" ) ); RoutingContext rc = readRoutingContext(args); - rc.memoryclass = 16; re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc ); re.doRun( 0 );