-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Document how to use ServeHTTP #549
Comments
Hi, are there any updates here? I really hate having to pass to my binaries both -port and -debug_port, and it's not really trivial to get this to work just from looking at the code in #514... |
While waiting for the "official" doc, probably you can check out |
We are working on that. But be aware of that is still in the experimental stage and may run into performance regression and stability issues. |
@iamqizhao, can we hold on the FUD until there's data to suggest otherwise? Yes, it's a newer implementation, but the x/net/http2 server is not new at all, and the new ServerTransport implementation isn't much glue between the two. There might be a bug in the glue, but I don't think it calls for warning about performance problems. But by all means, if people find problems, please report them. |
I have not done anything on that yet. But I saw something like https://github.com/cockroachdb/rpc-bench which is not the exact case here but may imply the potential performance regression. I think it would be good to give a headsup. |
Which numbers on https://github.com/cockroachdb/rpc-bench don't look good? |
Huh? rpc-bench doesn't benchmark grpc.(*Server).ServeHTTP at all. |
I meant the when you compare grpc and protoHTTP2. |
for example: name time/op name speed |
Doesn't seem relevant. |
It is relevant because ServeHTTP shares the same transport code as in http2 package. |
Drawing any conclusions about the performance of Please do not use this as a reference point. |
On Tue, Mar 1, 2016 at 1:09 PM, Tamir Duberstein notifications@github.com
|
It doesn't seem confusing: of course it uses a custom protobuf RPC codec: there is no public protobuf-based RPC mechanism. That is what GRPC will be. |
It seems at least I am getting confused here. :-) For the published results, what codec are used for |
No, they are not the same. ProtoHTTP2 is using http://godoc.org/github.com/cockroachdb/cockroach/rpc/codec. |
Thanks, tamird. @zellyn, this is the reason why it is confusing -- GRPC and ProtoHTTP2 used two different codecs in benchmarks... |
I've updated https://github.com/cockroachdb/rpc-bench to include |
@xiang90 Thanks a lot for the link! However, it doesn't really work for me, and it's not obvious to me if I am doing something wrong, or there's something about using grpc-gateway, swagger, etc. that makes it work in the example. My code looks kinda like this: // grpcHandlerFunc returns an http.Handler that delegates to
// grpcServer on incoming gRPC connections or otherHandler
// otherwise. Copied from cockroachdb.
func grpcHandlerFunc(rpcServer *rpc.Server, otherHandler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// TODO(tamird): point to merged gRPC code rather than a PR.
log.Info("here")
log.Infof("r: %#v r.Header: %v", r, r.Header)
if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") {
log.Infof("in grpc")
rpcServer.ServeHTTP(w, r)
} else {
log.Infof("in normal server")
otherHandler.ServeHTTP(w, r)
}
})
}
func main() {
// other, unrelated stuff
server := rpc.NewServer(opts...)
dm := NewMyServer()
pb.RegisterCapacityServer(server, dm)
srv := &http.Server{
Addr: fmt.Sprintf(":%d", *port),
Handler: grpcHandlerFunc(server, http.DefaultServeMux),
}
log.Exit(srv.Serve(lis))
} The HTTP part works fine, but as soon as I try to send an RPC using a Go client, then it goes in the wrong branch. The request looks like: &http.Request{Method:"PRI", URL:(*url.URL)(0xc82043e780), Proto:"HTTP/2.0", ProtoMajor:2, ProtoMinor:0, Header:http.Header{}, Body:(*struct { http.eofReaderWithWriteTo; io.Closer })(0xc97990), ContentLength:0, TransferEncoding:[]string(nil), Close:false, Host:"", Form:url.Values(nil), PostForm:url.Values(nil), MultipartForm:(*multipart.Form)(nil), Trailer:http.Header(nil), RemoteAddr:"[::1]:57688", RequestURI:"*", TLS:(*tls.ConnectionState)(nil), Cancel:(<-chan struct {})(nil)} r.Header: map[] So, it goes down the wrong path because the content-type is not set the to application/grpc. All this both in Go 1.5 and 1.6. @bradfitz Can you please shed some light on this? Oh, and this is for experimental code. I am fine with performance regressions, bugs, etc. |
The http.Handler-based server only works with TLS right now. The "PRI" you're seeing is the dummy kinda-not-really-HTTP request that is announced by http2 clients during upgrade. If you used TLS, though, the x/net/http2 package (or Go 1.6's default server) would do the upgrade for you. But neither x/net/http2 or Go itself automatically upgrades unencrypted connections to http2, so you're seeing the PRI request. I plan to make this work for gRPC, but it's not a super high priority at the moment. |
@bradfitz I haven't been able to make it work, even with TLS. This is the error I get philips/grpc-gateway-example#11 |
I'm seeing the same behavior in Go 1.7. |
(Tried with 1.5 and 1.7 here)
So I don't think I guess next step would be to add proper For anyone interested, the server-side is here: 79b7c34...gdm85:master The client-side greeter example can be used to test this. My end goal would be to have HTTP 1.x health checks support (e.g. |
Can you run the server with Go 1.7 and env |
It did have tests. I'm curious what could've regressed. |
The client-side shows:
However, if you look at the server I'm using (79b7c34...gdm85:master), I might say that this is not enabling HTTP2 at all before serving gRPC. I have already tried adding |
The only way I was able to make it work was using explicitly srv.ListenAndServeTLS |
@bradfitz I had looked at your PR (#514) before commenting here, I understand it's a refactoring step, but I see no explicit test for Sorry if my mention of tests was confusing, I didn't mean any regression happened but just that the bug/missing feature could be added by first writing the (failing) test for it (as a work-in-progress PR), then adjusting the code until test passes. |
What's needed to support non-TLS? |
Ok digging through issue #75 and this one, I found that @ryszard's example in #549 (comment) worked for a TLS enabled http.ServeMux. Can we at least document this approach if it is workable for users of TLS? |
@atombender Do you have an idea if this got fixed or if there is any plan to fix that? It's really annoying and I would need HTTP for production as well, I don't need termination in the APP (I am using a proxy). |
@Raffo No idea. |
I sent #1406 with some docs. |
Now that #75 is fixed (via #514), let's add examples on how to use ServeHTTP. The examples were removed from earlier versions of #514 to reduce the size of that change.
First, I'd like to get #545 submitted, to clean up the testdata files, before fixing this issue would otherwise make it worse.
/cc @iamqizhao
The text was updated successfully, but these errors were encountered: