Skip to content

Speed up edge-based CH preparation. #1565

Closed

Description

@easbar

Goal would be to make it practical to use it for continental sized maps like Europe.

(See also #1810)

Activity

  1. easbar commented on Mar 19, 2019

    @easbar
    MemberAuthor

    I ran the measurement on europe-140101.osm.pbf using Xmx/s29g (and car|fastest profile)

    map num nodes num edges num shortcuts preparation time average query time
    Germany 7.079.980 9.077.508 24.157.642 2.5h 26ms
    Europe 38.307.787 (x5.4) 49.581.134 (x5.5) 139.610.530 (x5.8) 10.4h (x4.2) 42ms (x1.6)

    The table also shows the relative increase of the different measures from Germany to Europe.
    The scaling behavior is quite nice, although the size of the graph is about x5.5 the queries are only x1.6 slower and also the import time increases less than proportional with the size of the graph.

    These results are different to the ones reported in the forum here (5days import time), but in the case of the forum it seems like two profiles were imported (fastest and shortest). I haven't checked the import time using the shortest weighting yet, but generally CH does not work as well with the shortest weighting (because the graph is less hierarchichal).

    Update: I also added the number of shortcuts, it seems to scale more or less proportional with the size of the graph.

  2. karussell commented on Mar 19, 2019

    @karussell
    Member

    This sounds nice - thanks!

    Do you also have the info regarding node based routing? Like preparation time and query time. Just for comparison on that hardware.

  3. easbar commented on Mar 19, 2019

    @easbar
    MemberAuthor

    Do you also have the info regarding node based routing?

    Will post once I have it.

  4. easbar commented on Mar 21, 2019

    @easbar
    MemberAuthor

    Here is the same measurement for node-based CH (no turn restrictions)

    map num nodes num edges num shortcuts preparation time average query time
    Germany 7.079.980 9.077.508 5.660.979 12min 3ms
    Europe 38.307.787 (x5.4) 49.581.134 (x5.5) 35.561.021 (x6.3) 1h12min (x6) 10ms (x3.3)

    For Europe the preparation for node-based is about 8.7x faster and the queries about 4x faster than for edge-based. The number of shortcuts is about x4 as high for edge-based.

  5. easbar commented on Mar 21, 2019

    @easbar
    MemberAuthor

    I think x4 shortcuts and query time is quite reasonable, but what probably could and should be improved is the preparation time. But also note that for Germany the differences are more extreme.

  6. karussell commented on Mar 21, 2019

    @karussell
    Member

    Thanks a lot!

    I think x4 shortcuts and query time is quite reasonable

    Indeed, sounds good :)

  7. easbar commented on Mar 28, 2019

    @easbar
    MemberAuthor

    I ran the import for europe with the shortest weighting. The factors show the relation to the values I obtained with the fastest weighting above. The number of shortcuts increases by about 20-30% (for node&edge-based), and the import time increases drastically (x3.2/x4.6), two days for edge-based. Unfortunately I did not get the query times, because the Measurement class uses hard-coded fastest weighting.

    map num nodes num edges num shortcuts preparation time
    Europe (node-based) 38.307.787 49.581.134 44.899.152 (x1.3) 3.8h (x3.2)
    Europe (edge-based) 38.307.787 49.581.134 169.740.507 (x1.2) 48.2h (x4.6)
  8. HendrikLeuschner commented on May 29, 2019

    @HendrikLeuschner

    Hey @easbar , we are interested in using the edge-based CH for our new algorithm, but especially the number of additional shortcuts and preparation time look like a strain on the servers. Do you have any upcoming ideas or projects for significant improvements? If help is required, we can take a look into the code too.
    Cheers

  9. easbar commented on May 29, 2019

    @easbar
    MemberAuthor

    This is something that is certainly in the pipeline for the near future yes. The easiest way to try and change things is playing with the parameters (periodic/lazy/neighbor updates) here (or via corresponding properties flags):

    static Params forTraversalMode(TraversalMode traversalMode) {
    if (traversalMode.isEdgeBased()) {
    // todo: optimize
    return new Params(0, 100, 0, 100, 5);
    } else {
    return new Params(20, 10, 20, 100, 20);
    }
    }

    Another important parameter is the sigmaFactor here:

    /**
    * Determines the maximum number of settled edges for the next search based on the mean number of settled edges and
    * the fluctuation in the previous searches. The higher this number the longer the search will last and the more
    * witness paths will be found. Assuming a normal distribution for example sigmaFactor = 2 means that about 95% of
    * the searches will be within the limit.
    */
    private double sigmaFactor = 3.0;
    private int minimumMaxSettledEdges = 100;
    private int settledEdgeStatsResetInterval = 10_000;

    which controls the trade-off between the number of shortcuts and the preparation time. If you want to speed up the preparation and are willing to accept slower queries you should try reducing sigmaFactor first (something between 1 and 3 would be my guess, but I have not tried this too much on maps as large as Europe).

    To really make progress here I think much more significant changes are needed, especially regarding the graph representation, like #1067.

  10. HendrikLeuschner commented on May 29, 2019

    @HendrikLeuschner

    Thanks, we can definitely try and tune the parameters. Seeing that there is an increase of 44M to 170M shortcuts, I do not think this will solve our problem, though. I agree that algorithmic/logical changes are needed to significantly improve the performance.

  11. easbar commented on May 29, 2019

    @easbar
    MemberAuthor

    Thanks, we can definitely try and tune the parameters.

    Ok, yes any progress you can make with this regard would be interesting

    Seeing that there is an increase of 44M to 170M shortcuts,

    I doubt that there will be huge improvements in terms of the number of shortcuts. For edge-based there will always be a lot more shortcuts needed than for node-based. But it should be possible to achieve a faster preparation (but using more rather than less memory, also mentioned in #1067).

  12. easbar commented on May 31, 2019

    @easbar
    MemberAuthor

    to significantly improve the performance.

    Are you mostly interested in a faster preparation time, less memory usage during the contraction or a smaller size of the contracted graph ?

  13. HendrikLeuschner commented on Jun 3, 2019

    @HendrikLeuschner

    The memory usage during preparation can be handled. What we definitely need is less prep time, as the current ~2 days for Europe will probably translate to 4 or more days globally, even more on our preprocessing that creates some extras. In addition, we need to run this with at least 2 profiles, meaning double the time and double the size. So out of the three, we definitely need less prep time and as secondary condition smaller size.
    As soon as I have some time, I can try some parameter tuning, though at least for node-based CH I did not actually find major improvements.
    Thanks!

  14. 3 remaining items

  15. benjamin-rty commented on Sep 4, 2019

    @benjamin-rty

    @HendrikLeuschner, Can you share the results of tuning the parameters ?
    @easbar, Can the PrepareContractionHierarchies done by multiple cores ? I thave 8 cpu's and only one cpu is calculation the edge based CH. (The prepare.ch.threads is set on 8)

  16. easbar commented on Sep 4, 2019

    @easbar
    MemberAuthor

    Can the PrepareContractionHierarchies done by multiple cores ? I thave 8 cpu's and only one cpu is calculation the edge based CH. (The prepare.ch.threads is set on 8)

    Maybe, but I don't think this trivial to do. The prepare.ch.threads parameter only determines how many preparations are done in parallel (when using multiple vehicles/weightings). For a single preparation we only use one core.

  17. benjamin-rty commented on Sep 5, 2019

    @benjamin-rty

    @esabar, thanks for the answer.
    I'am processing Europe - car - edgebased on my local machine. I will let you known my results (monday)

  18. benjamin-rty commented on Sep 10, 2019

    @benjamin-rty

    @esabar, my processing with edge_based=true|u_turn_costs=-1 in CH for europe took 1d 11h:10m:16s. I have run 3 different weigthings.
    INFO [2019-09-05 07:04:27,168] com.graphhopper.routing.ch.PrepareContractionHierarchies: new shortcuts: 127 184 814, initSize:40 226 867, prepare|fastest, periodic:0, lazy:100, neighbor:0, t(total): 44920.67, t(period): 3266.73, t(lazy): 33164.39, t(neighbor): 0.00, t(contr): 8312.85, t(other) : 176.70, dijkstra-ratio: 74.73%, lazy-overhead: 99%, totalMB:55532, usedMB:32065

    INFO [2019-09-05 07:04:27,171] com.graphhopper.routing.ch.PrepareContractionHierarchies: took: 44920s, graph now - num edges: 51 692 460, num nodes: 40 226 867, num shortcuts: 127 184 814

    INFO [2019-09-05 12:41:27,602] com.graphhopper.routing.ch.PrepareContractionHierarchies: new shortcuts: 136 829 098, initSize:40 226 867, prepare|shortestfastest, periodic:0, lazy:100, neighbor:0, t(total): 65141.11, t(period): 2963.12, t(lazy): 51612.38, t(neighbor): 0.00, t(contr): 10378.09, t(other) : 187.52, dijkstra-ratio: 79.48%, lazy-overhead: 100%, totalMB:55609, usedMB:44984

    INFO [2019-09-05 12:41:27,602] com.graphhopper.routing.ch.PrepareContractionHierarchies: took: 65141s, graph now - num edges: 51 692 460, num nodes: 40 226 867, num shortcuts: 136 829 098

    INFO [2019-09-06 04:54:32,932] com.graphhopper.routing.ch.PrepareContractionHierarchies: new shortcuts: 146 883 308, initSize:40 226 867, prepare|shortest, periodic:0, lazy:100, neighbor:0, t(total): 123526.44, t(period): 2803.39, t(lazy): 105324.03, t(neighbor): 0.00, t(contr): 15198.32, t(other) : 200.70, dijkstra-ratio: 86.03%, lazy-overhead: 102%, totalMB:55664, usedMB:42343

    INFO [2019-09-06 04:54:32,932] com.graphhopper.routing.ch.PrepareContractionHierarchies: took: 123526s, graph now - num edges: 51 692 460, num nodes: 40 226 867, num shortcuts: 146 883 308

    INFO [2019-09-06 04:54:32,933] com.graphhopper.reader.osm.GraphHopperOSM: flushing graph CH|motorrty|RAM_STORE|2D|turn_cost|5,14,4,3,3, details:edges:51 692 460(1578MB), nodes:40 226 867(614MB), name:(207MB), geo:309 513 127(1181MB), bounds:-31.2665395,46.67541544903998,30.171007778592582,78.94290117046761, CHGraph|shortest|motorrty|edge_based=true|u_turn_costs=-1, shortcuts:146 883 308, nodesCH:(307MB), CHGraph|fastest|motorrty|edge_based=true|u_turn_costs=-1, shortcuts:127 184 814, nodesCH:(307MB), CHGraph|shortestfastest|motorrty|edge_based=true|u_turn_costs=-1, shortcuts:136 829 098, nodesCH:(307MB), totalMB:55664, usedMB:42428)

    INFO [2019-09-06 04:57:06,554] com.graphhopper.reader.osm.GraphHopperOSM: flushed graph totalMB:55659, usedMB:44179)

  19. easbar commented on Sep 10, 2019

    @easbar
    MemberAuthor

    Thanks! If I may summarize this:

    weighting graph.nodes (mio) graph.edges (mio) graph.shortcuts (mio) preparation time (min)
    fastest 40 52 127 748
    shortestfastest 40 52 136 1085
    shortest 40 52 146 2085
  20. easbar commented on Sep 10, 2019

    @easbar
    MemberAuthor

    Btw if you use finite u-turn costs you might get less shortcuts: #1652 (comment)

  21. IldarKhayrutdinov commented on Feb 23, 2022

    @IldarKhayrutdinov
    Contributor

    My test results.
    OSM file: russia.osm.pbf 2.9 Gb
    Server: 20 GB RAM, CPU - know only that 8 cores

    CLICK ME

    0-7 rows is master branch (e3ab2ac from 8 Feb)
    *0 row is new_eb_ch_exp branch (aaee6d7 from 14 Feb)
    *0 launched after some time 0-7 by this time my server began to overload (other applications on the server), so maybe *0 could even better result

    ** watched not all the time, so this column is not accurate

    # Profile Mode Preparation time **RAM
    import is completed / max
    Request 9300 km
    Moscow-Vladivostok
    Request 1350 km
    Moscow-Ufa
    0 vehicle: car
    weighting: fastest
    turn_costs: true
    u_turn_costs: 60
    CH 1 h 10 min 12 / 13.5 Gb 148-155 ms 46-49 ms
    1 vehicle: car
    weighting: fastest
    CH 8-9 min 11 Gb 149-166 ms 43-46 ms
    2 vehicle: car
    weighting: fastest
    turn_costs: true
    u_turn_costs: 60
    LM 7 min 9.4 Gb 6 sec 55-75 ms
    3 vehicle: car
    weighting: fastest
    LM 7 min 9.4 / 14 Gb 916-962 ms 51-59 ms
    4 vehicle: car
    weighting: short_fastest
    turn_costs: true
    u_turn_costs: 60
    CH 1 h 12.3 Gb 151-161 ms 46-59 ms
    5 vehicle: car
    weighting: short_fastest
    CH 8 min 9.9 Gb 151-160 ms 46-47 ms
    6 vehicle: car
    weighting: shortest
    turn_costs: true
    u_turn_costs: 60
    CH 48 min 12.2 Gb 174-185 ms 50-52 ms
    7 vehicle: car
    weighting: custom
    turn_costs: true
    u_turn_costs: 60
    CH 1 h 6 min 16.2 Gb 161-177 ms 45-60 ms
    *0 vehicle: car
    weighting: fastest
    turn_costs: true
    u_turn_costs: 60
    CH 50 40 min 9-10 / 17 Gb the same the same
  22. easbar commented on Feb 23, 2022

    @easbar
    MemberAuthor

    Thanks! So edge-based CH import was around 6-8x slower than node-based. But the query time was about the same? Usually this should be a bit slower. The edge-based import on the new branch was around 30% faster than master. At some point I was hoping for more like 40-50%. I am still running some tests for this (will open a separate PR soon).

  23. IldarKhayrutdinov commented on Feb 23, 2022

    @IldarKhayrutdinov
    Contributor

    edge-based CH import was around 6-8x slower than node-based. But the query time was about the same?

    If I understand you correctly, needs to compare 0 and 2 rows. LM query is slower, especially 9300 km, 1350 km is a bit slower.

  24. easbar commented on Feb 23, 2022

    @easbar
    MemberAuthor

    If I understand you correctly, needs to compare 0 and 2 rows. LM query is slower, especially 9300 km, 1350 km is a bit slower.

    If we look at rows 0 and 2 we see that the LM query is much slower than CH and that is expected. And it is also the more slower the longer the route is that is expected as well. But I was actually comparing rows 0 and 1, because CH with turn costs normally results in a slower query time compared to CH without turn costs. Did you enable instructions and maybe path details? Maybe the total query time was not dominated by the pure route calculation time. 43-46ms in row 1 actually seem rather slow to me. If you are curious it would be interesting to know the query time for instructions=false.

  25. IldarKhayrutdinov commented on Feb 23, 2022

    @IldarKhayrutdinov
    Contributor

    ah, really, without turn_costs should be slower.

    Did you enable instructions and maybe path details?

    instructions was false.

    I will try again to run these tests (0, 1, *0 rows).

    PS: I just restarted *0, now it's even faster, result table updated. Maybe the server is not overloaded right now.
    But max RAM has increased (up to 17)

  26. otbutz commented on Feb 23, 2022

    @otbutz
    Contributor

    We should really provide a JMH benchmark for these kind of things.

  27. easbar commented on Feb 23, 2022

    @easbar
    MemberAuthor

    We should really provide a JMH benchmark for these kind of things.

    We have the Measurement class already which we run for every commit to track the routing and import speed etc. We do this for a map of Germany (~3G) and Bavaria (~0.5G). Would it be better to use JMH for these benchmarks? Maybe, yes. But so far I do not see what kind of improvement we can expect from this that justifies such a migration.

  28. easbar commented on Feb 25, 2022

    @easbar
    MemberAuthor

    After #2522 I'll close here for now. Not that further improvements are impossible, but we should open another issue if somebody actually wants to work on this.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions