Skip to content

MMAP load config - #2432

Closed
karussell wants to merge 4 commits into
masterfrom
mmap_load
Closed

karussell wants to merge 4 commits into
masterfrom
mmap_load

Conversation

@karussell

@karussell karussell commented Oct 13, 2021 •

Copy link
Copy Markdown
Member

Fixes #2416.

These new MMAP config options shall help to get cold query times similar to the case when the RAM option is used. They however do not help to warm up the JVM (JIT compiler). I.e. the first query will be still much slower than follow up queries but the difference should be reduced.

I tested this configuration on a rather slow Intel Xeon E5-1650V3 but with 256GB physical memory and an SSD disk.
Using a configuration with several edge-based CH custom profiles (no LM) leading to a graph of 247GB including a 39GB base graph plus 2.6GB location index and 8 CH profiles.

For java I used -Xmx140g -Xms140s (and ZGC) and the MMAP config option for GraphHopper.

Not really scientific measurements as I only repeated some numbers twice but as the values were very reproducible this should be fine (I ran sudo sysctl vm.drop_caches=3 after I stopped the JVM after every measurement to avoid cache effects).

The query was a 3000km route against car with avoid motorway and only the first response time was used. (The response time of the second query was then always below 0.35s.)

config response time (seconds) server start (seconds)
all options set to 0% 39 15
all 0% except graph.dataaccess.base.load: 100 13 94
all 0% except graph.dataaccess.index.load: 100 38 21
all 0% except graph.dataaccess.ch.load: 100 38 455
all 100% 39 537
all 80% (~198g) 38 430
all 50% (~124g) 30 277
base=100 and ch=50 (index=0) (~142g) 30 316
base=100 and ch=30 (index=0) (~101g) 7 225
base=100 and ch=20 (index=0) (~80g) 8.5 181
base=100 and ch=20 and index=100 (~83g) 8.5 186
RAM instead of MMAP (does not load with Xmx248g to Xmx252)

The results are interesting. Especially when we try to load everything. This seems to have minimal or even no effect on the route response time although the startup time can suffer a lot. Which very likely that the required data for the route is already removed from physical memory before we can use it as the memory pressure is high when mostly everything is loaded (keep in mind the available off-heap memory is smaller than 116g=256g-140g).

Comment on lines +490 to +491
// only relevant if MMAP is used
mmapLoadConfig = new MMapLoadConfig(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only relevant for mmap shall we include 'mmap' in the config parameter names?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@easbar

easbar commented Oct 14, 2021

Copy link
Copy Markdown
Member

They however do not help to warm up the JVM (JIT compiler). I.e. the first query will be still much slower than follow up queries but the difference should be reduced.

So maybe it would be better to simply run a few queries instead?

@karussell

Copy link
Copy Markdown
Member Author

So maybe it would be better to simply run a few queries instead?

We could query with some random requests but they might fail due to connection not found or point not found. Or we implement a special endpoint that has access to the graph directly.

And so I think preloading the entire base graph can be a simple step to reduce the delay at startup . Also it can be seen as a step to further reduce the initial delay.

(To reduce this further we could sort the DataAccess for all CHs and if we specify load=20%, then 20% of the especially important edges will be loaded.)

@karussell karussell closed this Oct 14, 2021
@karussell karussell reopened this Oct 14, 2021
@easbar

easbar commented Oct 14, 2021 •

Copy link
Copy Markdown
Member

We could query with some random requests but they might fail due to connection not found or point not found.

But what is the problem with failing requests? You could just keep sending random requests until a certain amount was successful. And usually you should know what data was imported and so it shouldn't be hard to send requests that work? Or is it crucial to use requests that actually load a large part of the graph? For JIT warmup this probably does not matter?

Or we implement a special endpoint that has access to the graph directly.

But then we still need this new API internally (and even expose it via http)

And so I think preloading the entire base graph can be a simple step to reduce the delay at startup . Also it can be seen as a step to further reduce the initial delay.

Ok, but pre-loading the base graph takes time as well according to your table?

(To reduce this further we could sort the DataAccess for all CHs and if we specify load=20%, then 20% of the especially important edges will be loaded.)

The CH edges are already sorted by the level of the lower-level nodes.

@karussell

Copy link
Copy Markdown
Member Author

Or is it crucial to use requests that actually load a large part of the graph?

Yes, I think this would be required to have the same effect like mmap.load but have not tried it.

For JIT warmup this probably does not matter?

Yes, that is the reason I would combine them: load the base graph into memory (to avoid loading geometry, names, nodes while the first queries in a certain area) and use a few requests to warm up the JIT in general.

E.g. think about a large graphhopper instance like worldwide with fresh data included in a load balanced setup and you do not know which areas are used but you do not have enough memory to use RAM_STORE but still want a best effort to reduce the maximum response time.

The CH edges are already sorted by the level of the lower-level nodes.

Ah, really nice, then the most likely used edges would be already loaded into physical memory :) (?)

