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

fix blocking of tileserver while serving index #529

Closed
wants to merge 1 commit into from

Conversation

candux
Copy link
Contributor

@candux candux commented Mar 11, 2021

we noticed sporadic long blocks of the entier tileserver on version 3.1.1
They always happend when somebody accessed the frontPage.
Our guess is, that clone() blocks the object and takes very long to finish.

We replaced the clone with ES6 magic from https://stackoverflow.com/a/42988763
and the problem is gone.

Also the time to generate the index goes from ~3s to ~0.2s
This should primarily affect user with many large styles

we noticed sporadic long blocks of the entier tileserver on version 3.1.1
They always happend when somebody accessed the frontPage.
Our guess is, that clone() blocks the object and takes very long to finish.

We replaced the clone with ES6 magic from https://stackoverflow.com/a/42988763
and the problem is gone.

Also the time to generate the index goesm from ~3s to ~0.2s
This should primarily affect user with many large styles
@mnutt
Copy link
Contributor

mnutt commented Apr 7, 2021

Object.assign() does a shallow copy, meaning only the top-level styles object is duplicated, while the clone module does a deep clone. Looking at the code following it, I think it's fine to leave the top-level alone and Object.assign the individual styles:

serveTemplate('/$', 'index', req => {
    for (const id of Object.keys(serving.styles || {})) {
      const style = Object.assign({}, styles[id]);
      style.name = (serving.styles[id] || serving.rendered[id] || {}).name;
      style.serving_data = serving.styles[id];
      style.serving_rendered = serving.rendered[id];
      ...

Then the same can be done with data.

acalcutt added a commit to WifiDB/tileserver-gl that referenced this pull request Oct 13, 2023
Based on maptiler#529 . might fix slow load due to tile cache

Signed-off-by: Andrew Calcutt <[email protected]>
@acalcutt acalcutt mentioned this pull request Oct 13, 2023
@acalcutt
Copy link
Collaborator

This should be fixed by #1009 . In that PR I have added a similar fix to index which does a more shallow array copy in https://github.com/WifiDB/tileserver-gl/blob/fa3dac46ca69ede31635867c4612dbf1a5b5decc/src/server.js#L450-L538

I am closing this PR now since it is no longer needed.

@acalcutt acalcutt closed this Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants