Skip to content

Refactoring of GraphHopperStorage to fix #111 - #447

Merged
karussell merged 33 commits into
masterfrom
issue_111
Jul 16, 2015
Merged

karussell merged 33 commits into
masterfrom
issue_111

Conversation

@karussell

Copy link
Copy Markdown
Member

This pull request is a major rewrite of some core parts of GraphHopper (storage and access of CHGraph, old name LevelGraph). This fixes #111. E.g. GraphHopperStorage now contains graphs like base graph and a ch graph which will allow for the physical separation of edges and shortcuts.

Currently there are the following steps before we can merge this:

  • merge master into this
  • rename LevelGraph* to CHGraph*
  • separate node_ch_refs for CHGraphImpl to avoid base graph going through shortcuts
  • test with none CH algo on prepared graph should pass now
  • make base graph see only its edges (no shortcuts). edge count for level graph and base graph should change (e.g. getAllEdges.count)
  • all tests should pass now
  • fix all TODOs in the source code, and can we add edges count to locationindextree.calcChecksum? And can we avoid requiring the GraphHopperStorage and use a Graph instead in DijkstraBidirectionCHTest.createFactory
  • fix some bugs uncovered while refactoring, but do this in different issues
  • separate shortcut DataAccess in CHGraphImpl

Later we can also have multiple ch graphs -> #464

Some bugs uncovered while refactoring:

  • setNodesHeader returns wrong used header size
  • internalEdgeDisconnect -> use N_EDGE_REF for nodes.setInt
  • bug if next is called after setAdditionalField? if (extStorage.isRequireEdgeField()) iter.setAdditionalField(extStorage.getDefaultEdgeFieldValue());
  • bug in test testFindShortcuts_Roundabout regarding skipped edges of shortcut 6,4
  • bug in alledgeiterator detach => reverse can be incorrectly set if detach(false) and reverse=true, can only happen if detach is called on an already detached iterator which would involve a cast
  • bug in alledgeiterator found: while iteration edgepointer can get bigger than valid edges and if it would be compacted then even array index out of bounds would get thrown
  • if too many names are stored => wrong check for long value instead int! (check AllEdgesIterator and EdgeIterable)
  • here it should be getNodes instead of getCapacity! removedNodes = new GHBitSetImpl((int) (nodes.getCapacity() / 4));
  • shouldn't we throw an exception in CHGraphImpl instead of returning? public final void setLevel( int nodeIndex, int level ) { if (nodeIndex >= baseGraph.getNodes()) return;

(where marked they are fixed in the pull request but not master yet)

@devemux86

Copy link
Copy Markdown
Contributor

Thanks Peter for providing also a summary of API changes in changelog, it helps studying the new code better.

@karussell

Copy link
Copy Markdown
Member Author

If you find something you do not understand, please let me know!

Also this is now different and needs to be changed:

call GraphHopperStorage.getBaseGraph(). To do routing with potentially shortcuts you call GraphHopperStorage.getGraph(encoder)

to "GraphHopperStorage implements now the Graph interface and delegates all necessary methods to the underlying base graph. To do routing you call getGraph(LevelGraph.class or Graph.class) where the parameter Graph.class currently returns the base graph and the behaviour is identical to GraphHopperStorage itself" (this is the convenient change I mentioned in the other issue)

@karussell karussell changed the title Refactoring of GraphHopperStorage to fix #111 and #339 Refactoring of GraphHopperStorage to fix #111 Jul 3, 2015
@karussell

Copy link
Copy Markdown
Member Author

The additional refactoring for #339 will be done in a separate step, also fixing the documentation. Now finalizing before like improving readability, fixing TODOs and performance checks.

Also to all: as all tests pass please review.

An open question is: move the BaseGraph implementation back into GraphHopperStorage to make everything simpler?

@karussell karussell added this to the 0.5 milestone Jul 3, 2015
@karussell karussell self-assigned this Jul 3, 2015
@devemux86

Copy link
Copy Markdown
Contributor

An open question is: move the BaseGraph implementation back into GraphHopperStorage to make everything simpler?

And what about CHGraph?

@karussell

Copy link
Copy Markdown
Member Author

And what about CHGraph?

CHGraph will stay separate. But moving BaseGraph back would have the advantage of avoiding the method delegation in GraphHopperStorage to the BaseGraph. Although I like the separation of storage and traversal stuff... but CHGraph currently also mixes storage and traversal :)

@devemux86

Copy link
Copy Markdown
Contributor

Ok you're probably right here.

@karussell

Copy link
Copy Markdown
Member Author

You mean moving it back into GraphHopperStorage? Just asking again as I'm still unsure ... probably I'll let if for now as it is until we find a reason pro or contra?

@devemux86

Copy link
Copy Markdown
Contributor

You mean moving it back into GraphHopperStorage?

Yes. I'm a bit sceptical about GraphHopperStorage hosting both types of graphs.
With the change it will be Base itself and still contain the CH?

@karussell

Copy link
Copy Markdown
Member Author

I'm a bit sceptical about GraphHopperStorage hosting both types of graphs.

