-
Notifications
You must be signed in to change notification settings - Fork 851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A channel pool #3310
A channel pool #3310
Conversation
|
// Start from the item two positions after the current item. This way, the | ||
// search will finish on the item after the current one. This ensures that, if | ||
// any channels tie for having the most capacity, the one that will be chosen is | ||
// the one immediately to the current one's right (wrapping around). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but I think this is only true if the channel immediately to the current one's right is part of the tie.
Consider the following channel scenarios:
A(1), B(1), C(1), D(1)
whereA
is the current one. Then hereB
is the next one because they are all tied.A(5), B(5), C(1), D(1)
whereA
is the current one. Then hereD
is the next one whereas we were probably expectingC
as per the rotation principle.
Wouldn't it be better to just do ii + 1
but then have a strict greater than in the condition below (i.e. mostFreeChannel.subscriptionCount > nextPoolEntry.subscriptionCount
)? That way, we only override if the next one is better (i.e. less subscribed to).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty insane, but in this case:
A(5), B(5), C(1), D(1) where A is the current one. Then here D is the next one whereas we were probably expecting C as per the rotation principle.
A
can't be the current one, because the next-free-channel is chosen ahead of time. The next free channel would always be C
or D
depending on where we were in the rotation.
Next free channels are chosen:
- as a last step, after one is added.
- as a last step, after one is removed.
The next time that a channel is added, it goes right where the freeChannelIndex
points, no questions asked.
I think covered all the weird cases in the tests, but let me know if you can think of one that breaks things!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the second scenario cannot happen due to how this function is being used within the decorator.
I think that's fine since we've got good test coverage but wouldn't it be better for maintainability if this function alone was responsible for keeping all the invariants of finding the next channel regardless of how it is being called?
packages/rpc-subscriptions/README.md
Outdated
@@ -18,6 +18,16 @@ This package contains types that implement RPC subscriptions as required by the | |||
|
|||
## Functions | |||
|
|||
### `getChannelPoolingChannelCreator({ createChannel, maxSubscriptionsPerChannel, minChannels })` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is essentially a channel creator decorator, how would you feel about making the createChannel
attribute a proper argument so it can be piped more easily?
Something like:
const channelCreator = pipe(
getMyOriginalChannelCreator(),
cc => getChannelPoolingChannelCreator(cc, { ... }),
)
fd5fc49
to
1ac504b
Compare
1b2a7ce
to
8350c40
Compare
a721e9a
to
2883f22
Compare
8350c40
to
17b642b
Compare
2883f22
to
3007e83
Compare
17b642b
to
e6b409a
Compare
3007e83
to
12931ce
Compare
e6b409a
to
4f256c9
Compare
4f256c9
to
244fdd7
Compare
12931ce
to
994441a
Compare
244fdd7
to
78d9c24
Compare
78d9c24
to
8e4edda
Compare
Merge activity
|
Summary
This is a special
RpcSubscriptionsChannelCreator
that creates a pool of underlying channels up tominChannels
, reuses them evenly up tomaxSubscriptionsPerChannel
, and tears the channels down when all of its subscribers abort.