Memory limitation
This commit is contained in:
parent
7068dd3b61
commit
988ce0587e
5 changed files with 74 additions and 7 deletions
|
@ -10,7 +10,8 @@
|
|||
<attribute name="zoomToLoadTiles" value="16" />
|
||||
<!-- by default it is 30. Value specified here overwrites all others
|
||||
(don't specify here ! it is device dependent) -->
|
||||
<attribute name="memoryLimitInMB" value="155" />
|
||||
<attribute name="memoryLimitInMB" value="" />
|
||||
<attribute name="nativeMemoryLimitInMB" value="75" />
|
||||
|
||||
<!-- 1.2 Build A* graph in backward/forward direction (can affect results) -->
|
||||
<!-- 0 - 2 ways, 1 - direct way, -1 - reverse way -->
|
||||
|
|
|
@ -18,5 +18,6 @@ endif
|
|||
|
||||
ifndef OSMAND_DEBUG_NATIVE
|
||||
# Force release compilation in release optimizations, even if application is debuggable by manifest
|
||||
APP_OPTIM := release
|
||||
#APP_OPTIM := release
|
||||
APP_OPTIM := debug
|
||||
endif
|
|
@ -360,6 +360,8 @@ public class RouteProvider {
|
|||
memoryLimit, specialization);
|
||||
if(!params.optimal){
|
||||
cf.heuristicCoefficient *= 1.5;
|
||||
// native use
|
||||
cf.attributes.put("heuristicCoefficient", cf.heuristicCoefficient+"");
|
||||
}
|
||||
RoutingContext ctx = new RoutingContext(cf, NativeOsmandLibrary.getLoadedLibrary(), files);
|
||||
ctx.interruptable = params.interruptable;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "common.h"
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
#include "binaryRead.h"
|
||||
#include "binaryRoutePlanner.h"
|
||||
#include <functional>
|
||||
|
@ -670,4 +669,8 @@ vector<RouteSegmentResult> searchRouteInternal(RoutingContext* ctx, bool leftSid
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool compareRoutingSubregionTile(SHARED_PTR<RoutingSubregionTile> o1, SHARED_PTR<RoutingSubregionTile> o2){
|
||||
int v1 = (o1->access + 1) * pow((float)10, o1->getUnloadCount() -1);
|
||||
int v2 = (o2->access + 1) * pow((float)10, o2->getUnloadCount() -1);
|
||||
return v1 < v2 ;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _OSMAND_BINARY_ROUTE_PLANNER_H
|
||||
#include "common.h"
|
||||
#include "binaryRead.h"
|
||||
#include <algorithm>
|
||||
|
||||
typedef UNORDERED(map)<string, float> MAP_STR_FLOAT;
|
||||
typedef UNORDERED(map)<string, string> MAP_STR_STR;
|
||||
|
@ -76,7 +77,17 @@ struct RoutingSubregionTile {
|
|||
}
|
||||
|
||||
void setLoaded(){
|
||||
loaded++;
|
||||
loaded = abs(loaded) + 1;
|
||||
}
|
||||
|
||||
void unload(){
|
||||
routes.clear();
|
||||
size = 0;
|
||||
loaded = - abs(loaded);
|
||||
}
|
||||
|
||||
int getUnloadCount() {
|
||||
return abs(loaded);
|
||||
}
|
||||
|
||||
int getSize(){
|
||||
|
@ -170,14 +181,15 @@ struct RoutingConfiguration {
|
|||
minDefaultSpeed = parseFloat("minDefaultSpeed", 45) / 3.6;
|
||||
maxDefaultSpeed = parseFloat("maxDefaultSpeed", 130) / 3.6;
|
||||
heurCoefficient = parseFloat("heuristicCoefficient", 1);
|
||||
memoryLimitation = (int)parseFloat("memoryLimitInMB", memoryLimitation);
|
||||
// don't use file limitations?
|
||||
memoryLimitation = (int)parseFloat("nativeMemoryLimitInMB", memoryLimitation);
|
||||
zoomToLoad = (int)parseFloat("zoomToLoadTiles", 16);
|
||||
routerName = parseString("name", "default");
|
||||
routerProfile = parseString("baseProfile", "car");
|
||||
distanceRecalculate = parseFloat("recalculateDistanceHelp", 10000) ;
|
||||
}
|
||||
|
||||
RoutingConfiguration(vector<ROUTE_TRIPLE>& config, float initDirection = -360, int memLimit = 30) :
|
||||
RoutingConfiguration(vector<ROUTE_TRIPLE>& config, float initDirection = -360, int memLimit = 100) :
|
||||
memoryLimitation(memLimit), initialDirection(initDirection) {
|
||||
for(int j = 0; j<config.size(); j++) {
|
||||
ROUTE_TRIPLE r = config[j];
|
||||
|
@ -348,6 +360,8 @@ struct RoutingConfiguration {
|
|||
|
||||
};
|
||||
|
||||
bool compareRoutingSubregionTile(SHARED_PTR<RoutingSubregionTile> o1, SHARED_PTR<RoutingSubregionTile> o2);
|
||||
|
||||
|
||||
struct RoutingContext {
|
||||
typedef UNORDERED(map)<int64_t, SHARED_PTR<RoutingSubregionTile> > MAP_SUBREGION_TILES;
|
||||
|
@ -360,6 +374,8 @@ struct RoutingContext {
|
|||
int64_t firstRoadId;
|
||||
RoutingConfiguration config;
|
||||
|
||||
int gcCollectIterations;
|
||||
|
||||
int startX;
|
||||
int startY;
|
||||
int endX;
|
||||
|
@ -390,8 +406,52 @@ struct RoutingContext {
|
|||
return sz;
|
||||
}
|
||||
|
||||
void unloadUnusedTiles(int memoryLimit) {
|
||||
int sz = getSize();
|
||||
float critical = 0.9f * memoryLimit * 1024 * 1024;
|
||||
if(sz < critical) {
|
||||
return;
|
||||
}
|
||||
float occupiedBefore = sz / (1024. * 1024.);
|
||||
float desirableSize = memoryLimit * 0.7f * 1024 * 1024;
|
||||
vector<SHARED_PTR<RoutingSubregionTile> > list;
|
||||
MAP_SUBREGION_TILES::iterator it = subregionTiles.begin();
|
||||
int loaded = 0;
|
||||
int unloadedTiles = 0;
|
||||
for(;it != subregionTiles.end(); it++) {
|
||||
if(it->second->isLoaded()) {
|
||||
list.push_back(it->second);
|
||||
loaded++;
|
||||
}
|
||||
}
|
||||
sort(list.begin(), list.end(), compareRoutingSubregionTile);
|
||||
int i =0;
|
||||
while(sz >= desirableSize && i < list.size()) {
|
||||
SHARED_PTR<RoutingSubregionTile> unload = list[i];
|
||||
i++;
|
||||
sz -= unload->getSize();
|
||||
unload->unload();
|
||||
unloadedTiles ++;
|
||||
}
|
||||
for(i = 0; i<list.size(); i++) {
|
||||
list[i]->access /= 3;
|
||||
}
|
||||
osmand_log_print(LOG_DEBUG, "Run GC (before %f Mb after %f Mb) unload %d of %d tiles",
|
||||
occupiedBefore, getSize() / (1024.0*1024.0),
|
||||
unloadedTiles, loaded);
|
||||
}
|
||||
|
||||
void loadHeaderObjects(int64_t tileId) {
|
||||
vector<SHARED_PTR<RoutingSubregionTile> > subregions = indexedSubregions[tileId];
|
||||
bool gc = false;
|
||||
for(int j = 0; j<subregions.size() && !gc; j++) {
|
||||
if(!subregions[j]->isLoaded()) {
|
||||
gc = true;
|
||||
}
|
||||
}
|
||||
if(gc) {
|
||||
unloadUnusedTiles(config.memoryLimitation);
|
||||
}
|
||||
for(int j = 0; j<subregions.size(); j++) {
|
||||
if(!subregions[j]->isLoaded()) {
|
||||
loadedTiles++;
|
||||
|
|
Loading…
Reference in a new issue