Skip to content

Geometry limited by 2^32-1 #500

Closed

Description

@karussell

Geometry is limited by 2^31 (after a change here it is now limited by 2^32-1).

As the geometry ref is a positive integer only and we point into the DataAccess object with this int (without any conversion) there is a limit of 2^31 ints encoded from a list of "lat,lon,ele" which could be reachable for the world wide case when all ways are included. (2^31 because of signed int vs. 2^32 unsigned for other programming languages)

For car,bike2,foot it is currently only geo:1 676 518 308(6396MB) (and edges:178 094 237(6115MB))

See this mailing list post by @jtheuer

To reduce severity of this issue we can additionally:

  • reuse the area when calling setWayGeometry of existing edge, if new point list is smaller
  • use delta encoding Use delta encoding for geometry #234
  • use only 3 bytes for the elevation data instead of 4 -> not much improvement as we use int-based reference for way geometry
  • using negative values too (convert into 'unsigned int' -> long) done
  • trying lz4 compression that could reduce the string_index a lot: String index #1784 lz4 likely increases output due to short length

Activity

  1. added this to the 0.6 milestone on Aug 24, 2015
  2. karussell commented on Dec 1, 2015

    @karussell
    MemberAuthor

    We increased the limit to (2^32-1) which makes this issue a lot less critical, this could only be tested via some unit test and this real world test. Will still let it open.

  3. removed this from the 0.6 milestone on Dec 1, 2015
  4. highsource commented on Aug 17, 2016

    @highsource
    Contributor

    Hi,

    I'm trying to get my head around this issue.

    From what I see in BaseGraph, it uses DataAccess (a kind of abstract byte storage) to save bytes. PointList gets encoded into a list of lat, lon and possibly ele, 4 bytes each which are then saved in wayGeometry altogether as a byte array.

    I'm not quite sure where the limit is. Is it the type of geoRef? I see this:

            long geoRef = Helper.toUnsignedLong(edges.getInt(edgePointer + E_GEO));
    

    Is the problem that geoRef is stored as unsigned int? Why can't we store it as long instead? Probably because it will add 4 bytes per edge and that would be too much of memory? How many edges do we have? If it's only 178 094 237 (not sure about the number above), 4 extra bytes per edge will be around 700 MB, that does not seem too much.
    We can add just one or two bytes if it's critical, that would increase the capacity to 2^40/2^48 which will be more than enough - without significantly increasing the size of the edge storage. Or am I missing something?

    Or is there a limit of DataAccess size like 4GB file size or something?

    To reduce severity of this issue one can additionally reduce the storage usage by:

    This actually does not increase the possible space of geoRef but reduces the rate of geoRef growth, right? The size of the byte array of the point list will be smaller so geoRef will grow slower.

    I think we can win 1 bit if we don't save len * dim but just len. dim is 2 or 3 so this would give at least 1 bit.

    Concerning proposed solutions:

    • reusing the area when calling setWayGeometry of existing edge, if new point list is smaller

    I think this might be quite hard to implement correctly.

    Quite an approach.

    • use only 2 or 3 bytes for the elevation data instead of 4

    I think this is a pretty good idea. Who needs elevation with 32-bit precision?

    • use negative values too (convert into 'unsigned int' -> long)

    I guess this is already done.

    I think 16-bit elevation would be the easiest to get start with, it would give ca. 2 bytes per point (1/6 if I get it correctly).

    But an ultimate solution would be to make the length of geoRef configurable so that you could use 32 bit on smaller datasets and 48 or 64 on larger datasets.

    Please let me know if I'm on the right track.

    Best wishes,
    Alexey

  5. highsource commented on Aug 17, 2016

    @highsource
    Contributor
    • reusing the area when calling setWayGeometry of existing edge, if new point list is smaller

    Sorry, I got this now. This must be quite easy. Basically get geoRef and count like in fetchWayGeometry_ and if count is less than number of current points in the list, write the new array over existing geoRef.

    This help with most update operations (unless PointList grows). This is why you've pointed me to this in #713. If I update elevations in post-processing step, this will use a lot of new geo-refs. Got it.

    I think I'll give it a try.

  6. karussell commented on Aug 17, 2016

    @karussell
    MemberAuthor

    Is the problem that geoRef is stored as unsigned int?

    Yes, kind of. In Java everything is signed so we only have 2^31 ... using the full int already save us for the several next years :)

    Or is there a limit of DataAccess size like 4GB file size or something?

    DataAccess is designed to grow efficient and to a big size. The functionality is basically a big array (but not limited to an integer size like array) and it also does not have the ugliness of e.g. an ArrayList to grow memory inefficient (allocate new and copy). Instead it starts with 1MB and just adds more segments if necessary. So you can grow to 1MB*2^31=2048TB if I have correctly calculated, also you can increase or decrease the segment size. Furthermore you can switch easily between the implementations (in-memory vs. memory mapped)

    without significantly increasing the size of the edge storage. Or am I missing something?

    This is correct, yes. But the storage is not that efficient at the moment (ask people using this for offline routing :)) and I would avoid to bloat it more. Instead I would prefer to make the geometry more compact.

    This actually does not increase the possible space of geoRef but reduces the rate of geoRef growth, right?

    Yes

    I guess this is already done.

    To be honest, I'm not 100% sure. Will have to check again.

    But an ultimate solution would be to make the length of geoRef configurable so that you could use 32 bit on smaller datasets and 48 or 64 on larger datasets.

    This would be nice but is currently not possible. E.g. it would also nice to have not 4 but 5 bytes for edgeIds as we could run out of IDs in some (dozen?) years. Dynamic length of pointers is not possible because every edge is basically a row in the edges DataAccess and the row length is static. Of course we could point into some dynamic edge area like we are already doing for the geometry but these indirections also costs a bit performance.

    If I update elevations in post-processing step, this will use a lot of new geo-refs. Got it.

    Yes & 👍 !

    Please keep asking if something is unclear :) !

  7. karussell commented on Aug 17, 2016

    @karussell
    MemberAuthor
  8. karussell commented on Aug 18, 2016

    @karussell
    MemberAuthor

    Ups, I have indeed already fixed the 2^31 limit, see this comment with a real world test case #500 (comment)

    So the limit is now 2^32 which is a lot less critical (several years with the current ~10% grow of OSM per year)

  9. added a commit that references this issue on Aug 19, 2016
  10. buma commented on Oct 16, 2019

    @buma

    Is it possible that this problem came back with increase of OSM data?

    I have graphopper version 0.6 with applied fix: dfd62e2 which increases limit to 2^32. I tested graphopper on linked real world test and it worked.
    I'm importing world planet file and everything worked until this week. I can't import OSM data from 2019 10 13 anymore because
    java.lang.IllegalArgumentException: new capacity has to be strictly positive at com.graphhopper.storage.RAMDataAccess.ensureCapacity(RAMDataAccess.java:99) at com.graphhopper.storage.BaseGraph.ensureGeometry(BaseGraph.java:984) at com.graphhopper.storage.BaseGraph.setWayGeometryAtGeoRef(BaseGraph.java:864) at com.graphhopper.storage.BaseGraph.setWayGeometry_(BaseGraph.java:851) at com.graphhopper.storage.BaseGraph.access$100(BaseGraph.java:46) at com.graphhopper.storage.BaseGraph$CommonEdgeIterator.setWayGeometry(BaseGraph.java:1294)

    And maxGeoRef in Base graph is -2 147 483 139 after this exception
    Here are values at the point of exception:
    14:22:03.584 WARN main d.k.w.importer.OSMReader: EdgeID: 301415499, pillarNodes:169 geo_max:-2147483139
    14:22:03.584 WARN main d.k.w.importer.OSMReader: Counter:162710476 pillarNodesCount:661591226 (sums all pillarNodes in storeWayGeometry function)
    14:22:03.584 WARN main d.k.w.importer.OSMReader: Simplify removed 64 nodes
    14:22:03.584 WARN main d.k.w.importer.OSMReader: edges:301 415 500(10349MB), nodes:233 521 524(3564MB), name:(546MB), geo:-2 147 483 139(8193MB), bounds:-180.0,180.0,-79.81499965820461,83.66130796062889,-965.31,8793.5
    I'm looking if there is problem in my code (the problem is any change takes 6 hours to run, because world is big), but code for importing graph didn't change at all during this and previous import in September the only thing that could be the issue is broken creation of planet file which is also custom code.
    But same planet file can be imported when setWayPointMaxDistance is set on 6 (instead of 3) on OSMReader.
    And this import has this values at the end:
    imported graph dimensions|RAM_STORE|3D|NoExt|4,12,3,2,2, details:edges:302 220 812(10376MB), nodes:233 672 258(3566MB), name:(546MB), geo:1 757 760 817(6706MB), bounds:-180.0,180.0,-79.81499965820461,83.66130796062889,-965.31,8793.5

  11. 2 remaining items

  12. added 2 commits that reference this issue on Oct 17, 2019
  13. changed the title [-]Geometry limited by 2^31[/-] [+]Geometry limited by (2^32-1)[/+] on Apr 17, 2020
  14. changed the title [-]Geometry limited by (2^32-1)[/-] [+]Geometry limited by 2^32-1[/+] on Apr 17, 2020
  15. huco commented on Apr 6, 2024

    @huco

    I think OSM world dataset has reached a point where 32 bits are no longer enough.

    I've tried to import world dump from April 5th with the latest master branch and it fails with the following exception:

    java.lang.RuntimeException: Could not parse OSM file: /home/bonk/import/import/planet-latest.osm.pbf
    at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:406)
    at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:107)
    at com.graphhopper.reader.osm.OSMReader.readGraph(OSMReader.java:177)
    at com.graphhopper.GraphHopper.importOSM(GraphHopper.java:910)
    at com.graphhopper.GraphHopper.process(GraphHopper.java:812)
    at com.graphhopper.GraphHopper.importAndClose(GraphHopper.java:776)
    at com.graphhopper.application.cli.ImportCommand.run(ImportCommand.java:36)
    at com.graphhopper.application.cli.ImportCommand.run(ImportCommand.java:27)
    at io.dropwizard.cli.ConfiguredCommand.run(ConfiguredCommand.java:98)
    at io.dropwizard.cli.Cli.run(Cli.java:78)
    at io.dropwizard.Application.run(Application.java:94)
    at com.graphhopper.application.GraphHopperApplication.main(GraphHopperApplication.java:38)
    Caused by: java.lang.IllegalStateException: Geometry too large, does not fit in 32 bits 4294967319
    at com.graphhopper.storage.BaseGraph.nextGeoRef(BaseGraph.java:503)
    at com.graphhopper.storage.BaseGraph.setWayGeometry_(BaseGraph.java:367)
    at com.graphhopper.storage.BaseGraph$EdgeIteratorStateImpl.setWayGeometry(BaseGraph.java:931)
    at com.graphhopper.reader.osm.OSMReader.addEdge(OSMReader.java:383)
    at com.graphhopper.reader.osm.WaySegmentParser$Pass2Handler.handleSegment(WaySegmentParser.java:370)
    at com.graphhopper.reader.osm.WaySegmentParser$Pass2Handler.splitSegmentAtSplitNodes(WaySegmentParser.java:341)
    at com.graphhopper.reader.osm.WaySegmentParser$Pass2Handler.splitLoopSegments(WaySegmentParser.java:299)
    at com.graphhopper.reader.osm.WaySegmentParser$Pass2Handler.splitWayAtJunctionsAndEmptySections(WaySegmentParser.java:274)
    at com.graphhopper.reader.osm.WaySegmentParser$Pass2Handler.handleWay(WaySegmentParser.java:256)
    at com.graphhopper.reader.osm.WaySegmentParser$ReaderElementHandler.handleElement(WaySegmentParser.java:501)
    at com.graphhopper.reader.osm.WaySegmentParser.readOSM(WaySegmentParser.java:401)
    ... 11 more

    Is anybody else experiencing this issue? My last successful world import was somewhere around mid February.

  16. easbar commented on Apr 6, 2024

    @easbar
    Member

    Which settings/profiles/ignored_highways/config.yml did you use for this planet import?

  17. huco commented on Apr 8, 2024

    @huco

    I'm using:

    • 3 custom profiles (road, mtb and hike)
    • ignored_highways = motorway,trunk
    • elevation data (long_edge_sampling_distance=10, way_point_max_distance=1)

    I guess elevation settings exacerbate the issue; if I increase long_edge_sampling_distance = 20 planet import finishes successfully.

  18. easbar commented on Apr 8, 2024

    @easbar
    Member

    Ok yes this could be it. For graphhopper.com we are running up to date planet imports without this issue, but you might have hit the limit because of the long edge sampling. Did you check how large the geo ref value gets without the sampling?

  19. easbar commented on Apr 8, 2024

    @easbar
    Member

    I increased the size of the geo ref from four to eight bytes here: f18c122
    This is certainly not the most memory efficient solution and five bytes should already be enough. The memory increase is four bytes per edge, so something like 3-4GB for the planet import. I haven't tested this yet, but if you could try the planet import with your settings again that would be very helpful.

  20. huco commented on Apr 9, 2024

    @huco

    Did you check how large the geo ref value gets without the sampling?

    I've tried to disable sampling (comment out sampling parameters and disabled bilinear interpolation) and got the following:

    geo:3,824,033,340(14588MB)

    With sampling distance = 20 it was:

    geo:4,273,074,032(16301MB)

    I increased the size of the geo ref from four to eight bytes here: f18c122 This is certainly not the most memory efficient solution and five bytes should already be enough. The memory increase is four bytes per edge, so something like 3-4GB for the planet import. I haven't tested this yet, but if you could try the planet import with your settings again that would be very helpful.

    I will try it out and report back.

  21. added a commit that references this issue on Apr 9, 2024
  22. huco commented on Apr 11, 2024

    @huco

    I will try it out and report back.

    I can confirm import completes successfully with my original settings. Thanks!

  23. added a commit that references this issue on Apr 20, 2024
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