Skip to content

Alternatives are very slow for LM/AStar+turn costs #2566

Closed

Description

@easbar

map: bayern-210101.osm.pbf:
route using maps 2 client: http://localhost:3000/?point=49.583276%2C10.991626&point=48.455783%2C12.095752&profile=car
profile: fastest/car, u_turn_costs: 60

image

traversal mode single route alternatives (max=3)
node-based 13ms ~800ms
edge-based 25ms ~9000ms

So alternatives take 80 times longer than a single route for node-based. This seems very slow, but at least it still takes less than a second. But for edge-based it is even worse where the slow down is x360 and the response takes so long that its almost not useful anymore.

This is not just special for this route, I just gave an example. I actually saw routes that took tens of seconds, and I did not even try a larger map. Disabling LM makes it even slower.

Activity

  1. easbar commented on Apr 27, 2022

    @easbar
    MemberAuthor

    Using the approach taken by @michaz in #2092 the query time for edge-based alternative seems to go down from ~9s to ~5s. For node-based it goes down a bit, too: ~700ms instead of 800ms. Even the single routes seem to be a bit faster. This was just a quick manual test, let's see what our automatic performance measurements say: 19e2e16

  2. easbar commented on Apr 27, 2022

    @easbar
    MemberAuthor

    @otbutz in #2567 you wrote:

    I can vouch for Java Mission Control paired with -XX:+UnlockDiagnosticVMOptions -XX:+DebugNonSafepoints for getting a good grasp about where the bottleneck is :)

    I am answering here as this is about speeding up alternative routes:

    Thanks I will try. I am using the YourKit Profiler, usually. But in my experience this does not help much and the real issues are typically caused by the algorithms (i.e. normally something is called too often rather than some method is slow). Or I still haven't really figured out how to use it :) In the case of AlternativeRoute I am pretty sure the following code takes very long, especially for large search trees:

    bestWeightMapFrom.forEach(new IntObjectPredicate<SPTEntry>() {
    @Override
    public boolean apply(final int traversalId, final SPTEntry fromSPTEntry) {
    SPTEntry toSPTEntry = bestWeightMapTo.get(traversalId);
    if (toSPTEntry == null)
    return true;

    But I did not really look at the alternative route algorithm to figure out if this can be avoided without making the quality of alternative routes worse.

  3. otbutz commented on Apr 27, 2022

    @otbutz
    Contributor

    normally something is called too often rather than some method is slow

    The flame view is immensely helpful IMHO.

    https://www.youtube.com/watch?v=vVh_z34Gtn8

  4. easbar commented on Apr 28, 2022

    @easbar
    MemberAuthor

    Yes, I like the flame view, too. YourKit has it as well. But often I saw cases where something looks like a bottleneck there, but in reality it wasn't. Overall I feel like I spent a lot of time looking at the profiler, but rarely it helped me finding important bottlenecks and a lot more often it was improving the algorithm that lead to significant speed ups. But maybe I'm still just doing it wrong.

    In other news: This: 19e2e16 is definitely an improvement, especially for edge-based routing without CH. And in this case the PriorityQueue#remove() call actually shows up in the profiler, too :) I'll open a separate PR for this soon -> #2571.

  5. michaz commented on May 17, 2022

    @michaz
    Member

    I would just put in a comment that this is code that exists for completeness (alternative routes without CH), but doesn't claim to be practical.

    No need to worry about its performance at all.

  6. easbar commented on May 27, 2022

    @easbar
    MemberAuthor

    Alternatives with CH are faster, but alternatives with LM/AStar are even slower since #2567. See this list of potential optimizations: #2567 (comment)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions