Running OSRM

markspence edited this page Jan 5, 2017 · 79 revisions

How to run the tool chain



osrm-extract berlin-latest.osm.pbf -p profiles/car.lua
osrm-contract berlin-latest.osrm
osrm-routed berlin-latest.osrm

Extracting the Road Network (osrm-extract)

Exported OSM data files can be obtained from providers such as Geofabrik. OSM data comes in a variety of formats including XML and PBF, and contain a plethora of data. The data includes information which is irrelevant to routing, such as positions of public waste baskets. Also, the data does not conform to a hard standard and important information can be described in various ways. Thus it is necessary to extract the routing data into a normalized format. This is done by the OSRM tool named extractor. It parses the contents of the exported OSM file and writes out routing metadata.

Profiles are used during this process to determine what can be routed along, and what cannot (private roads, barriers etc.).

It's best to provide a swapfile so that the out-of-memory situations do not kill OSRM (the size depends on your map data):

fallocate -l 100G /path/to/swapfile
chmod 600 /path/to/swapfile
mkswap /path/to/swapfile
swapon /path/to/swapfile

Note: this does not write 100 GB of zeros. Instead what it does is allocating a certain amount of blocks and just setting the 'uninitialized' flag on them, returning more or less immediately.

External memory accesses are handled by the stxxl library. Although you can run the code without any special configuration you might see a warning similar to [STXXL-ERRMSG] Warning: no config file found. Given you have enough free disk space, you can happily ignore the warning or create a config file called .stxxl in the same directory where the extractor tool sits. The following is taken from the stxxl manual:

You must define the disk configuration for an STXXL program in a file named '.stxxl' that must reside in the same directory where you execute the program. You can change the default file name for the configuration file by setting the enviroment variable STXXLCFG .

Each line of the configuration file describes a disk. A disk description uses the following format:


Example: at the time of writing this (v4.9.1) the demo server uses 250GB stxxl file with the following configuration:


Check STXXL's config documentation.

Creating the Hierarchy (osrm-contract)

The so-called Hierarchy is precomputed data that enables the routing engine to find shortest path within short time.

osrm-contract map.osrm 

where map.osrm is the extracted road network. Both are generated by the previous step. A nearest-neighbor data structure and a node map are created alongside the hierarchy.

Running the Engine via a HTTP Server (osrm-routed)

We provide a demo HTTP server on top of the libosrm library doing the heavy lifting. You can start it via:

osrm-routed map.osrm

You can access the API on localhost:5000. See the Server API for details on how to use it.

Here is how to run an example query: