This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 173
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
Possible memory leak in getMany? #790
Copy link
Copy link
Closed
Labels
more information neededFurther information is requestedFurther information is requested
Description
Hi,
first of all thanks for providing this awesome package!
I've noticed that memory usage is creeps up higher when using getMany vs pushing to an array with get.
Examples
Using .get and pushing to an array:
const crypto = require('crypto')
const path = require('path')
const level = require('level')
const db = level(path.resolve(__dirname, './db'))
async function main() {
for (let i = 1; i < 10; i++) {
const keys = []
for (let j = 0; j < 10000; j++) {
const key = `${i}:${j}`
keys.push(key)
await db.put(key, crypto.randomBytes(1000))
}
const values = []
for (const key of keys) {
values.push(await db.get(key))
}
const mem = process.memoryUsage()
console.log(i, Math.floor(mem.rss / 1024 / 1024))
await new Promise((resolve) => setTimeout(() => resolve(null), 1000))
}
}
main()$ node index.js
1 77
2 108
3 94
4 105
5 116
6 135
7 156
8 100
9 94Using .getMany:
const crypto = require('crypto')
const path = require('path')
const level = require('level')
const db = level(path.resolve(__dirname, './db'))
async function main() {
for (let i = 1; i < 10; i++) {
const keys = []
for (let j = 0; j < 10000; j++) {
const key = `${i}:${j}`
keys.push(key)
await db.put(key, crypto.randomBytes(1000))
}
const values = await db.getMany(keys)
const mem = process.memoryUsage()
console.log(i, Math.floor(mem.rss / 1024 / 1024))
await new Promise((resolve) => setTimeout(() => resolve(null), 1000))
}
}
main()1 81
2 127
3 155
4 178
5 142
6 140
7 142
8 151
9 146Running the examples multiple times shows that using getMany allocates more memory over time.
I know very little about memory leaks so let me know if I'm looking at this the wrong way! We've noticed our program eventually crashes because the memory keeps growing when using getMany (mabye) so wondering if this is expected behavior (it possibly could be something else in my application). Thanks!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
more information neededFurther information is requestedFurther information is requested