Make node bindings optionally return pre-rendered JSON buffers#5189
Merged
Make node bindings optionally return pre-rendered JSON buffers#5189
Conversation
f3d0r
approved these changes
Sep 3, 2018
f3d0r
approved these changes
Sep 3, 2018
chaupow
reviewed
Sep 5, 2018
…string (this avoids a lot of overhead, and moves JSON string rendering out of the main event loop).
bfe11b3 to
4058eae
Compare
ghoshkaj
approved these changes
Sep 5, 2018
datendelphin
added a commit
to fossgis-routing-server/osrm-backend
that referenced
this pull request
Nov 19, 2020
- Changes from 5.18.0:
- Optimizations:
- CHANGED: Use Grisu2 for serializing floating point numbers. [Project-OSRM#5188](Project-OSRM#5188)
- ADDED: Node bindings can return pre-rendered JSON buffer. [Project-OSRM#5189](Project-OSRM#5189)
- Profiles:
- CHANGED: Bicycle profile now blacklists barriers instead of whitelisting them [Project-OSRM#5076
](Project-OSRM#5076)
- CHANGED: Foot profile now blacklists barriers instead of whitelisting them [Project-OSRM#5077
](Project-OSRM#5077)
- CHANGED: Support maxlength and maxweight in car profile [Project-OSRM#5101](Project-OSRM#5101]
- Bugfixes:
- FIXED: collapsing of ExitRoundabout instructions [Project-OSRM#5114](Project-OSRM#5114)
- Misc:
- CHANGED: Support up to 512 named shared memory regions [Project-OSRM#5185](Project-OSRM#5185)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If you're using the NodeJS bindings with OSRM, and you're generating large responses, there can be significant overhead simply translating the OSRM JSON structure into a NodeJS object tree.
There are several use-cases where the next step you take is to simply render the NodeJS object into a JSON string, and send it over the network - using NodeJS as your OSRM HTTP server is one example of this.
This PR adds a new optional parameter to all the NodeJS API methods that allows you to configure the format of the response that OSRM returns. It defaults to the current object tree, but if you supply
{format: 'json_buffer'}, it will instead cause OSRM to pre-render the JSON tree on a worker thread, then return a NodeJSBufferobject containing the JSON response string.In cases where you only wanted to return the result to a client over the network anyway, pre-rendering the JSON has a significant speedup. It significantly unburdens the main NodeJS thread, allowing more concurrent work.
Timeline of a 5000x5000

tablerequest and serialization over the network before this change:Timeline of a 5000x5000

tablerequest and serialization over the network after this change:The
Main Threadhere represents the primary NodeJS event loop - less work done here means the event loop stays clear to handle i/O.The time spent in the
pthread_bodyhas increased slightly in the second image - this shows the additional time spent rendering the JSON outside the main thread.Tasklist
Requirements / Relations
Link any requirements here. Other pull requests this PR is based on?