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
pubsuffix.js using a lot of memory #48
Comments
Hi, Can you provide the numbers, please? Is it leaking or just constantly consuming some huge amount of memory? |
I think the later. Can i send the heap shot to your email (The one at your profile page)? |
So, I wrote a quick little script to try to figure this out because it came up in my tests for memory leak. https://github.com/Myztiq/cookie-leak I got here from bunyan-loggly -> loggly -> reuqest -> tough-cookie. Please let me know if there is anything obvious I might be missing here. |
@Myztiq i got pretty much the same path from request to tough-cookie Thank you! |
It looks like a super tiny memory leak though. But that might add up. |
On second thought, my cookie in the test is |
I have almost 13mb in an application that have 80mb on total, just at the start (without start running the heavy calls) |
With On further review with To verify you can run it from my branch I made to test it. https://github.com/Myztiq/cookie-leak/tree/node-inspector Instructions are in the readme.md |
I run your 2 branches in node-inspector. I can see the leak at Here is the heapsnapshoot. Look at the 3 first at |
I think it's just a problem of a single large object that pubsuffix.js creates. I pre-warm the cache in both by making a fake call before starting profiling, but it depends on when you hit it from node-inspector in master. @luanmuniz Also, if you remove console.logs throughout the code that I have you will notice the leak actually gets significantly better from |
I'd be pretty surprised if there was in fact a leak because this is a core dependency of |
The snapshot i sent is from the master branch at almost 90%. Well, it can be |
@luanmuniz Yes, but did you snapshot it when it was sitting at 100% long enough to garbage collect? While it's pounding the machine as fast as possible making new objects I am sure you will encounter a high amount of memory churn, but the problem will be when the churn is over, did the memory go back to normal. If it doesn't thats a leak, if it does its just a high memory intensive application. The problem is when it doesn't go back down, if it doesn't we know that the system won't be stable for extended periods of time. |
I have just sent the PR above with a forced GC. and i got the same result :( |
Hey folks. I finally have a bit of time to look at this today. I'll try to review what's been found and see if I can reproduce it. |
So, I made this script and played with node-inspector: var tough;
var N = 1000000;
console.log('waiting');
process.stdin.once('data', load);
function load() {
tough = require('./lib/cookie.js');
console.log('loaded, waiting');
process.stdin.once('data', phaseOne);
}
function parseABunch(seed) {
var result = seed;
for (var i = 0; i < N; i++) {
var numbers = ("" + Math.random()).replace(/^\d\./,'');
var cookie = tough.parse('a='+numbers+'; domain=xyz.google.com; path=/');
result ^= parseInt(cookie.value, 10);
}
return result;
}
function phaseOne() {
var result = parseABunch(42);
console.log('done '+N+' parses, waiting (ignore:' + result + ')');
process.stdin.once('data', phaseTwo);
}
function phaseTwo() {
var result = parseABunch(4242);
console.log('done '+N+' parses, waiting (ignore:' + result + ')');
process.stdin.once('data', done);
}
function done() {
console.log('exiting', tough);
process.exit(0);
} Here's as screenshot of the memory profile:
Loading the library is the big spike, the first million parses is the tiny blip around ~11s. The second parse of a million cookies (and prompt to hit a key) only adds 4.1KB to the heap. As far as I can tell, looking at retainers, loading tough cookie seems to retain 670KB. I think almost half of that is the source code ( Meta: there seems to be a new MIT-licensed public suffix library on the block: https://github.com/wrangr/psl -- wonder how this would change things (it uses the JSON-loading technique, not a source-generator technique like tough cookie does) |
lol, wrong screenshot |
@luanmuniz @Myztiq can you folks still reproduce this? Is there something significantly different from the script I used and the ones you used to test? Something to do with Logly or request? |
@stash-sfdc There is no memory leak for me as I mentioned earlier in the thread. Essentially there is a big memory usage upfront but no leak. It was just showing up as top on my stack because it was getting destroyed and re-created in my system so it showed up as a new big memory add (I later found the big memory remove). The node-inspector branch that I have linked to above does not show a memory leak. 👍 |
I came here with a similar idea as other people who have reached this point. I think the reason we believe pubsuffix.js is the culprit for a lot of memory is that we see it multiple times within a heapdump analysis. For our application this is entirely caused by the fact that a lot of major NPM packages include tough-cookie (by way of |
Adding to this. In Node v0.12.7, my app has a huge memory leak. After a few minutes of a few thousand people hitting it it will die from memory consumption. Node-inspector lead me to pubsuffix.js, which led me to this page. If I hit any route, including one serving static content through express, the memory leak occurs. I upgraded to Node v4.x and I don't see the problem, which is weird. Hopefully this helps narrow down the issue. |
For me in either Node v4.2.2 or v0.12.7, I have the exact same problem with a ton of repeated memory consumption by pubsuffix.js. Memory usage is comparable for both versions. |
Hi Guys, sorry that took so long to respond here.
And this is for v4.2.1
This is the same application, the only difference is the node version and i had to use |
@luanmuniz were you able to deploy in production? how? as of today's release, Meteor 1.3 only supports node v0.10.41. Deploying to a node 4.x.x or higher will result to a fibers@1.0.5 dependency error. |
@ianpogi5 The module i was using was
|
Having this issue as well - node 4.2.4, also node 4.4.7 |
I have the same problem in v6.6.0. What is the purpose of pubsuffix and why you need to use 8k domains such as: google, yahoo, yandex, zipoo??? amazon etc. Thank you! |
@marko-jankovic the use of public suffixes is important for security. Without them, different domains could alter each others cookies. |
Can that file be imported lazily so its only using memory when it is actually needed (when either |
tough-cookie moved to |
Hi Guys,
I had a memory leak in my application and debugging it i found a few problems.
beside the leak in question i found that
pubsuffix.js
is taking a lot of memory allocation.I don`t know if i have read the logs correctly but it is a big allocation in arrays and strings.
Tracking problems i found the following issues that i think are related:
request/request#792
#12
Is there anyway we can improve the code?
if you guys want, i can send a heapshoot from my application
The text was updated successfully, but these errors were encountered: