Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Memory leak? #6

Open
stuartlynn opened this issue Apr 26, 2017 · 13 comments
Open

Memory leak? #6

stuartlynn opened this issue Apr 26, 2017 · 13 comments

Comments

@stuartlynn
Copy link

Running geojson2mvt on a large region tends to crash with the javascript heap size limit being reached. I think something is leaking memory in there. Plot shows heapsize vs tile number. You can see the Garbage collection working but its not grabbing everything.

heap

Not sure if this is an issue in geojson2mvt or one of the required libraries but investigating.

@gijs
Copy link

gijs commented Apr 26, 2017

This tool is exactly what I need! Too bad I'm having similar issues with enormous GeoJSON files.

Maybe we can use streaming instead of parse() and parse the geojson file line by line?

var geoJson = JSON.parse(fs.readFileSync(filePath, "utf8"));

@chriswhong
Copy link

Hi all, could either of you let us know the enormity of the data you're trying to bring in? Are we talking hundreds of thousands or millions of vertices? I would love to test as well and see if I can help.

@chriswhong
Copy link

@stuartlynn for my education, can you tell me how you produced that heap size chart? Is there a node package that does it, or did you pull the data somehow and chart it elsewhere?

@gijs
Copy link

gijs commented Apr 26, 2017

The GeoJSON file I'm attempting to convert is 1.08 GB. It contains every farming parcel in the Netherlands. I guess we're in the millions of vertices then?

@chriswhong
Copy link

I feel like any workflow dealing with files that big will be riddled with problems. I think the tools that can generate tiles from a database might be a better option for a dataset that large. https://github.com/mapbox/awesome-vector-tiles

@stuartlynn
Copy link
Author

stuartlynn commented Apr 26, 2017

Hey @chriswhong it's super easy

process.memoryUsage().heapUsed

super useful. Trying to get heap dumps to see what's leaking.

I don't think its the size of the data in memory, for example, my file is just 77mb. It's the number of tiles you want that's the problem I think.

Every time through the inner loop that generates the tiles, something is allocating memory that's getting lost and not deallocated properly. It might be in one of the deps rather than your code. Trying to track it down.

@stuartlynn
Copy link
Author

Ok looks like it might be all the fs.writeSync calls. Looking at the heap the system objects account for the huge size.

screen shot 2017-04-26 at 6 38 04 pm

Going to try and rewrite it a little to use async write and potentially a pool of workers? See if that helps

@stuartlynn
Copy link
Author

also huge thank you to @rochoa for showing me how to debug node better. If you use

node --debug --inspect convert.js

It will give you a URL in chrome you can use with the standard chrome tools to debug

@chriswhong
Copy link

@stuartlynn Thanks for the tips, and the worker pool sounds like a good idea, I look forward to seeing how you go about it.

@SKalt
Copy link

SKalt commented Dec 14, 2017

Looks like geojson-vt's internal tile generation is caching all generated tiles (see geojson-vt#L82). I'm currently rolling my own implementation to recursively save lower-zoom tiles, then delete them from the index along with the parent tile.

@gijs
Copy link

gijs commented Dec 15, 2017

FYI We've moved to using the ST_AsMVT function in PostGIS to generate our vector tile pyramids.

@stuartlynn
Copy link
Author

That's what I ended up doing as well. Would still be good to have a version of geojson2mvt that can handle large files. @SKalt happy to help with that implementation if you need it.

@SKalt
Copy link

SKalt commented Dec 15, 2017

I hadn't heard about the ST_AsMVT function, that's extremely useful. @stuartlynn Thanks! The work is at skalt/store-mvt currently. I'm using the issues tab for my to-do list until the project is ready to be published.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants