graphql-redis-subscriptions icon indicating copy to clipboard operation
graphql-redis-subscriptions copied to clipboard

make pubsub subRefsMap use maps and sets

Open tjmehta opened this issue 4 years ago • 3 comments

Simplify pubsub subscription-id state by using maps and sets

tjmehta avatar Dec 06 '20 00:12 tjmehta

Hey @tjmehta, Thanks for the PR! I'd love to merge this but can you fix the failing tests? Thanks ahead!

davidyaha avatar Dec 13 '20 12:12 davidyaha

cool was wondering if y'all would even want this.

I went off the deep-end and wrote my own module bc I was paranoid about memoryleaks https://github.com/tjmehta/graphql-ioredis-subscriptions (would you want me to bring in any of this functionality, like promise queues by triggerName?). I am still seeing memory leaks related to subscriptions in my application and I cannot repro in development. I even found some potential leaks in https://github.com/tjmehta/subscriptions-transport-ws/commit/6d425ba694939df4ee6ea32c22e1072dd06f82f5. Would love some tips if you've had issues with memory leaks around with graphql subscriptions.

tjmehta avatar Dec 18 '20 01:12 tjmehta

@davidyaha this PR should be passing tests now and ready to merge. For some context, my company experienced issues where we had around ~50k subscribers, and this was causing the array operations to be very slow when every a new subscriber joined, or one dropped off. For example, adding an ID to the array using the spread operator

[...refs, id]

was causing an array of ~50k elements to get fully copied. In our setup, these expensive copies were happening multiple times per second, causing a noticeable performance hit. The maps/sets remove the need for these expensive array operations.

thecodeboss avatar Feb 07 '22 23:02 thecodeboss

@davidyaha Any chance you'd consider merging this? Can help out where needed.

CutmanCometh avatar Nov 12 '22 01:11 CutmanCometh

Thanks, @tjmehta @thecodeboss for the PR! and Thanks @CutmanCometh for the willingness to help.

davidyaha avatar Dec 15 '22 19:12 davidyaha