Ok, but pre-loading the base graph takes time as well according to your table?

Sorry, what I meant with "initial delay" is the slowdown of the first requests if no mmap.load is used. And this slowdown is significantly reduced.

@easbar

easbar commented Oct 14, 2021

Copy link
Copy Markdown
Member

Ah, really nice, then the most likely used edges would be already loaded into physical memory :) (?)

This depends on the query. Typical CH queries use only a few dozens or maybe hundreds of shortcuts (out of hundreds of millions for planet), some of which are on lower levels and some of which are on higher levels. It might be even more useful to just load some random segments (just guessing here).

@karussell

karussell commented Oct 15, 2021 •

Copy link
Copy Markdown
Member Author

I created a more generic solution: https://github.com/graphhopper/graphhopper/compare/mmap_config

The configuration is a bit more verbose but now you can change the type and preload percentage for every single DataAccess:

graphhopper:

  graph.dataaccess.shortcuts_mycar: MMAP;30
  graph.dataaccess.nodes_ch_mycar: MMAP;30
  graph.dataaccess.shortcuts_car_rarely_used: MMAP;0
  graph.dataaccess.nodes_ch_car_rarely_used: MMAP;0

  # the default type:
  graph.dataaccess: RAM_STORE
  # so all other DataAccess objects like nodes, edges, geometry, location_index, string_index_keys, string_index_vals of the base graph get this default type

With this I got:

config response time (seconds) server start (seconds)
all RAM, except the CHs with MMAP + 30% preload and base graph with MMAP + 100% preload 7 233
all RAM, except the CHs with MMAP + 30% preload 7 270

So it seems that MMAP preloading results in faster startup times.

Then I compared the query times in cache-cold areas for MMAP 0% vs. the best MMAP config (base 100% preload + CH 30% preload). The method I used was: I picked warmup queries in Europa, Africa, Asia and North America and then queried (1) in South America and orthogonal (2) in SA.

config warmup queries then (1) and (2)
MMAP 0% EU 41s, Africa 14s, Asia 12s, North America 24s (1) 12s, (2) 12s
MMAP 0% (changed order) Asia 17s, Africa 16s, EU 35s, North America 24s (2) 13s (1) 10s
MMAP base 100% preload + CH 30% EU 8s, Africa 3.7s, Asia 2.9s, North America 5.6s (1) 3s, (2) 3.1s
MMAP base 100% preload + CH 30% (changed order) Asia 4.2, Africa 3.9, EU 6s, North America 5.5s (2) 3.3s (1) 2.6s

Note, the numbers are interestingly always reproducible. Clearing the memory was required after a restart (as above).

The response time of (1) after 10x (1) was always 0.12 seconds.

So the "warming" with random example queries seems to improve neighboring areas a bit but likely thousands of random requests would be required for the world wide setup to reduce the initial slowdown in a broad area like MMAP preloading does.

@easbar

easbar commented Oct 17, 2021

Copy link
Copy Markdown
Member

So the "warming" with random example queries seems to be improve neighboring areas a bit but likely thousands of random requests would be required for the world wide setup to reduce the initial slowdown in a broad area like MMAP preloading does.

Ok, a thousand (CH?) queries does not sound so bad, but I can imagine that it is hard to cover a sufficient amount of the graph storage by running random queries. So let's use the extended configuration options in your new branch?

@karussell

Copy link
Copy Markdown
Member Author

Ok, a thousand (CH?) queries does not sound so bad, but I can imagine that it is hard to cover a sufficient amount of the graph storage by running random queries.

Yes

So let's use the extended configuration options in your new branch?

Ok, will create a new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When using MMAP provide an option to force load the graph

2 participants