OutOfMemoryError when starting Server

I am trying to set up Graphhopper following the Quickstart Guide on GitHub. When trying to launch the application using the germany-latest.osm.pbf, I get an OutOfMemoryError after some time.

~/apps/graphhopper$java -jar *.jar jetty.resourcebase=webapp config=config-example.properties osmreader.osm=germany-latest.osm.pbf

2016-01-12 11:06:13,288 [main] INFO  com.graphhopper.GraphHopper - version 0.5.0|2015-08-12T12:33:51+0000 (4,12,3,2,2,1)
2016-01-12 11:06:13,345 [main] INFO  com.graphhopper.GraphHopper - graph CH|car|RAM_STORE|2D|NoExt|,,,,, details:edges:0(0MB), nodes:0(0MB), name:(0MB), geo:0(0MB), bounds:1.7976931348623157E308,-1.7976931348623157E308,1.7976931348623157E308,-1.7976931348623157E308, CHGraph|FASTEST|car, shortcuts:0, nodesCH:(0MB)
2016-01-12 11:06:13,389 [main] INFO  com.graphhopper.GraphHopper - start creating graph from germany-latest.osm.pbf
2016-01-12 11:06:13,396 [main] INFO  com.graphhopper.GraphHopper - using CH|car|RAM_STORE|2D|NoExt|,,,,, memory:totalMB:15, usedMB:4
Exception in thread "pool-1-thread-2" Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space
	at java.util.HashMap.resize(HashMap.java:703)
	at java.util.HashMap.putVal(HashMap.java:662)
	at java.util.HashMap.put(HashMap.java:611)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.buildTags(PbfBlobDecoder.java:146)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.processWays(PbfBlobDecoder.java:272)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.processOsmPrimitives(PbfBlobDecoder.java:370)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.runAndTrapExceptions(PbfBlobDecoder.java:386)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.run(PbfBlobDecoder.java:404)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
java.lang.OutOfMemoryError: Java heap space
	at java.util.ArrayList.iterator(ArrayList.java:834)
	at java.util.Collections$UnmodifiableCollection$1.<init>(Collections.java:1039)
	at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1038)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.buildTags(PbfBlobDecoder.java:138)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.processWays(PbfBlobDecoder.java:272)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.processOsmPrimitives(PbfBlobDecoder.java:370)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.runAndTrapExceptions(PbfBlobDecoder.java:386)
	at com.graphhopper.reader.pbf.PbfBlobDecoder.run(PbfBlobDecoder.java:404)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)

I only have 1gb of RAM on the Server. So now my question: Is increasing the RAM on the server the only way to set up Graphhopper with the German map or is there a different way of doing it?

Thanks for your help!

1 Like

The Stacktrace tells me that you only have 15mb of RAM. 1GB should be enough for Germany (if I remember correctly). You could try with a Subregion of Germany.

Hm yes you’re right. But not really sure how to read/interpret that correctly. It seems like the java app allocates that amount of RAM. Is there a way to manually increase that?

By default a lot more RAM should be assigned to the JVM. Increase this e.g. via
export JAVA_OPTS="-Xmx500m -Xms500m"
before calling the graphhopper.sh script or in your case do
java -Xmx500m -Xms500m ...

1 Like

Thanks for the suggestion. I tried your suggestion and it increased the assigned RAM, but after some time I got the same error. I am trying to extract the germany-latest.osm.pbf, which is about 2.6gb big. Do you think my overall RAM is insufficient for this kind of map?

2016-01-12 17:59:09,900 [main] INFO  com.graphhopper.GraphHopper - using CH|car|RAM_STORE|2D|NoExt|,,,,, memory:totalMB:483, usedMB:27
2016-01-12 18:16:13,934 [main] INFO  com.graphhopper.reader.OSMReader - 5 000 000 (preprocess), osmIdMap:31 742 427 (420MB) totalMB:483, usedMB:445
Exception in thread "pool-1-thread-2" Exception in thread "pool-1-thread-1" java.lang.OutOfMemoryError: Java heap space

with default config (CH enabled) you’ll probably need ~2500mb for the import and 1500mb for running it (at least that were the numbers I have in mind for DE when I tried it the last time). But just try yourself :slight_smile:
BTW: are you running a 64bit system?

1 Like

I ended up increasing the RAM of the server. 3000mb was sufficient for the German map.
Thanks for the help!

This topic was automatically closed after 12 days. New replies are no longer allowed.