Skip to content

Commit 30f9254

Browse files
authored
Configure the channel pool to open a new channel when all of the currently open channels reach 100 subscriptions each (#3380)
1 parent 456b0be commit 30f9254

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/rpc-subscriptions/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Creates a function that returns new subscription channels when called.
2727
A config object with the following properties:
2828

2929
- `intervalMs`: The number of milliseconds to wait since the last message sent or received over the channel before sending a ping message to keep the channel open.
30-
- `maxSubscriptionsPerChannel`: The number of subscribers that may share a channel before a new channel must be created. Set this to the maximum number of subscriptions that your RPC provider recommends making over a single connection.
30+
- `maxSubscriptionsPerChannel`: The number of subscribers that may share a channel before a new channel must be created (default: 100). It is important that you set this to the maximum number of subscriptions that your RPC provider recommends making over a single connection; the default is set deliberately low, so as to comply with the restrictive limits of the public mainnet RPC node.
3131
- `minChannels`: The number of channels to create before reusing a channel for a new subscription.
3232
- `sendBufferHighWatermark`: The number of bytes of data to admint into the `WebSocket` buffer before buffering data on the client. -`url`: The URL of the web socket server. Must use the `ws` or `wss` protocols.
3333

packages/rpc-subscriptions/src/rpc-subscriptions-channel.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ export function createDefaultRpcSubscriptionsChannelCreator<TClusterUrl extends
4848
return getChannelPoolingChannelCreator(createDefaultRpcSubscriptionsChannel, {
4949
maxSubscriptionsPerChannel:
5050
config.maxSubscriptionsPerChannel ??
51-
// TODO: Determine this experimentally
52-
1_000,
51+
/**
52+
* A note about this default. The idea here is that, because some RPC providers impose
53+
* an upper limit on the number of subscriptions you can make per channel, we must
54+
* choose a number low enough to avoid hitting that limit. Without knowing what provider
55+
* a given person is using, or what their limit is, we have to choose the lowest of all
56+
* known limits. As of this writing (October 2024) that is the public mainnet RPC node
57+
* (api.mainnet-beta.solana.com) at 100 subscriptions.
58+
*/
59+
100,
5360
minChannels: config.minChannels ?? 1,
5461
});
5562
}

0 commit comments

Comments
 (0)