What do you mean? Or what do you think could improve the situation? Keep in mind that we'll need in the near future multiple chGraphs managed by the GraphHopperStorage. But via ghstorage.getGraph(class) it should be very simple to extend for more purposes or even other algorithms.

With the change it will be Base itself and still contain the CH?

Yes, this would be a bit uglier design-wise but simpler.

@devemux86

Copy link
Copy Markdown
Contributor

I'm fine with current PR implementation.

With the change it will be Base itself and still contain the CH?
Yes, this would be a bit uglier design-wise but simpler.

Here I had second design thoughts but as you said it'll be simpler, so it's ok.

@devemux86

Copy link
Copy Markdown
Contributor

Well I suppose (depending on ram) it could work.
Sorry not having something usable in mind right now.

@karussell

Copy link
Copy Markdown
Member Author

Some numbers for the area 'Germany': 15% less storage and therefor RAM - as expected :) !
Routing same speed. But strangly CH routing is 20% slower, also preparation is 18% slower. To be investigated

@devemux86

Copy link
Copy Markdown
Contributor

👍
What algorithm, bidirectional Dijkstra ?

@karussell

Copy link
Copy Markdown
Member Author

Yes, to better compare CH and none-CH I've picked bidir dijkstra in both cases -> See the measurement class (or graphhopper.sh measurement area.pbf)

karussell pushed a commit that referenced this pull request Jul 14, 2015
karussell pushed a commit that referenced this pull request Jul 14, 2015
karussell pushed a commit that referenced this pull request Jul 14, 2015
@karussell

Copy link
Copy Markdown
Member Author

Although I only slightly improved the speed situation I'll merge this request soon as there are many advantages.

Disadvantages (higly likely due to the additional EdgeAccess layer):

  • 12% slower CH preparation
  • 12% slower CH routing

Advantages:

  • 10% less storage/RAM used
  • 5% faster routing, but highly likely via an unrelated change 3b19746
  • separated edges from shortcuts storage, as well as CH entries (nodesCH) from normal traversal entries (nodes), allowing us to add multiple CH profiles in the near future
  • making other speed-up techniques easier pluggable in the future
  • better architecture via composition (EdgeAccess, CHGraphImpl and BaseGraph) instead of extension (LevelGraphStorage extends GraphHopperStorage)

@devemux86

Copy link
Copy Markdown
Contributor

I follow your code changes, so 👍 for that.

@karussell

Copy link
Copy Markdown
Member Author

@devemux86 thanks for the feedback!

BTW: It would be now also possible to revert the speed we lost with #338 but we would need to introduce two integers for additional ch refs in the normal edges DataAccess object, and the levels per node could be removed which therefor leads to a slight RAM increase of ~0.5GB = (2-1)*0.5GB for the world wide case. Then we could entirely avoid the LevelEdgeFilter for normal edges too, giving us a rough boost of 15-20%

BTW2: The levels should not be removed (although no longer needed then). Instead we should just avoid to load them into RAM. Because when edge weights change and we need to recreate the CH profile the levels could then be reused and the CH preparation could be a lot faster then - at least from what I know from papers.

@devemux86

Copy link
Copy Markdown
Contributor

Peter I started playing with latest GH code.
I see with this PR old graphs do not work, right?

@karussell

Copy link
Copy Markdown
Member Author

Yes, because there is now a separate shortcuts and edges storage. Any problems I didn't think about with this :) ?

@devemux86

Copy link
Copy Markdown
Contributor

I try all the cases (e.g. loading a CH graph with a non CH config) and I see the same error message, let me conclude my tests and come back.

@devemux86

Copy link
Copy Markdown
Contributor

Yes I think something is not right (or I'm doing wrong!).

I have created a CH graph and I'm able to load it with graphHopper.setCHEnable either true or false.

@karussell

Copy link
Copy Markdown
Member Author

That is like it should be :)

You can now run without performance lost normal routing algorithms even if CH is enabled, which means you can also load the graph without the ch datastructure and everything should work - at least in theory ;)

@devemux86

Copy link
Copy Markdown
Contributor

Oh I missed that step.
I support all possible GH cases in graph loading - so it was strange to me.
It seems now that I can loosen the checks, thanks for the tip.

@devemux86

Copy link
Copy Markdown
Contributor

Since now we cannot be notified if a graph has CH or not, do we need always using setCHEnable(true) at reader, in order to be sure that we actually use the CH in CH graphs?

Because the setCHEnable(true) works also with non CH graphs, that could be a problem.
On the contrary, the setCHEnable(false) means that we may loose CH in those graphs.
Is this thought correct?

@karussell

Copy link
Copy Markdown
Member Author

Ah, okay. I see what you mean.

Because the setCHEnable(true) works also with non CH graphs

That is a problem which we should indeed fix! Either we automatically detect CH and configure everything accordingly like we do partially for the flagEncoders, or we should throw an exception. Feel free to create an issue!

On the contrary, the setCHEnable(false) means that we may loose CH in those graphs.

That is not such a big problem IMO as the results should be still correct, but yes this should be fixed probably at the same time.

@karussell
karussell deleted the issue_111 branch July 29, 2015 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

More efficient graph storage via separating shortcuts from edges

2 participants