Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Node-osmium run out of memory #79

Closed
matiasdahl opened this issue May 7, 2016 · 8 comments
Closed

Node-osmium run out of memory #79

matiasdahl opened this issue May 7, 2016 · 8 comments
Labels

Comments

@matiasdahl
Copy link

I have previously ran various node-osmium scripts that extract data from the full OpenStreetMap history. I have previously run these on an m3.medium instance on AWS with 3.75G of memory without any problems. Lately, however, these scripts run out of memory. Is it possible that some recent update has introduced a memory leak somewhere?

The instance setup is described here, and below is a simple example script that run out of memory:

"use strict";

var osmium = require('osmium');
var reader = new osmium.Reader("../history-160502.osm.pbf");
var handler = new osmium.Handler();

var object_handler = function(map_obj) {
  /* dummy handler. Print map id. */
  console.log(map_obj.id)
};

handler.on("node", object_handler);
osmium.apply(reader, handler);

By running top, I found that the script starts with around 25% of memory usage (out of 3.75G) and this slowly increases. After c. 20 mins, it is around 95% and a few minutes after that the process is aborted.

This is with Ubuntu 14.04.3 LTS (trusty), node version v0.10.25, and with the following npm packages installed:

├── [email protected]
├─┬ [email protected]
│ ├── [email protected]
│ └─┬ [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   ├─┬ [email protected]
│   │ └── [email protected]
│   ├─┬ [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ ├── [email protected]
│   │ │ └─┬ [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   └── [email protected]
│   │ └─┬ [email protected]
│   │   ├── [email protected]
│   │   ├─┬ [email protected]
│   │   │ ├── [email protected]
│   │   │ └── [email protected]
│   │   ├─┬ [email protected]
│   │   │ ├── [email protected]
│   │   │ └── [email protected]
│   │   └─┬ [email protected]
│   │     ├── [email protected]
│   │     └── [email protected]
│   ├─┬ [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ └── [email protected]
│   ├─┬ [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └─┬ [email protected]
│   │ │   ├── [email protected]
│   │ │   └── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └─┬ [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   └── [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └── [email protected]
│   │ ├─┬ [email protected]
│   │ │ ├─┬ [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ ├─┬ [email protected]
│   │ │ │ │ └── [email protected]
│   │ │ │ ├─┬ [email protected]
│   │ │ │ │ └── [email protected]
│   │ │ │ └── [email protected]
│   │ │ ├─┬ [email protected]
│   │ │ │ └── [email protected]
│   │ │ ├─┬ [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ ├─┬ [email protected]
│   │ │ │ │ └── [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ └── [email protected]
│   │ │ └─┬ [email protected]
│   │ │   └── [email protected]
│   │ ├─┬ [email protected]
│   │ │ ├── [email protected]
│   │ │ ├── [email protected]
│   │ │ ├── [email protected]
│   │ │ └── [email protected]
│   │ ├─┬ [email protected]
│   │ │ ├── [email protected]
│   │ │ ├─┬ [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ ├── [email protected]
│   │ │ │ └── [email protected]
│   │ │ └─┬ [email protected]
│   │ │   ├── [email protected]
│   │ │   ├─┬ [email protected]
│   │ │   │ └── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   ├── [email protected]
│   │ │   └── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ ├── [email protected]
│   │ └── [email protected]
│   ├─┬ [email protected]
│   │ └─┬ [email protected]
│   │   ├─┬ [email protected]
│   │   │ └── [email protected]
│   │   ├── [email protected]
│   │   ├─┬ [email protected]
│   │   │ └─┬ [email protected]
│   │   │   ├── [email protected]
│   │   │   └── [email protected]
│   │   ├─┬ [email protected]
│   │   │ └── [email protected]
│   │   └── [email protected]
│   ├── [email protected]
│   ├─┬ [email protected]
│   │ ├── [email protected]
│   │ ├─┬ [email protected]
│   │ │ └── [email protected]
│   │ └── [email protected]
│   └─┬ [email protected]
│     ├─┬ [email protected]
│     │ └── [email protected]
│     ├─┬ [email protected]
│     │ ├── [email protected]
│     │ └── [email protected]
│     ├─┬ [email protected]
│     │ ├── [email protected]
│     │ └─┬ [email protected]
│     │   └─┬ [email protected]
│     │     ├── [email protected]
│     │     └── [email protected]
│     ├─┬ [email protected]
│     │ └── [email protected]
│     ├─┬ [email protected]
│     │ ├── [email protected]
│     │ ├── [email protected]
│     │ ├── [email protected]
│     │ ├── [email protected]
│     │ ├── [email protected]
│     │ └── [email protected]
│     └── [email protected]
└── [email protected]

Please let me know if I can provide further details.

Thank you!

@matiasdahl
Copy link
Author

A workaround seems to use node-osmium v. 0.4.5 (and not the latest 0.5.0 used above). After running the above example script listed above for 25+ minutes, memory usage is stably around 23%.

@springmeyer
Copy link
Contributor

Is it possible that some recent update has introduced a memory leak somewhere?

Seems unlikely. Usually large memory growth is due to lots of objects being allocated in JS and the node.js/v8 garbage collector not cleaning them up in time before high memory usage occurs.

A workaround seems to use node-osmium v. 0.4.5 (and not the latest 0.5.0 used above).

Interesting - as long as you are using the same version of node that seems to indicate a leak could have been introduced in v0.5.0. What changed in v0.5.0 was 1) upgrade of libosmium from 2.6.0 to 2.6.1 and 2) ported the codebase to https://github.com/nodejs/nan. The port to nan is a much more likely culprit for memory leaks.

@matiasdahl
Copy link
Author

Yes, I used the same setup as before (node v.0.10.25 on an m3.medium running Ubuntu 14.04.3 LTS, trusty). The only exception was to use node-osmium v. 0.4.5 and not 0.5.0. Once I switched to 0.4.5 the memory problems disappeared (*).

(*) I ran this script on the full OSM history database without memory problems. This took around 45 hours.

@joto joto added the bug label Jul 21, 2016
@joto
Copy link
Member

joto commented Jul 26, 2016

I think there are two different issue here. The first, missing HandleScopes, I have fixed in master. With this fix your test program runs okay without the console.log() call. With the console.log() call, the program will stop outputting anything at some point but keep drawing memory. I am not sure what is happening here, but it does not happen when using the Stream interface instead of the Handler interface. This might have something to do with how node does I/O asynchronously, but console.log() should be synchronous, so I am not sure.

@matiasdahl can you check how the current version works for you?

@springmeyer
Copy link
Contributor

@matiasdahl - [email protected] is now published and ready for you to test.

@matiasdahl
Copy link
Author

Thank you very much. I did some testing, and the new 0.5.2 version of node-osmium seems to have fixed the memory issue in 0.5.0.

Using node-osmium 0.5.2 (installed via npm), I ran the short example script listed above that prints the id:s for all elements for around 40 mins using the same setup as earlier. Previously this ran out of memory after around 20 minutes. Now memory usage was rather constant and at around 25%.

@joto: I redirected the output to a file and I did notice that output would stop.

Thank you again, and let me know if I can provide other details.

@joto
Copy link
Member

joto commented Aug 3, 2016

I have opened a new issue #85 for the remaining problem and will close this one.

@joto joto closed this as completed Aug 3, 2016
@springmeyer
Copy link
Contributor

👍 @joto

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

No branches or pull requests

3 participants