node-maxmind icon indicating copy to clipboard operation
node-maxmind copied to clipboard

GEOIP_CHECK_CACHE

Open angleman opened this issue 13 years ago • 5 comments

I see the GEOIP_CHECK_CACHE flag is defined internally but it doesn't appear it's being used. Is this something that is going to be supported? As I understand it, this flag: Checks for updated database. If database has been updated, reload file handle and/or memory cache.

This would be helpful as currently when the database updated and you re-init(), there appears to be a memory leak.

Thoughts?

angleman avatar Sep 04 '13 23:09 angleman

Yeah, the update of db on-the-fly isn't supported yet. I'll try to find time to add this feature to the module.

How did you understand that you got a memory leak?

runk avatar Sep 04 '13 23:09 runk

@runk, thanks for considering the on-the-fly support. To get the memory leak I used a timer to do maxmind.init() and then watched the logging of process.memoryUsage() and it was constantly dropping. In answer to your inquiry I put together the following:

var maxmind = require('maxmind');
var handle;
var prior   = -1;

function init() {
    clearTimeout(handle);
//  delete maxmind;
//  maxmind = require('maxmind');
    maxmind.init('GeoLiteCity.dat', { indexCache: true });

    var up = Math.floor(process.uptime() / 60);
    if (up > prior) {
        prior            = up;
        var mem          = process.memoryUsage();
        var humanize_mem = {
            uptime: up + ' min',
            rss:       Math.floor(mem.rss / 1000000) + 'M',
            heapTotal: Math.floor(mem.heapTotal / 1000000) + 'M',
            heapUsed:  Math.floor(mem.heapUsed / 1000000) + 'M',
        }
        console.log(humanize_mem);
        if (up>14) {
            process.exit(1);
        }
    }
    handle = setTimeout(init, 1);
}

handle = setTimeout(init, 1);

And I received the following with node 0.10.17:

{ uptime: '0 min', rss: '28M', heapTotal: '6M', heapUsed: '3M' }
{ uptime: '1 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '2 min', rss: '31M', heapTotal: '8M', heapUsed: '3M' }
{ uptime: '3 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '4 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '5 min', rss: '31M', heapTotal: '8M', heapUsed: '3M' }
{ uptime: '6 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '7 min', rss: '31M', heapTotal: '8M', heapUsed: '3M' }
{ uptime: '8 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '9 min', rss: '31M', heapTotal: '8M', heapUsed: '4M' }
{ uptime: '10 min', rss: '31M', heapTotal: '8M', heapUsed: '3M' }
{ uptime: '11 min', rss: '31M', heapTotal: '8M', heapUsed: '3M' }
{ uptime: '12 min', rss: '31M', heapTotal: '9M', heapUsed: '5M' }
{ uptime: '13 min', rss: '31M', heapTotal: '9M', heapUsed: '3M' }
{ uptime: '14 min', rss: '31M', heapTotal: '9M', heapUsed: '4M' }
{ uptime: '15 min', rss: '31M', heapTotal: '9M', heapUsed: '4M' }

As you can see, during the first minute of thousands of iterations, there is some memory usage; however, in this zoomed out perspective over time; the memory usage appears to settle. I obtained the same results both with and without commented out lines. So in short, there doesn't appear to be a memory leak that I'm seeing. Sorry for the miss :-D

angleman avatar Sep 06 '13 23:09 angleman

Thanks for sharing, I'll check it later today. :+1:

runk avatar Sep 07 '13 00:09 runk

Hey @angleman, I've added this feature, could you please give it a try?

Cheers

runk avatar Sep 10 '13 12:09 runk

Just had an opportunity to check this out. Nice :-) I'll look into integrating it into the maxminded package that I've been working on. It's a scheduled auto update and failover layer. If you've an opportunity, I'd appreciate your thoughts on it.

angleman avatar Sep 16 '13 21:09 angleman