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

Add more information about http2 connection #1276

Open
polRk opened this issue Oct 15, 2024 · 7 comments
Open

Add more information about http2 connection #1276

polRk opened this issue Oct 15, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@polRk
Copy link

polRk commented Oct 15, 2024

Is your feature request related to a problem? Please describe.

CONTEXT

Within the YDB SDK, client-side load balancing is used. We send a single request to any database node, and it returns an array of available endpoints. Our task is to maintain connections to these endpoints as needed: close connections that we no longer need to use, create new connections to those that are missing, balance requests across these connections, and have the ability to send a request to a specific connection.

PROBLEM

Currently, it's not very clear how to properly close a connection (graceful shutdown), how to obtain the status of a connection, and how to receive notifications when a connection has been closed.

ONLY FOR HTTP2

Describe the solution you'd like

Extends Transport with EventEmitter, emit information about transport status changes, add current status of connection.

Additional context
https://ydb.tech/docs/en/recipes/ydb-sdk/balancing
https://blog.ydb.tech/client-side-balancing-in-ydb-89677b34fd5b

@polRk polRk added the enhancement New feature or request label Oct 15, 2024
@srikrsna-buf
Copy link
Member

srikrsna-buf commented Nov 5, 2024

For H/2 you can use the nodeOptions transport option to override createConnection callback to get a handle on the connection and inspect the status. If you want greater control over the connections you can use the sessionManager option to provide a NodeHttp2ClientSessionManager type to manage the connection.

export type NodeHttp2TransportOptions = {
/**
* A manager for the HTTP/2 connection of the transport.
*
* Providing this option makes nodeOptions as well as the HTTP/2 session
* options (pingIntervalMs et cetera) ineffective.
*/
sessionManager?: NodeHttp2ClientSessionManager;
/**
* Options passed to the connect() call of the Node.js built-in
* http2 module.
*/
nodeOptions?: http2.ClientSessionOptions | http2.SecureClientSessionOptions;
} & Http2SessionOptions;

@polRk
Copy link
Author

polRk commented Nov 12, 2024

Is connect-es provides default NodeHttp2ClientSessionManager ?

@timostamm
Copy link
Member

Yes, see the export Http2SessionManager.

@polRk
Copy link
Author

polRk commented Nov 13, 2024

How to gracefully shutdown htt2 connection (for example, server send me information do not use this endpoint) ? Maybe will be good implement disposable in transport?

I need HTTP2 connection management tools to help me balance my clients. I open 20 connections at once and keep them updated if the server sends me information about new endpoints or if any of the endpoints become unavailable. I need to be able to safely close the connection and create new ones.

For now, I can only createTransport, but I don't know how to gracefully shutdown them.

@polRk
Copy link
Author

polRk commented Nov 13, 2024

It may be that the endpoint is available now, and after 5 minutes it is unavailable, and then it is available again. I need to effectively manage the current connections, understand in advance that the connection should not be used due to an error or loss of connection.

@srikrsna-buf
Copy link
Member

It may be that the endpoint is available now, and after 5 minutes it is unavailable, and then it is available again.

The default session manager manages the connections according to HTTP/2 semantics (like goaway) and has settings to tweak ping/idle timeouts. You can look at the source code here. If the existing options don't cover your use case you can tweak it to do as you need.

@polRk
Copy link
Author

polRk commented Nov 13, 2024

@srikrsna-buf I have a clear belief that Transport needs graceful shutdown (for example, Symbol.disposable), what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants