mingmwang commented on code in PR #146:
URL: https://github.com/apache/arrow-ballista/pull/146#discussion_r945679953


##########
ballista/rust/scheduler/src/state/executor_manager.rs:
##########
@@ -194,6 +200,33 @@ impl ExecutorManager {
         .await
     }
 
+    pub async fn get_client(
+        &self,
+        executor_id: &str,
+    ) -> Result<ExecutorGrpcClient<Channel>> {
+        let client = {
+            let clients = self.clients.read();
+            clients.get(executor_id).cloned()
+        };
+
+        if let Some(client) = client {
+            Ok(client)
+        } else {
+            let executor_metadata = 
self.get_executor_metadata(executor_id).await?;
+            let executor_url = format!(
+                "http://{}:{}";,
+                executor_metadata.host, executor_metadata.grpc_port
+            );
+            let client = ExecutorGrpcClient::connect(executor_url).await?;
+
+            {
+                let mut clients = self.clients.write();
+                clients.insert(executor_id.to_owned(), client.clone());
+            }
+            Ok(client)
+        }
+    }
+
     /// Get a list of all executors along with the timestamp of their last 
recorded heartbeat

Review Comment:
   There is a new method in utils.rs to create Grpc client which handles the 
grpc connection timeout and keep-alive settings, you can use that.
   
   ````
   pub async fn create_grpc_client_connection<D>(
       dst: D,
   ) -> std::result::Result<Channel, Error>
   where
       D: std::convert::TryInto<tonic::transport::Endpoint>,
       D::Error: Into<StdError>,
   {
       let endpoint = tonic::transport::Endpoint::new(dst)?
           .connect_timeout(Duration::from_secs(20))
           .timeout(Duration::from_secs(20))
           // Disable Nagle's Algorithm since we don't want packets to wait
           .tcp_nodelay(true)
           .tcp_keepalive(Option::Some(Duration::from_secs(3600)))
           .http2_keep_alive_interval(Duration::from_secs(300))
           .keep_alive_timeout(Duration::from_secs(20))
           .keep_alive_while_idle(true);
       endpoint.connect().await
   }
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to