Skip to content
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

The relationship between ManagedChannel, InternalSubchannel and netty channel #11736

Closed
hlx502 opened this issue Dec 10, 2024 · 3 comments
Closed
Labels

Comments

@hlx502
Copy link
Contributor

hlx502 commented Dec 10, 2024

A ManagedChannel contains multiple InternalSubchannels, and an InternalSubchannel contains multiple TCP connections (ConnectionClientTransport). I have the following questions, can you help me answer them? Thanks.

I understand that InternalSubchannel is generally a connection between a specific service instance, why does it need EquivalentAddressGroups as a parameter, and why does InternalSubchannel contain multiple TCP connections?
image
image
image

@hlx502 hlx502 changed the title The relationship between ManagedChannel, InternalSubchannel and Netty channel The relationship between ManagedChannel, InternalSubchannel and netty channel Dec 10, 2024
@kannanjgithub
Copy link
Contributor

Transport connection is only established to one of addresses in an EquivalentAddressGroup as gRPC considers them all equivalent.
For DNS based name resolution for example, there is only one entry created in the EquivalentAddressGroup per i.p. Address.
In the case of XDS name resolution of an endpoint, an endpoint can have additional i.p. Addresses as defined by this envoy proto for an endpoint in xds. The XdsEndpointResource creates an EquivalentAddressGroup with more than one address when there is dual stack enabled, in which case it adds i.p.v6 address from the endpoint's additional addresses into the EAG.

An InternalSubChannel holds only one ConnectionClientTransport denoting a transport connection, not multiple as you mentioned.

gRPC's per-rpc load balancing happens across all the subchannels in a managed channel.

@ejona86
Copy link
Member

ejona86 commented Dec 20, 2024

why does it need EquivalentAddressGroups as a parameter

Long, long ago gRPC Java supported dual-stack (IPv4 and IPv6 addresses for the same server). We knew each LB policy, even things like round-robin, would need pick-first behavior to choose the working version of IP. So we built pick-first into the Subchannel. We allow multiple EquivalentAddressGroups because the Attributes can be significant, so it prevents needing to merge multiple EAGs together (which we used to do, but stopped doing once Attributes mattered more).

However, with xDS we started using hierarchical LBs, where one LB policy delegates to another. And they've worked out pretty well. And thus with the cross-language dual-stack design subchannels cross-language won't have multiple addresses and instead we're delegating to pick first itself. So we're in the middle of migrating from the old style and in the future subchannels will have only one address.

and why does InternalSubchannel contain multiple TCP connections?

A subchannel can have up to one of (pending, active) transport. "pending" being connecting and "active" being connected. However, it can have many non-active/pending transports (stored in transports field). These are old transports that still have RPCs running on them and haven't yet stopped, but can't be used for new RPCs. For example, when we receive a GOAWAY the activeTransport will be cleared but it stays in transports until the transport terminates. This is necessary for managedChannel.awaitTermination() and even managedChannel.shutdownNow(), as shutdownNow() will cancel those old RPCs.

@ejona86
Copy link
Member

ejona86 commented Dec 26, 2024

Seems like this is resolved. If you have more questions, comment, and it can be reopened.

@ejona86 ejona86 closed this as completed Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants