如何提高gRPC流性能?

I have a Go gRPC server with an endpoint that handles a stream. I have a client that streams a large file to the Go gRPC server. The performance of the server seems to be low when streaming a the large file. How can I improve performance?

Initially the server was setup on a VM and it took about 1 second to stream a file of size 8mb. Then I moved the server to my local machine where the client is located and now it takes about 250ms. I tried playing around with the ReadBufferSize server option but that did nothing. I am using the code recommended by the gRPC server for receiving data from the stream.

Here is how I'm configuring the server:

gRPCServer := grpc.NewServer(
    // Hook up credentials for SSL/TLS
    grpc.Creds(creds),

    // Inject Intercepters
    grpc_middleware.WithUnaryServerChain(

        // Hook up the ctxtags to allow for tracing
        grpc_ctxtags.UnaryServerInterceptor(ctxtagsOpts...),

        // Hook up logrus logging lib to gRPC requests
        grpc_logrus.UnaryServerInterceptor(logrusEntry, logrusOpts...),

        // Hook up the open tracer to allow for distributed logging
        grpc_opentracing.UnaryServerInterceptor(),

        // Hook up custom middlewares (i18n and error)
        middleware.ServerInterceptor,

        // Hook up custom middleware for stack trace
        middleware.Stacktrace(),
    ),

    // Hook up chain stream server
    grpc_middleware.WithStreamServerChain(
        // Hook up ctxtags to allow for tracing
        grpc_ctxtags.StreamServerInterceptor(ctxtagsOpts...),

        // Hook up logrus logging lib to gRPC requests
        grpc_logrus.StreamServerInterceptor(logrusEntry, logrusOpts...),

        // Hook up the open tracer to allow for distributed logging
        grpc_opentracing.StreamServerInterceptor(),
    ),
    grpc.MaxRecvMsgSize(config.MaxRecvMsgSize),
)

How I'm receiving the stream:

var data []byte

log.Debug("Start reconstruction of stream")

start := time.Now()

// Open up a loop to read the stream, exit when stream has reached EOF
for {
    content, err := stream.Recv()

    if err != nil {
        if err == io.EOF {
            log.Debug("End reconstruction of stream")
            break
        }
        log.Errorf("Reading chunks from stream failed unexpectedly with: %s", err)

        // return err if reading stream fails
        return err
    }

    // Append the stream content chunks to the global chunk holder
    data = append(data, content.Data...)
}

t := time.Now()
fmt.Println(t.Sub(start))

Is there anyway to improve performance? Does it come down to a resource issue (i.e. hardware or connection speed)?

dongmeng1402
dongmeng1402 确定不知道该如何帮助。您想达到什么性能?您的网络连接速度有多快?
大约一年之前 回复
dsour68888
dsour68888 这是远程@Charlie
大约一年之前 回复
dtgv52982
dtgv52982 听起来不对劲。VM是在您的开发机器上还是在远程机器上?如果是远程的,您的连接速度是多少?如果大约10MB,那就是您的问题。
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