anycable / graphql-anycable

A drop-in replacement for GraphQL ActionCable subscriptions. Works with AnyCable.
MIT License
107 stars 16 forks source link

Add support for GraphQL-Ruby 1.11+ Broadcasts #13

Closed Envek closed 3 years ago

Envek commented 4 years ago

Originally asked by @bdsimmons in our Gitter chat here: https://gitter.im/anycable/Lobby?at=5f2325cc03d73b60ee57852e

Documentation: https://graphql-ruby.org/subscriptions/broadcast

bdsimmons commented 4 years ago

@Envek Any updates on this?

stereoscott commented 4 years ago

We are looking into this, too. We've benefited from GraphQL-Ruby broadcasts quite a bit, but have been hitting messaging delays from ActionCable when we get lots (4k+) of concurrent subscribers. Right now we run ActionCable in a standalone Rack app so we can scale that out independently on its main app, but it still suffers from delays. If we figure out the right spots in the code to address this, we'll share our results here. Right now we still have a lot to discover around the internals of both Anycable and the broadcast functionality in the GraphQL gem.

Envek commented 4 years ago

Please take a look at draft implementation at https://github.com/anycable/graphql-anycable/pull/15 and try to use it.

I haven't tested it on real applications yet.

@bdsimmons thank you for heads up. I was able to dive into graphql-ruby broadcasts only on this week.

mjthompsgb commented 3 years ago

@Envek thanks for looking into the broadcasts stuff. I'm working with @bdsimmons on the GraphQL Ruby project. I have tried to implement your changes from this PR but it seems the subscription data isn't getting stored in Redis.

If I go from a working branch without broadcast to the broadcast branch I get this error. It is trying to find a particular key in Redis but it doesn't exist.

2020-12-22T03:46:47.922Z pid=40210 tid=ovh2cw1kq WARN: {"context":"Job raised exception","job":{"retry":true,"queue":"default","class":"TableInfoWorker","args":[1,24],"jid":"2fcf4076d80d2a754b6fbecd","created_at":1608608807.9127119,"enqueued_at":1608608807.912777},"jobstr":"{\"retry\":true,\"queue\":\"default\",\"class\":\"TableInfoWorker\",\"args\":[1,24],\"jid\":\"2fcf4076d80d2a754b6fbecd\",\"created_at\":1608608807.9127119,\"enqueued_at\":1608608807.912777}"}
2020-12-22T03:46:47.922Z pid=40210 tid=ovh2cw1kq WARN: TypeError: no implicit conversion of nil into String
2020-12-22T03:46:47.922Z pid=40210 tid=ovh2cw1kq WARN: /Users/matt/.rvm/gems/ruby-2.6.6/gems/json-2.3.0/lib/json/common.rb:156:in `initialize'
/Users/matt/.rvm/gems/ruby-2.6.6/gems/json-2.3.0/lib/json/common.rb:156:in `new'
/Users/matt/.rvm/gems/ruby-2.6.6/gems/json-2.3.0/lib/json/common.rb:156:in `parse'
/Users/matt/.rvm/gems/ruby-2.6.6/gems/graphql-1.11.6/lib/graphql/subscriptions/serialize.rb:21:in `load'
/Users/matt/.rvm/gems/ruby-2.6.6/bundler/gems/graphql-anycable-bacdd5edfab5/lib/graphql/subscriptions/anycable_subscriptions.rb:162:in `block in read_subscription'

If I flush Redis completely, then try it, nothing happens, no errors, nothing. Assuming that is because nothing is getting stored in Redis.

Any thoughts on what could be happening?

Envek commented 3 years ago

Released in v1.0.0