-
Notifications
You must be signed in to change notification settings - Fork 309
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
leak from plugin when using toString on large data #401
Comments
@mcollina Any high level thoughts on this? |
FWIW, here are some relevant node.js bugs: |
Also, I changed generateLargeBuffer() to use 10% of the size, 4363201, |
And changing generateLargeBuffer() to use a smaller size buffer of 4*1024, with enough calls to match the volume of memory of the preceding ~4MB test, yields similar results.
So it doesn't appear to be related to the size. |
And I have confirmed that when I rework my main program |
does this also happen with |
Let me try that and get back. |
@psnider I suggest you to reconsider your architecture. Sending 40MB of data from Node.js will likely cause you problems in other places as well. The solution to this issue is uploading that file to S3 or another blob storage, and then send a URL to your caller. Given that there are no leaks for small strings, I presume it's some bad interaction with long strings and Seneca. There are quite a few |
I agree that 40MB is too large, but I have no control over what the external service sends.
Are you suggesting that 4k is a long string? If so, what is a reasonable maximum length? |
Receiving 40MB in your process for a live transaction is probably a bad idea anyway. You will get a much more performing user experience by 1) having the client return an original URL or 2) uploading that data somewhere else in a batch/queue fashion. Regarding the bug, I expressed myself badly. Given there is no problem with "normal" strings and objects, this should be tightly correlated with buffers. Also, why you need to convert it to a String? Keeping it as a buffer will definitely help in memory management. |
I believe that there is a serious memory leak in this use case. BTW, I worked carefully on the examples I gave in the initial report to decouple it from all other aspects of my app. |
@psnider Let me first check the cache stuff, if that's the issue it's fairly simple to fix. I'll report back soon. |
I need to consider how to handle very large messages in terms of graceful degredation. |
See also: #627 |
I've encountered a severe memory leak when an external service started sending very large XML responses (~40MB).
Note that there are some bug reports in node with very large strings leaking, but they must be around 250MB, and seem to be unrelated to this issue. Also , I couldn't reproduce this problem when I don't use seneca.
node v5.0.0
seneca ^1.3.0
Here is minimal code I use from a REPL that reproduces the issue reliably.
Enable garbage collection API to help with testing:
node --expose-gc
Find the base heap size:
For me this gives: { rss: 52281344, heapTotal: 32966400, heapUsed: 26,996,888 }
Then excercise the above code from the REPL with combinations of tests and measurements and running the GC.
Wait for the tests to finish, then run:
For me this gives: { rss: 293875712, heapTotal: 152241920, heapUsed: 115,433,200 }
Verify that this memory can be reclaimed by running the GC:
For me this gives: { rss: 182329344, heapTotal: 31946496, heapUsed: 26,413,976 }
So it appears that memory is reclaimed correctly.
Now switch to performing the toString() from within the plugin:
Again, wait for the tests to finish, then run:
For me this gives: { rss: 527720448, heapTotal: 206558208, heapUsed: 198,439,760 }
Now confirm that the GC cannot reclaim this memory any longer.
For me this gives: { rss: 523902976, heapTotal: 204523008, heapUsed: 198,208,656 }
In contrast to before, it has dropped only by about 200k !
The text was updated successfully, but these errors were encountered: