modified memory behaviour (use up to memoryclass only when neccessary)

This commit is contained in:
Arndt Brenschede 2019-07-20 10:24:00 +02:00
parent 2213d4f7fc
commit 80e36d4bb5
3 changed files with 39 additions and 23 deletions

View file

@ -782,7 +782,7 @@ public class RoutingEngine extends Thread
addToOpenset( startPath1 );
addToOpenset( startPath2 );
}
ArrayList<OsmPath> openBorderList = new ArrayList<OsmPath>();
ArrayList<OsmPath> openBorderList = new ArrayList<OsmPath>(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 )

View file

@ -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<OsmNode> nodes2check, OsmNode n )
@ -147,7 +164,7 @@ public final class OsmNodesMap
{
boolean sawLowIDs = false;
lastVisitID++;
ArrayList<OsmNode> nodes2check = new ArrayList<OsmNode>();
nodes2check.clear();
nodes2check.add( n0 );
while ( !nodes2check.isEmpty() )
{
@ -192,11 +209,17 @@ public final class OsmNodesMap
return false;
}
private ArrayList<OsmNode> nodes2check;
public void clearTemp()
{
nodes2check = null;
}
public void collectOutreachers()
{
nodes2check = new ArrayList<OsmNode>(nodesCreated);
nodesCreated=0;
ArrayList<OsmNode> nodes2check = new ArrayList<OsmNode>();
for( OsmNode n : hmap.values() )
{
addActiveNode( nodes2check, n );

View file

@ -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 );