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

Expand director API to allow for connection management #16

Closed
wants to merge 7 commits into from

Conversation

vgough
Copy link

@vgough vgough commented Jun 16, 2017

Fixes #15 , allowing director to decide how to deal with connections - either by closing them when they're not used, or allowing the director to track how long they've been inactive.

Adds forwarding metadata, and updates metadata functions to no longer use the deprecated functions.

if strings.HasPrefix(method, "/com.example.internal.") {
return nil, nil, grpc.Errorf(codes.Unimplemented, "Unknown method")
}
md, ok := metadata.FromContext(ctx)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change to FromIncomingContext?

README.md Outdated
[![Travis Build](https://travis-ci.org/mwitkow/grpc-proxy.svg?branch=master)](https://travis-ci.org/mwitkow/grpc-proxy)
[![Go Report Card](https://goreportcard.com/badge/github.com/mwitkow/grpc-proxy)](https://goreportcard.com/report/github.com/mwitkow/grpc-proxy)
[![GoDoc](http://img.shields.io/badge/GoDoc-Reference-blue.svg)](https://godoc.org/github.com/mwitkow/grpc-proxy)
[![Travis Build](https://travis-ci.org/vgough/grpc-proxy.svg?branch=master)](https://travis-ci.org/vgough/grpc-proxy)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to revert this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm.. this was not part of the PR I initially sent. Looks like it keeps getting updated with the state of my fork. I'll see what I can do.

@vgough
Copy link
Author

vgough commented Aug 19, 2017

Updated examples, removed status link changes.

@mwitkow
Copy link
Owner

mwitkow commented Aug 23, 2017

Why is this needed?

The naive implementation re-creates a new ClientConn, but since ClientConn can be stored and retained outside of the director and reused between connections.

For example:
https://github.com/mwitkow/kedge/blob/master/grpc/director/director.go#L13
https://github.com/mwitkow/kedge/blob/master/grpc/backendpool/pool.go

Am I missing something?

@vgough
Copy link
Author

vgough commented Aug 24, 2017

@mwitkow the problem is one of scale - see #15. Imagine that you potentially contact 10s of thousands of endpoints. Your example pool has a close-all function, but that's not safe to use without disconnecting live connections.

How would you implement a pool which keeps connections around for T seconds after last use, or at most N connections? In order to do that, you need to know when the handler is done using the connection, so that you don't end up disconnecting live streaming connections.

If the director were to return an interface, it would be possible wrap the grpc connection in something that tracks lifespan. Since we're returning a struct, I went the route of adding an explicit release method.

@mwitkow
Copy link
Owner

mwitkow commented Aug 25, 2017

vgough, I understand the use case, but this is not a problem with the grpcproxy code, but instead with the fact that grpc.Conn is not an interface.

We had a similar problem in other places (e.g. ephemeral connections to ip addresses), and we solved it by having a piece of middleware that accounted for in flight RPCs and cleared stuff from the pool.

I'd rather not change the interface of grpcproxy atm, as I am planning for it to go through a stabilization phase.

@bufdev
Copy link

bufdev commented Aug 25, 2017 via email

@vgough
Copy link
Author

vgough commented Aug 25, 2017

Michal, sounds like you're thinking that a connection-managing proxy would implement a new grpc.StreamHandler which takes an API for connection management and wraps TransparentHandler with a custom StreamDirector function which tracks established connections?

Seems like pretty basic functionality, knowing when TransparentHandler is done with a resource taken from StreamDirector. Would you include this wrapper in grpcproxy? If so, then I'm willing to redo this PR to add the new interfaces.

@vgough
Copy link
Author

vgough commented May 21, 2018

Closing this, my fork is diverging, not expecting to integrate changes.

@vgough vgough closed this May 21, 2018
@vgough vgough mentioned this pull request May 21, 2018
This was referenced Dec 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants