-
Notifications
You must be signed in to change notification settings - Fork 641
use array instead of event emitter for queuing requests #223
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
Conversation
Maybe we can just do this? http://nodejs.org/api/events.html#events_emitter_setmaxlisteners_n |
|
What limit would we set? Would this limit be sufficient for all cases and why? |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
The error is: |
|
No memory leak, just a low value set by default. I would set the limit to 0 for unlimited. |
|
@jkingyens can you show the code you used that triggered this error? I'm curious how so many connections were queuing up. Regardless, I'm preparing a PR with setMaxListeners(0) and would appreciate if you could test it :) |
Node's default limit for max listeners on an event emitter is at a low 10. We are using an event emitter internally in the Connection class to handle queueing callbacks for the token retrieval event. The default of 10 is now lifted to unlimited, so the developer doesn't have to worry about overriding the default themselves. Fixes googleapis#223
|
I am queuing up requests for GCE account activity available in daily JSON records from google cloud storage. Since its Sept 18th, I would have sent out 18 requests in parallel for the data. I don't want any uneccessary serialization as to keep latency for the query very low. In general, I think using event emitters to buffer up async callbacks makes for less readable code. The buffering technique that I used here is the way I see things normally done and the advantage is its very readable. If you look at node.js modules like mongoose this is the way they do things. If you make a mongodb request before a mongo connection becomes active, it queues using this method. https://github.com/LearnBoost/mongoose/blob/master/lib/connection.js#L447-L450 |
|
The tests are failing as well so I would have to fix that too. |
|
We started out with a similar technique, but queuing behavior is built into Node with event emitters. No need to re-invent the wheel. Happy to hear other opinions, however. |
|
IMO, its not built-in. If it was, it wouldn't need a workaround like setMaxListeners(0) in order to make it work correctly. What you are essentially doing is turning off the node.js warning mechanism that something isn't quite right. Does that sound good to you? |
Google around. It's a known ridiculous low limit. |
|
Fair enough. I just think the large accumulation of events in a single event emitter object is a bad smell and is why these limits are in place and haven't been removed at any point due to some kind of annoyance. Its probably more personal preference then anything else and I just want to get off my fork and have the problem go away, so whatever works is fine with me :) |
|
thanks! |
|
We need to address the setMaxListeners(0) concern, but published this hotfix as 0.7.1. |
* chore: update jsdoc - protos and double quote * chore: update jsdoc - protos and double quote Co-authored-by: Alexander Fenster <github@fenster.name>
… node can be used with profiler. (#223) * fix: make version restrictions a warning instead of an error * coerce version
… node can be used with profiler. (#223) * fix: make version restrictions a warning instead of an error * coerce version
use a node.js array to queue up pending callbacks when requests are made before the token is fetched. The current mechanism uses an event emitter to add listeners, which can cause warnings when there is a buildup of requests during the initialization phase:
node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Connection.addListener (events.js:160:15)
at Connection.once (events.js:185:8)
at Connection.createAuthorizedReq (/Users/jkingyens/reach_system/node_modules/gcloud/lib/common/connection.js:272:8)
at Connection.req (/Users/jkingyens/reach_system/node_modules/gcloud/lib/common/connection.js:230:8)
at Bucket.makeReq_ (/Users/jkingyens/reach_system/node_modules/gcloud/lib/storage/index.js:572:19)
at Bucket.stat (/Users/jkingyens/reach_system/node_modules/gcloud/lib/storage/index.js:269:8)
at Bucket.createReadStream (/Users/jkingyens/reach_system/node_modules/gcloud/lib/storage/index.js:404:8)
at /Users/jkingyens/reach_system/Gruntfile.js:48:31
at /Users/jkingyens/reach_system/node_modules/async/lib/async.js:125:13
at Array.forEach (native)