Published by breki on 20 Jan 2011 at 10:12 pm
Maperitive Build 1108

photo credit: Omar Eduardo
My previous post about PBF reading successes was written way too prematurely. It turned out my PBF reading code had some serious bugs which made reading look much faster than it actually was (one of the reasons was that I neglected to read OSM node keys/values when written in PBF dense node format).
I’ve subsequently written some extensive tests, comparing OSM database contents from XML and PBF file of the same area (thanks Geofabrik) on an object by object basis, so I’m now 95% sure the PBF code works OK. Performance-wise the (final?) results are much less glamorous than it looked initially: PBF reading is “only” 2.5 times faster than reading OSM.bz2 files, while in memory consumption terms, they are pretty much the same. I curious what other OSM software like osmosis has to say about these results.
I had hoped I could speed the PBF reading by spreading the work on several processor cores. What I did is to use Microsoft’s Parallel Extensions library to separate the fetching of PBF file blocks from the actual parsing of them into two (or more) cores. This resulted in only about 10% increase of the overall speed (tested on my two-core machine, so on more cores the result could be better).
It actually proved pretty hard to do a decent job of separating work in some balanced fashion. Since the file reading is sequential, this can only be done by one thread/core, so you want to put as little other work to that core as possible. As soon as file block bytes are fetched from the file, they are delegated to another core to parse it (in terms of protocol buffers) and then extract OSM objects from it. The problem is that you don’t want to enqueue too many file blocks at the same time, since this takes up valuable memory (which is already filled with extracted OSM objects). So I ended up using a blocking queue, which means the main thread (which reads the file) will wait until at least one core is available before filling the queue with another file block.
I’ve also tried micro-management strategy – using multiple cores to extract individual OSM objects, but this only really works for ways and relations. Current PBF extracts use dense nodes format, which is delta-encoded and thus forces you to read things sequentially on a single thread of execution. I guess this is the price of having a format that wants to satisfy two different (and inherently conflicting) goals: less space and less CPU.
I’m fairly new to Parallel Extensions and there are probably better ways of handling this, but I’ll leave it for the future.
Anyway, a new Maperitive release is out, grab it from the usual place.


igorbrejc.net » Maperitive: Reading OSM PBF Files on 20 Jan 2011 at 22:19 #
[...] UPDATE: the post below was based on premature assumptions that my new PBF code is actually working. It turns out it had a number of serious bugs which made reading look faster than it actually is. Here’s a followup post. [...]
Mirek on 04 Feb 2011 at 11:19 #
HI Breki,
Maperitive is just fantastic piece of work
. I’ve decided to donate your programming via ‘Kosmos Home’ page. So keep up your perfect work.
Now I’ve a question – is it possible to configure http address of OSM API for downloading XML data? Because now the preconfigured server doesn’t work (503) .
Thanks for info,
Mirek Novak
Johannes on 05 Feb 2011 at 12:24 #
Hello Igor, i found .no other way to get to you, i just wanted to report that i tried Maperitive on Linux (Mono 2.8.2) and got the following error:
Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for Maperitive.Program —> System.TypeInitializationException: An exception was thrown by the type initializer for log4net.LogManager —> System.ExecutionEngineException: SIGILL at System.Collections.Hashtable..ctor (Int32 capacity, Single loadFactor, IHashCodeProvider hcp, IComparer comparer) [0x00000] in :0 at System.Collections.Hashtable..ctor (Int32 capacity, Single loadFactor) [0x00000] in :0 at System.Collections.Hashtable..ctor () [0x00000] in :0 at log4net.Core.WrapperMap..ctor (log4net.Core.WrapperCreationHandler createWrapperHandler) [0x00000] in :0 at log4net.LogManager..cctor () [0x00000] in :0 — End of inner exception stack trace — at Maperitive.Program..cctor () [0x00000] in :0 — End of inner exception stack trace —
Raghav on 11 Feb 2011 at 10:48 #
Hi, Maperitive is a wonderful software and it worked like a charm for my purpose. We are working on a small map based app and we are building on OpenLayers. Could you please tell me where to include the Tiles generated using Maperitive. Thanks, Raghav
breki on 11 Feb 2011 at 18:44 #
@Raghav: I’m a little bit confused by your question, could you write a little bit more?
Raghav on 11 Feb 2011 at 19:43 #
Thanks breki for the reply. I could successfully generate tiles for my osm dataset using Maperitive for different zoom levels. I want to use them with openlayers, can you brief me a bit on how to proceed? I used another app called maptiler from maptiler.org, which is generating the tiles and also the html file(which gives me an idea how these tiles are added to openlayers/google maps api), but it doesn’t have as many options as Maperitive. I am not sure if I could make myself clear
Regards,
Raghav
Somenath on 18 Apr 2012 at 6:21 #
i am very new to this domain. actually i want to develop a PBF reader/writer for Android to read-cum-render/store OSM data. i am now a little bit familiar with protobuf. however, i am really facing difficulties to do the above task. is it possible for you to guide me in this regards? also please share some useful links from where i can get some idea to do it.
breki on 18 Apr 2012 at 17:00 #
@Somenath: unfortunately I don’t really have too much time for some real guidance with all the work I’m doing. In general, I suggest asking it on the OSM-dev mailing list (http://lists.openstreetmap.org/listinfo/dev). I also suggest you should look for existing open source implementations of a PBF reader/writer (which there should be plenty of, especially for Java).
If you have any specific questions/issues on PBF, let me know and I’ll try to help you.
Somenath on 19 Apr 2012 at 13:15 #
Breki,
Thank you for your prompt reply. i will definitely keep in touch with you.
Som