TensorFlow Server 在客户端超时内关闭连接

TensorFlow Server close the connection within client timeout

我们已经使用 TensorFlow Serving 加载模型并实现 Java gRPC 客户端。

正常,适用于小数据。但是如果我们请求的batch size比较大,数据差不多1~2M,服务器会很快关闭连接并抛出内部错误。

我们还在 https://github.com/tensorflow/serving/issues/284 中打开了一个问题来跟踪这个问题。

Job aborted due to stage failure: Task 47 in stage 7.0 failed 4 times, most recent failure: Lost task 47.3 in stage 7.0 (TID 5349, xxx)
io.grpc.StatusRuntimeException: INTERNAL: HTTP/2 error code: INTERNAL_ERROR
Received Rst Stream
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:230)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:211)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:144)
at tensorflow.serving.PredictionServiceGrpc$PredictionServiceBlockingStub.predict(PredictionServiceGrpc.java:160)

......

at scala.collection.Iterator$$anon.hasNext(Iterator.scala:371)
at org.apache.spark.util.collection.ExternalSorter.insertAll(ExternalSorter.scala:189)
at org.apache.spark.shuffle.sort.SortShuffleWriter.write(SortShuffleWriter.scala:64)
at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:73)
at org.apache.spark.scheduler.ShuffleMapTask.runTask(ShuffleMapTask.scala:41)
at org.apache.spark.scheduler.Task.run(Task.scala:91)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:219)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)

Driver stacktrace:

正如在 above issue 中所见,这是由于消息超过了默认的最大消息大小 4 MiB。较大消息的接收方需要明确允许较大的消息,或者发送方发送较小的消息。

gRPC 适用于较大的消息(甚至 100 MB),但应用程序通常不行。最大消息大小已到位,仅允许 "large" 条消息出现在准备接受它们的应用程序中。