modified memory behaviour (use up to memoryclass only when neccessary)
This commit is contained in:
parent
2213d4f7fc
commit
80e36d4bb5
3 changed files with 39 additions and 23 deletions
|
@ -782,7 +782,7 @@ public class RoutingEngine extends Thread
|
||||||
addToOpenset( startPath1 );
|
addToOpenset( startPath1 );
|
||||||
addToOpenset( startPath2 );
|
addToOpenset( startPath2 );
|
||||||
}
|
}
|
||||||
ArrayList<OsmPath> openBorderList = new ArrayList<OsmPath>();
|
ArrayList<OsmPath> openBorderList = new ArrayList<OsmPath>(4096);
|
||||||
boolean memoryPanicMode = false;
|
boolean memoryPanicMode = false;
|
||||||
boolean needNonPanicProcessing = 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" );
|
throw new IllegalArgumentException( "operation killed by thread-priority-watchdog after " + ( System.currentTimeMillis() - startTime)/1000 + " seconds" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( maxRunningTime > 0 )
|
if ( maxRunningTime > 0 )
|
||||||
{
|
{
|
||||||
long timeout = ( matchPath == null && fastPartialRecalc ) ? maxRunningTime/3 : maxRunningTime;
|
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" );
|
throw new IllegalArgumentException( operationName + " timeout after " + (timeout/1000) + " seconds" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OsmPath path = null;
|
|
||||||
|
|
||||||
synchronized( openSet )
|
synchronized( openSet )
|
||||||
{
|
{
|
||||||
path = openSet.popLowestKeyValue();
|
|
||||||
|
OsmPath path = openSet.popLowestKeyValue();
|
||||||
if ( path == null )
|
if ( path == null )
|
||||||
{
|
{
|
||||||
if ( openBorderList.isEmpty() )
|
if ( openBorderList.isEmpty() )
|
||||||
|
@ -823,7 +821,6 @@ public class RoutingEngine extends Thread
|
||||||
needNonPanicProcessing = true;
|
needNonPanicProcessing = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ( path.airdistance == -1 )
|
if ( path.airdistance == -1 )
|
||||||
{
|
{
|
||||||
|
@ -835,14 +832,13 @@ public class RoutingEngine extends Thread
|
||||||
{
|
{
|
||||||
if ( !memoryPanicMode )
|
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 nodesBefore = nodesCache.nodesMap.nodesCreated;
|
||||||
int pathsBefore = openSet.getSize();
|
int pathsBefore = openSet.getSize();
|
||||||
|
|
||||||
nodesCache.nodesMap.collectOutreachers();
|
nodesCache.nodesMap.collectOutreachers();
|
||||||
synchronized( openSet )
|
|
||||||
{
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
OsmPath p3 = openSet.popLowestKeyValue();
|
OsmPath p3 = openSet.popLowestKeyValue();
|
||||||
|
@ -852,14 +848,14 @@ public class RoutingEngine extends Thread
|
||||||
openBorderList.add( p3 );
|
openBorderList.add( p3 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
nodesCache.nodesMap.clearTemp();
|
||||||
for( OsmPath p : openBorderList )
|
for( OsmPath p : openBorderList )
|
||||||
{
|
{
|
||||||
openSet.add( p.cost + (int)(p.airdistance*airDistanceCostFactor), p );
|
openSet.add( p.cost + (int)(p.airdistance*airDistanceCostFactor), p );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
openBorderList.clear();
|
openBorderList.clear();
|
||||||
logInfo( "collected, nodes/paths before=" + nodesBefore + "/" + pathsBefore + " after=" + nodesCache.nodesMap.nodesCreated + "/" + openSet.getSize() + " maxTotalCost=" + maxTotalCost );
|
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 )
|
if ( maxTotalCost < 1000000000 || needNonPanicProcessing || fastPartialRecalc )
|
||||||
{
|
{
|
||||||
|
@ -1133,17 +1129,15 @@ public class RoutingEngine extends Thread
|
||||||
}
|
}
|
||||||
bestPath.treedepth = path.treedepth + 1;
|
bestPath.treedepth = path.treedepth + 1;
|
||||||
link.addLinkHolder( bestPath, currentNode );
|
link.addLinkHolder( bestPath, currentNode );
|
||||||
synchronized( openSet )
|
|
||||||
{
|
|
||||||
addToOpenset( bestPath );
|
addToOpenset( bestPath );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
path.unregisterUpTree( routingContext );
|
path.unregisterUpTree( routingContext );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( nodesVisited < MAXNODES_ISLAND_CHECK && islandNodePairs.getFreezeCount() < 5 )
|
if ( nodesVisited < MAXNODES_ISLAND_CHECK && islandNodePairs.getFreezeCount() < 5 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,7 @@ public final class OsmNodesMap
|
||||||
|
|
||||||
public int nodesCreated;
|
public int nodesCreated;
|
||||||
public long maxmem;
|
public long maxmem;
|
||||||
|
private long currentmaxmem = 4000000; // start with 4 MB
|
||||||
public int lastVisitID = 1000;
|
public int lastVisitID = 1000;
|
||||||
public int baseID = 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 * 76L + linksCreated * 48L;
|
||||||
long total = nodesCreated * 95L + npaths * 200L;
|
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 )
|
private void addActiveNode( ArrayList<OsmNode> nodes2check, OsmNode n )
|
||||||
|
@ -147,7 +164,7 @@ public final class OsmNodesMap
|
||||||
{
|
{
|
||||||
boolean sawLowIDs = false;
|
boolean sawLowIDs = false;
|
||||||
lastVisitID++;
|
lastVisitID++;
|
||||||
ArrayList<OsmNode> nodes2check = new ArrayList<OsmNode>();
|
nodes2check.clear();
|
||||||
nodes2check.add( n0 );
|
nodes2check.add( n0 );
|
||||||
while ( !nodes2check.isEmpty() )
|
while ( !nodes2check.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -192,11 +209,17 @@ public final class OsmNodesMap
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArrayList<OsmNode> nodes2check;
|
||||||
|
|
||||||
|
public void clearTemp()
|
||||||
|
{
|
||||||
|
nodes2check = null;
|
||||||
|
}
|
||||||
|
|
||||||
public void collectOutreachers()
|
public void collectOutreachers()
|
||||||
{
|
{
|
||||||
|
nodes2check = new ArrayList<OsmNode>(nodesCreated);
|
||||||
nodesCreated=0;
|
nodesCreated=0;
|
||||||
|
|
||||||
ArrayList<OsmNode> nodes2check = new ArrayList<OsmNode>();
|
|
||||||
for( OsmNode n : hmap.values() )
|
for( OsmNode n : hmap.values() )
|
||||||
{
|
{
|
||||||
addActiveNode( nodes2check, n );
|
addActiveNode( nodes2check, n );
|
||||||
|
|
|
@ -127,7 +127,6 @@ public class BRouter
|
||||||
{
|
{
|
||||||
wplist.add( readPosition( args, 3, "to" ) );
|
wplist.add( readPosition( args, 3, "to" ) );
|
||||||
RoutingContext rc = readRoutingContext(args);
|
RoutingContext rc = readRoutingContext(args);
|
||||||
rc.memoryclass = 16;
|
|
||||||
re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
|
re = new RoutingEngine( "mytrack", "mylog", args[0], wplist, rc );
|
||||||
re.doRun( 0 );
|
re.doRun( 0 );
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue