Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for disabling feature datasets #6666

Merged
merged 1 commit into from
Aug 4, 2023

Conversation

mjjbell
Copy link
Member

@mjjbell mjjbell commented Jul 31, 2023

Issue

This change adds support for disabling datasets, such that specific files are not loaded into memory when running OSRM. This enables users to not pay the memory cost for features they do not intend to use.

Initially, there are two options:

  • ROUTE_GEOMETRY, for disabling overview, steps, annotations and waypoints.
  • ROUTE_STEPS, for disabling steps only.

Attempts to query a feature for which the dataset is disabled will lead to a DisabledDatasetException being returned.

Full details are on a new wiki page: https://github.com/Project-OSRM/osrm-backend/wiki/Disabled-Datasets

Design Choices

The implementation separates the "feature dataset" concept from the actual files loaded into memory. This gives some flexibility in how the data is stored, allowing for changes in the file structure without breaking the user facing API.

The feature datasets to disable are passed as an array argument to osrm-routed, osrm-datastore and the NodeJS engine configuration. Currently, you would only select at most one option (ROUTE_GEOMETRY is a superset of ROUTE_STEPS), but the array interface will allow us to add more options in the future whilst maintaining backwards compatibility.

On every data facade call to optional datasets, we check a boolean to see if its loaded. I attempted other solutions that don't perform a check on every call, such as virtual functions and lambdas. These didn't improve performance and were significantly more complicated, so I stuck with the simplest implementation.

Performance

For a contraction hierarchy dataset, --disable-feature-dataset ROUTE_GEOMETRY reduces RAM usage by ~15%.

There appears to be no impact on query performance. This is likely due to the number of data facade calls affected being very small. Will add full query performance results in a subsequent post.

Future Direction

Some optional datasets are stored in files with required datasets. One such example is OSM node IDs being stored with coordinates. We could reduce memory usage further when disabling ROUTE_GEOMETRY by splitting such files, or refactoring how files are loaded into memory.

Tasklist

Requirements / Relations

#5218
#5838
#6045

@@ -31,40 +31,79 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <boost/filesystem/path.hpp>

#include "storage/io_config.hpp"
#include "osrm/datasets.hpp"

#include "set"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit.

Suggested change
#include "set"
#include <set>

{
}

std::string Dataset() const { return dataset; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit.

Suggested change
std::string Dataset() const { return dataset; }
const std::string& Dataset() const { return dataset; }

Base automatically changed from mbell/direct_load to master August 1, 2023 08:24
@mjjbell mjjbell force-pushed the mbell/disable_feature_dataset branch from 3b90f44 to d34f259 Compare August 1, 2023 20:14
This change adds support for disabling datasets, such that specific
files are not loaded into memory when running OSRM. This enables users
to not pay the memory cost for features they do not intend to use.

Initially, there are two options:
- ROUTE_GEOMETRY, for disabling overview, steps, annotations and waypoints.
- ROUTE_STEPS, for disabling steps only.

Attempts to query features for which the datasets are disabled will
lead to a DisabledDatasetException being returned.
@mjjbell mjjbell force-pushed the mbell/disable_feature_dataset branch from d34f259 to 189f6eb Compare August 3, 2023 22:01
@mjjbell
Copy link
Member Author

mjjbell commented Aug 4, 2023

For completeness, I ran performance tests using the same setup as here with the first three coordinate sets.

All requests had the parameters overview=simplified&annotations=true&steps=true&skip_waypoints=false, to check if there is any performance penalty for checking if a dataset is loaded (optional) in comparison to it always being loaded (master).

The results show no change in performance with this PR. Tests with request parameters that disabled geometries and steps had the same outcome.

image
image
image

@mjjbell mjjbell merged commit db7946d into master Aug 4, 2023
@mjjbell mjjbell deleted the mbell/disable_feature_dataset branch August 4, 2023 17:43
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.

2 participants