【问题标题】:How to increase message size in grpc using python如何使用 python 增加 grpc 中的消息大小
【发布时间】:2017-07-26 12:35:48
【问题描述】:

我正在使用 grpc 进行消息传递,并且正在测试一个简单的服务器和客户端。当我的消息大小超过限制时,我收到此错误。

grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with 
(StatusCode.INVALID_ARGUMENT,
 Received message larger than max (7309898 vs. 4194304))>

如何增加服务器端和客户端的消息大小?

【问题讨论】:

    标签: python server client message grpc


    【解决方案1】:

    更改发送和接收的message_length 即可。

    channel = grpc.insecure_channel(
        'localhost:50051',
        options=[
            ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
            ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
        ],
    )
    

    【讨论】:

    • @duck 也许您只更改服务器或客户端?尝试从双方改变
    【解决方案2】:

    我遇到了这个问题,我通过在客户端和服务器上设置“grpc.max_send_message_length”和“grpc.max_receive_message_length”解决了这个问题:

    在客户端(此代码 sn-p 归功于 @Dumbo):

    channel = grpc.insecure_channel(
        'localhost:50051',
        options=[
            ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
            ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH),
        ],
    )
    

    在服务器中:

    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10), options = [
            ('grpc.max_send_message_length', MAX_MESSAGE_LENGTH),
            ('grpc.max_receive_message_length', MAX_MESSAGE_LENGTH)
        ])
    

    【讨论】:

      【解决方案3】:

      您不应该增加消息大小。
      它会带来性能损失。
      在实际情况中,人们会实现分页来拆分过大的消息。

      【讨论】:

      • 也许可以,但我还是想看看是否有可能以及性能损失会是多少。
      • 没有适合所有环境的黄金设置
      猜你喜欢
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-03
      • 2018-07-29
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      相关资源
      最近更新 更多