apollographql / graphql-subscriptions

:newspaper: A small module that implements GraphQL subscriptions for Node.js
MIT License
1.59k stars 133 forks source link

default pubsub scaling limitations #207

Closed slmyers closed 5 years ago

slmyers commented 5 years ago

Note that the default PubSub implementation is intended for demo purposes. It only works if you have a single instance of your server and doesn't scale beyond a couple of connections. For production usage you'll want to use one of the PubSub implementations backed by an external store. (e.g. Redis)

Can someone please ELI5 (or give me hints on where to look, currently looking at Node EventEmitter as issue) why the default implementation "doesn't scale beyond a couple connections" and how I could make it scale better (although to a still relatively small amount) on a single server. Please and thank you.

context: I work on an app that is shipped to run on client premises which are each smaller businesses without many concurrent users.

grantwwu commented 5 years ago

I'm not completely clear, to be honest. I think one issue you may run into is that the default number of listeners that can be added before warnings are printed is 10: https://nodejs.org/api/events.html#events_eventemitter_defaultmaxlisteners

Another issue is that (https://nodejs.org/api/events.html#events_events)

When the EventEmitter object emits an event, all of the functions attached to that specific event are called synchronously. Any values returned by the called listeners are ignored and will be discarded.

So EventEmitter may not be suited for instances where you serve a large number of connections listening on a particular event.

slmyers commented 5 years ago

Thanks again for the help. I'm closing this issue to avoid clutter.