d-exclaimation / pioneer

GraphQL for Swift.
https://pioneer.dexclaimation.com
Apache License 2.0
40 stars 8 forks source link

Does Pioneer support multiplexing subscriptions over one WebSocket connection? #142

Open cshadek opened 7 months ago

cshadek commented 7 months ago

Does Pioneer support multiplexing multiple subscriptions over one WebSocket connection?

This is relevant when a client wants to subscribe to a high number of subscriptions.

d-exclaimation commented 7 months ago

Pioneer only opens 1 WebSocket connection for each client and uses either graphql-ws or subscriptions-transport-ws protocol to handle multiple subscription operations within that 1 connection.

If you notice that this isn't the case, let me know and I'll try to get it fixed

cshadek commented 7 months ago

Got it. I assumed as much but I wasn't sure.

Do you know if there is any downside to having many subscriptions open at the same time from a client?

I am using Redis PubSub.

d-exclaimation commented 7 months ago

Not quite sure if there would be obvious problems having many subscriptions open. I haven't done many tests with a significantly large number of subscription operations active

cshadek commented 7 months ago

So, if I understand correctly the protocol handles multiplexing from the client and Pioneer Redis PubSub's Broadcast makes sure there is only one Redis connection per topic?

cshadek commented 7 months ago

And if that's the case, in https://github.com/d-exclaimation/pioneer-redis-pubsub/issues/8,

Maybe the answer is that in:


let redisConfig = try RedisConfiguration(
            url: redisUrl,
            tlsConfiguration: nil,
            pool: .init(
                maximumConnectionCount: .maximumActiveConnections(10),
                minimumConnectionCount: 0,
                connectionBackoffFactor: 2,
                initialConnectionBackoffDelay: .microseconds(100),
                connectionRetryTimeout: .milliseconds(100)
            )

Then maximumConnectionCount needs to be at least as great as the number of subscription types that the GraphQL API offers.

I'm assuming the number of Redis connections is not based on the number of clients and only on the number of unique subscription topics.

d-exclaimation commented 7 months ago

The protocol handle multiplexing of subscriptions on both the client and server on but only at the network/API level.

RedisPubSub and PubSub also try to multiplex Redis subscriptions for each channel. RedisPubSub will multiplex all async stream of the same channel to 1 RediStack subscription, so basically 1 RediStack subscription for every GraphQL subscription of the same channel.

The number of connections to Redis is dependent on how RediStack handle channel subscriptions and I don't know if they make a new Redis connection for each channel subscriptions.