<p>I am running in the following scenario:</p>

<ul>
<li>Single Node Kubernetes Cluster (1x i7-8700K, 1x RTX 2070, 32GB RAM)</li>
<li>1 Tensorflow Serving Pod</li>
<li>4 Inference Client Pods</li>
</ul>

<p>What the inference clients do is they get images from 4 separate cameras (1 each) and pass it to TF-Serving for inference in order to get the understanding of what is seen on the video feeds.</p>

<p>I have previously been doing inference inside the Inference Client Pods individually by calling TensorFlow directly but that hasn't been good on the RAM of the graphics card. Tensorflow Serving has been introduced to the mix quite recently in order to optimize RAM as we don't load duplicated models to the graphics card.</p>

<p>And the performance is not looking good, for a 1080p images it looks like this:</p>

<p>Direct TF: 20ms for input tensor creation, 70ms for inference.
TF-Serving: 80ms for GRPC serialization, 700-800ms for inference.</p>

<p>The TF-Serving pod is the only one that has access to the GPU and it is bound exclusively. Everything else operates on CPU.</p>

<p>Are there any performance tweaks I could do?</p>

<p>The model I'm running is Faster R-CNN Inception V2 from the TF Model Zoo.</p>

<p>Many thanks in advance!</p>

Wojtek Turowicz
<p><a href="https://www.tensorflow.org/tfx/serving/performance#1_the_tensorflow_model" rel="nofollow noreferrer">This is from TF Serving documentation</a>:</p>
<blockquote>
<p>Please note, while the average latency of performing inference with TensorFlow Serving is usually not lower than using TensorFlow directly, where TensorFlow Serving shines is keeping the tail latency down for many clients querying many different models, all while efficiently utilizing the underlying hardware to maximize throughput.</p>
</blockquote>
<p>From my own experience, I've found TF Serving to be useful in providing an abstraction over model serving which is consistent, and does <strong>not require implementing custom serving functionalities</strong>. Model versioning and multi-model which come out-of-the-box save you lots of time and are great additions.</p>
<p>Additionally, I would also recommend <a href="https://www.tensorflow.org/tfx/serving/serving_config#batching_configuration" rel="nofollow noreferrer">batching your requests</a> if you haven't already. I would also suggest playing around with the <code>TENSORFLOW_INTER_OP_PARALLELISM</code>, <code>TENSORFLOW_INTRA_OP_PARALLELISM</code>, <code>OMP_NUM_THREADS</code> arguments to TF Serving. <a href="https://stackoverflow.com/questions/41233635/meaning-of-inter-op-parallelism-threads-and-intra-op-parallelism-threads">Here is an explanation of what they are</a></p>
