Grpc-gateway: Add UNIX socket support

Created on 3 Sep 2017  Â·  5Comments  Â·  Source: grpc-ecosystem/grpc-gateway

Hi all,

What do you think about generating code that would support UNIX socket instead of TCP over loopback for communication between reverse proxy and gRPC server ?
I don't know if this make sense (maybe it could be better to call the gRPC methods directly from the HTTP Handler?) but it would be great to skip TCP overhead in order to decrease latency and CPU usage.

Let me know what do you think about this.

documentation wontfix

Most helpful comment

This is an enhancement request to support more options when using protoc with grpc-gateway_out plugin. Beeing able to choose between TCP socket / Unix socket or direct function call for performances purposes.

Taken this proto3 file :
car.txt

Using protoc to generate reverse proxy stub :
protoc -I/usr/local/include -I. ${GOPATHLIST} --grpc-gateway_out=logtostderr=true:. car.proto

This will generate the following function :

// RegisteCarHandler registers the http handlers for service Car to "mux".                                                                                                                                                                                                                                                                                          
// The handlers forward requests to the grpc endpoint over "conn".                                                                                                                                                                                                                                                                                                         
func RegisterCarHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {                                                                                                                                                                                                                                                                      
    client := NewCarClient(conn)  
...
...

The main issue with current implementation is that this will create a mux that will dial over "conn" to gRPC endpoint using a TCP socket, ie much more overhead than direct executing RPC or using UNIX socket as a transport.

All 5 comments

Right now I am using grpc gateway with UNIX sockets in a project. Maybe you could document what you've tried and we can work together to figure out what's going on.

This is an enhancement request to support more options when using protoc with grpc-gateway_out plugin. Beeing able to choose between TCP socket / Unix socket or direct function call for performances purposes.

Taken this proto3 file :
car.txt

Using protoc to generate reverse proxy stub :
protoc -I/usr/local/include -I. ${GOPATHLIST} --grpc-gateway_out=logtostderr=true:. car.proto

This will generate the following function :

// RegisteCarHandler registers the http handlers for service Car to "mux".                                                                                                                                                                                                                                                                                          
// The handlers forward requests to the grpc endpoint over "conn".                                                                                                                                                                                                                                                                                                         
func RegisterCarHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {                                                                                                                                                                                                                                                                      
    client := NewCarClient(conn)  
...
...

The main issue with current implementation is that this will create a mux that will dial over "conn" to gRPC endpoint using a TCP socket, ie much more overhead than direct executing RPC or using UNIX socket as a transport.

Have you tried creating your connection over a unix socket? Untested pseudocode to follow:

conn, err := grpc.Dial(addr, []grpc.DialOption{grpc.WithDialer(net.DialTimeout("unix", addr, timeout))})
// Error handling

s.RegisterCarHandler(ctx, mux, conn)

What happens?

It looks like grpc may also support grpc.WithNetwork("unix") which would be even simpler (but wouldn't have support for a timeout).

I think this would be a good documentation topic as some folks are
uncomfortable going over loopback.
On Fri, Sep 8, 2017 at 10:23 AM Andrew Z Allen notifications@github.com
wrote:

Have you tried creating your connection over a unix socket? Untested
pseudocode to follow:

conn, err := grpc.Dial(addr, []grpc.DialOption{grpc.WithDialer(net.DialTimeout("unix", addr, timeout))})// Error handling

s.RegisterCarHandler(ctx, mux, conn)

What happens?

It looks like grpc may also support grpc.WithNetwork("unix") which would
be even simpler (but wouldn't have support for a timeout).

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/grpc-ecosystem/grpc-gateway/issues/451#issuecomment-328164455,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAPiacNQkAH2XlBwbb600raGhBBUXjeks5sgXfxgaJpZM4PLCli
.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

strobil picture strobil  Â·  4Comments

orjanbruland picture orjanbruland  Â·  3Comments

arun0009 picture arun0009  Â·  3Comments

pzsfeng picture pzsfeng  Â·  5Comments

stevenroose picture stevenroose  Â·  3Comments