ncb000gt / node-es

NodeJS module for ElasticSearch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EventEmitter Listeners when a lot of concurrent query

tchiotludo opened this issue · comments

When a lot of concurrent query and async queries are done at the same time, Node raise en error :

(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
    at Socket.EventEmitter.addListener (events.js:160:15)
    at Socket.Readable.on (_stream_readable.js:689:33)
    at ClientRequest.<anonymous> (E:\Web\node\node_modules\elasticsearch\lib\request.js:150:12)
    at ClientRequest.EventEmitter.emit (events.js:117:20)
    at http.js:1758:9
    at process._tickCallback (node.js:415:13)

To have this error, i have like 1000 queries in 1 sec, so I guess I have 11 concurrent queries.

Is it possible to adjust the setMaxListeners with the number of concurrent queries ?

The error occurs on the 11th listener added. Have you tried raising the max to see how many are used at the level of concurrency you're running?

We may not be handling listeners as well as we could be, or the max may just need to be raised. See the following fairly recent relevant conversations across various Node.js projects:

I made a test on file : /elasticsearch/lib/request.js line 147

// timeout the connection
if (options.timeout) {
  req.on('socket', function (socket) {
    console.log(EventEmitter.listenerCount(socket, "timeout"));
    socket.setTimeout(options.timeout);
    socket.on('timeout', function () {
    });
  });
}

le console.log output look like :

170
171
176
175
183
171
172
184
176

The EventListener are destroyed but to late I think.

Look at this commit : https://github.com/tchiotludo/node-es/commit/07c76235bca0581d4d32a9d3cd6e0bac22e8df32

No more error are rise but full free to verify if the timeout are still available

@tchiotludo Would you mind submitting this in a pull request?

Just done :)

Is there any updates on/fixes for this? I'd like to know as I need to pump data into ES as close to realtime as possible, but the service load is not consistent (ie: periods of super low traffic punctuated by periods of saturated throughput). Possibly just expose the maxListeners property on the http object via a configuration option?