go - grpc 生成的 stub 线程安全吗?

标签 go grpc

我正在看grpc的教程 https://grpc.io/docs/tutorials/basic/go.html

grpc 一元调用看起来像这样

conn, err := grpc.Dial(*serverAddr)
if err != nil {
    ...
}
defer conn.Close()
client := pb.NewRouteGuideClient(conn)
feature, err := client.GetFeature(context.Background(), &pb.Point{409146138, -746188906})
if err != nil {
        ...
}

我想知道我是否打电话

   client.GetFeature

来自多个线程,它是线程安全的吗?

最佳答案

调查此 issue你可以了解到:

@rubenv asks:

Can I use a client from different threads in parallel?

@iamqizhao replies:

On client, if you want to perform multiple rpc in parallel, you should spawn multiple goroutines to do that since the rpc is synchronous/blocking

答案是肯定的,但是不能共享流 ( source )。

@trevorgray, these kinds of concurrency topics are apparently still not documented, per #682.

关于go - grpc 生成的 stub 线程安全吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49662965/

相关文章:

c# - 如何在 C# 中生成 .proto 文件或使用 'Code First gRPC'

javascript - Node JS : Will a Bidirection GRPC Call Open Multiple http2 Connections?

Go gRPC status.Error() 在运行并发请求时导致无效的内存地址

go - 使用 Go 读取 TOML 文件时结果为空

go - 将多个 bool 值(来自 HTML 表单)转换为一个字符串 (Go)

mongodb - FindOneAndUpdate函数不更新数据库

mongodb - $literal 在 Golang-mgo 中的用法

c++ - 如何在 grpc 中进行 payload 压缩?

go - 文本/模板 : "can' t call method/function with 0 results. "

python - gRPC/proto Google 云客户端库与 GAPIC Google 云客户端库