-
Notifications
You must be signed in to change notification settings - Fork 261
feat: make gRPC timeout configurations user-configurable #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
milenkovicm
merged 7 commits into
apache:main
from
CuteChuanChuan:cutechuanchuan/grpc-user-configurable
Nov 1, 2025
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
384c4ec
feat: make gRPC timeout configurations user-configurable
CuteChuanChuan 23cd355
refactor: introduce GrpcClientConfig and GrpcServerConfig
CuteChuanChuan 9e2cf6f
Address PR review feedback for gRPC configuration
CuteChuanChuan c6b8d87
refactor: simplify GrpcClientConfig usage with Into trait
CuteChuanChuan 3d9f9f0
Cargo fmt
CuteChuanChuan 10ab817
Merge branch 'apache:main' into cutechuanchuan/grpc-user-configurable
CuteChuanChuan c83bc84
fix: remove unused GrpcClientConfig imports
CuteChuanChuan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| use crate::config::BallistaConfig; | ||
| use crate::error::{BallistaError, Result}; | ||
| use crate::extension::SessionConfigExt; | ||
| use crate::serde::scheduler::PartitionStats; | ||
|
|
@@ -36,6 +37,95 @@ use std::{fs::File, pin::Pin}; | |
| use tonic::codegen::StdError; | ||
| use tonic::transport::{Channel, Error, Server}; | ||
|
|
||
| /// Configuration for gRPC client connections. | ||
| /// | ||
| /// This struct holds timeout and keep-alive settings that are applied | ||
| /// when establishing gRPC connections from executors to schedulers or | ||
| /// between distributed components. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use ballista_core::config::BallistaConfig; | ||
| /// use ballista_core::utils::GrpcClientConfig; | ||
| /// | ||
| /// let ballista_config = BallistaConfig::default(); | ||
| /// let grpc_config = GrpcClientConfig::from(&ballista_config); | ||
| /// ``` | ||
| #[derive(Debug, Clone)] | ||
| pub struct GrpcClientConfig { | ||
| /// Connection timeout in seconds | ||
| pub connect_timeout_seconds: u64, | ||
| /// Request timeout in seconds | ||
| pub timeout_seconds: u64, | ||
| /// TCP keep-alive interval in seconds | ||
| pub tcp_keepalive_seconds: u64, | ||
| /// HTTP/2 keep-alive ping interval in seconds | ||
| pub http2_keepalive_interval_seconds: u64, | ||
| } | ||
|
|
||
| impl From<&BallistaConfig> for GrpcClientConfig { | ||
| fn from(config: &BallistaConfig) -> Self { | ||
| Self { | ||
| connect_timeout_seconds: config.default_grpc_client_connect_timeout_seconds() | ||
| as u64, | ||
| timeout_seconds: config.default_grpc_client_timeout_seconds() as u64, | ||
| tcp_keepalive_seconds: config.default_grpc_client_tcp_keepalive_seconds() | ||
| as u64, | ||
| http2_keepalive_interval_seconds: config | ||
| .default_grpc_client_http2_keepalive_interval_seconds() | ||
| as u64, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Default for GrpcClientConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| connect_timeout_seconds: 20, | ||
| timeout_seconds: 20, | ||
| tcp_keepalive_seconds: 3600, | ||
| http2_keepalive_interval_seconds: 300, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Configuration for gRPC server. | ||
| /// | ||
| /// This struct holds timeout and keep-alive settings that are applied | ||
| /// when creating gRPC servers in executors and schedulers. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ``` | ||
| /// use ballista_core::utils::GrpcServerConfig; | ||
| /// | ||
| /// let server_config = GrpcServerConfig::default(); | ||
| /// let server = ballista_core::utils::create_grpc_server(&server_config); | ||
| /// ``` | ||
| #[derive(Debug, Clone)] | ||
| pub struct GrpcServerConfig { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please put some docs please, we will try to catch up with documentation at some point so it would help.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Absolutely! |
||
| /// Request timeout in seconds | ||
| pub timeout_seconds: u64, | ||
| /// TCP keep-alive interval in seconds | ||
| pub tcp_keepalive_seconds: u64, | ||
| /// HTTP/2 keep-alive ping interval in seconds | ||
| pub http2_keepalive_interval_seconds: u64, | ||
| /// HTTP/2 keep-alive ping timeout in seconds | ||
| pub http2_keepalive_timeout_seconds: u64, | ||
| } | ||
|
|
||
| impl Default for GrpcServerConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| timeout_seconds: 20, | ||
| tcp_keepalive_seconds: 3600, | ||
| http2_keepalive_interval_seconds: 300, | ||
| http2_keepalive_timeout_seconds: 20, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Default session builder using the provided configuration | ||
| pub fn default_session_builder( | ||
| config: SessionConfig, | ||
|
|
@@ -106,31 +196,40 @@ pub async fn collect_stream( | |
|
|
||
| pub async fn create_grpc_client_connection<D>( | ||
| dst: D, | ||
| config: &GrpcClientConfig, | ||
| ) -> 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)) | ||
| .connect_timeout(Duration::from_secs(config.connect_timeout_seconds)) | ||
| .timeout(Duration::from_secs(config.timeout_seconds)) | ||
| // 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)) | ||
| .tcp_keepalive(Some(Duration::from_secs(config.tcp_keepalive_seconds))) | ||
| .http2_keep_alive_interval(Duration::from_secs( | ||
| config.http2_keepalive_interval_seconds, | ||
| )) | ||
| // Use a fixed timeout for keep-alive pings to keep configuration simple | ||
| // since this is a standalone configuration | ||
| .keep_alive_timeout(Duration::from_secs(20)) | ||
| .keep_alive_while_idle(true); | ||
| endpoint.connect().await | ||
| } | ||
|
|
||
| pub fn create_grpc_server() -> Server { | ||
| pub fn create_grpc_server(config: &GrpcServerConfig) -> Server { | ||
| Server::builder() | ||
| .timeout(Duration::from_secs(20)) | ||
| .timeout(Duration::from_secs(config.timeout_seconds)) | ||
| // Disable Nagle's Algorithm since we don't want packets to wait | ||
| .tcp_nodelay(true) | ||
| .tcp_keepalive(Option::Some(Duration::from_secs(3600))) | ||
| .http2_keepalive_interval(Option::Some(Duration::from_secs(300))) | ||
| .http2_keepalive_timeout(Option::Some(Duration::from_secs(20))) | ||
| .tcp_keepalive(Some(Duration::from_secs(config.tcp_keepalive_seconds))) | ||
| .http2_keepalive_interval(Some(Duration::from_secs( | ||
| config.http2_keepalive_interval_seconds, | ||
| ))) | ||
| .http2_keepalive_timeout(Some(Duration::from_secs( | ||
| config.http2_keepalive_timeout_seconds, | ||
| ))) | ||
| } | ||
|
|
||
| pub fn collect_plan_metrics(plan: &dyn ExecutionPlan) -> Vec<MetricsSet> { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please put some docs please, we will try to catch up with documentation at some point so it would help.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely!