如何解决grpc Deadline Exceeded错误?

huangapple go评论98阅读模式
英文:

How to solve grpc Deadline Exceeded error?

问题

我有一个由Go编写的gRPC服务器和一个Python客户端,有时会出现以下错误:

eggs/grpcio-1.0.0-py2.7-linux-x86_64.egg/grpc/_channel.py",第432行,_end_unary_response_blocking函数中
raise _Rendezvous(state, None, None, deadline)

InternalServerError: Deadline Exceeded

grpc截止时间概念

> gRPC允许客户端在调用远程方法时指定截止时间。这指定了客户端在RPC完成之前希望等待服务器响应的时间,否则将返回DEADLINE_EXCEEDED错误。在服务器端,服务器可以查询截止时间,以查看特定方法是否已超时,或者完成该方法还剩多少时间。
>
> 截止时间的指定方式因语言而异-例如,在Python中始终需要指定截止时间,并非所有语言都有默认截止时间。

有没有办法解决这个错误?

英文:

I have grpc server which write by go and a python client, sometimes, the errors occurred as below:

eggs/grpcio-1.0.0-py2.7-linux-x86_64.egg/grpc/_channel.py\", line 432, in _end_unary_response_blocking\n    raise _Rendezvous(state, None, None, deadline)\nInternalServerError: Deadline Exceeded\n"}

grpc Deadlines concept

> gRPC allows clients to specify a deadline value when calling a remote
> method. This specifies how long the client wants to wait for a
> response from the server before the RPC finishes with the error
> DEADLINE_EXCEEDED. On the server side, the server can query the
> deadline to see if a particular method has timed out, or how much time
> is left to complete the method.
>
> How the deadline is specified varies from language to language - for
> example, a deadline value is always required in Python, and not all
> languages have a default deadline.

is there way to solve this error?

答案1

得分: 4

如上面的评论中提到的,截止日期可以是客户端和服务器之间的任何事情,包括网络和服务器的实现。由于您正在通过网络进行通信,偶尔会出现截止日期,例如在数据包丢失时。一般来说,您可以在这里有几个选择:

  • 优化服务器实现,以更快地处理您的请求。
  • 如果客户端设置了较短的截止日期,可以将其延长。
  • 优雅地处理截止日期错误:
    • 重试。确保使用指数退避,以免在服务器超载情况下使问题变得更糟。
    • 向上游报告错误。
    • 有时还可以回退到不使用该grpc调用并降低体验的方式。
英文:

As mentioned in the comment above, deadlines can be just about anything between the client and server, including the network and implementation of the server. As you are talking over a network, deadlines should be expected occasionally, for example during package losses. In general, there are a couple of options on what you can do here:

  • Optimize the server implementation to handle your requests faster.
  • In case the client sets a short deadline, increase this.
  • Handle the deadline errors gracefully by:
    • Retrying. Just make sure to use an exponential back-off, so you don't make the problem worse in case of a server overload situation.
    • Report an error up-streams.
    • Sometimes it may also be possible to fall back to not use that grpc call and degrade the experience.

huangapple
  • 本文由 发表于 2017年3月23日 18:19:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/42973191.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定