Connection issue #54

Closed
runk opened this Issue Aug 8, 2012 · 6 comments

Projects

None yet

4 participants

@runk

Hi all,

Looks like that something in code does not work properly and I'm having an error when I'm trying to run many commands at once:

    var Memcached = require('memcached');
    var _client = new Memcached('localhost:11211');

    for (var i = 0; i < 100; i++) {
        _client.set('test' + i, 'value', 1000, function(err, res) {
            if (err) throw err;
            else console.log('ok');
        });
    };
Error: All the connections in the memcached pool are busy

However the following code works splendidly:

   _client.set('foo', 'bar', 1000, function(err, res) {
        for (var i = 0; i < 100; i++) {
            _client.set('test' + i, 'value', 1000, function(err, res) {
                if (err) throw err;
                else console.log('ok');
            });
        };
    });

I think the problem because in the first example, library tries to connect 100 times (because there was no connection). In contract, in the second example library is already connected and do not perform another 100 attempts to connect.
Hope that helps!

@3rd-Eden
Owner

Thanks for the information. I have already actively working on refactoring parts of the memcached driver and extracted and refactored the connection handling as part of that: https://github.com/3rd-Eden/jackpot

But I suspect that the new version will not solve this issue either.. Because I'm not queueing allocations when we are generating a new connection. Not sure what would wise to fix this issue..

@euskode

I wonder if this is related to an issue I am seeing.

Despite setting the poolSize to values greater than the default, I am only seeing a single TCP connection being established to memcached. So when my backend is receiving hundreds of requests per second, it's still putting them through a single socket, as this is what node-memcached seems to do.

Is this intentional?

@3rd-Eden
Owner

@euskode That is odd-sh, the way the connection pool works is that if we cannot write to the connection (if it's busy processing) we create another connection.

Anyways, I have created a new branch that implements 3rd-Eden/jackpot as connection pool. @euskode @runk this might solve both of your issues. Could you check it out?

You can add https://github.com/3rd-Eden/node-memcached#jackpot in your package.json instead of a version number so it gets this version from github instead of the npm registry.

@mridgway

I am facing the same error. I tried out the 'jackpot' branch and I no longer get the error with the same code as before.

@3rd-Eden
Owner
@3rd-Eden
Owner

Merged the Jackpot branch in to master, should be fixed in 0.1.1

@3rd-Eden 3rd-Eden closed this Oct 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment