mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-06 13:22:57 +00:00
feat: enable tcp keepalive for http server (#4019)
* feat: enable tcp keepalive for http server * chore: for enterprise's update * resolve PR comments
This commit is contained in:
@@ -306,7 +306,7 @@ impl StartCommand {
|
||||
}
|
||||
|
||||
// The precedence order is: cli > config file > environment variables > default values.
|
||||
fn merge_with_cli_options(
|
||||
pub fn merge_with_cli_options(
|
||||
&self,
|
||||
global_options: &GlobalOptions,
|
||||
mut opts: StandaloneOptions,
|
||||
|
||||
@@ -367,6 +367,19 @@ pub enum Error {
|
||||
#[snafu(source(from(common_config::error::Error, Box::new)))]
|
||||
source: Box<common_config::error::Error>,
|
||||
},
|
||||
|
||||
#[snafu(display(
|
||||
"Failed to get region metadata from engine {} for region_id {}",
|
||||
engine,
|
||||
region_id,
|
||||
))]
|
||||
GetRegionMetadata {
|
||||
engine: String,
|
||||
region_id: RegionId,
|
||||
#[snafu(implicit)]
|
||||
location: Location,
|
||||
source: BoxedError,
|
||||
},
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
@@ -433,7 +446,9 @@ impl ErrorExt for Error {
|
||||
TableIdProviderNotFound { .. } | UnsupportedGrpcRequest { .. } => {
|
||||
StatusCode::Unsupported
|
||||
}
|
||||
HandleRegionRequest { source, .. } => source.status_code(),
|
||||
HandleRegionRequest { source, .. } | GetRegionMetadata { source, .. } => {
|
||||
source.status_code()
|
||||
}
|
||||
StopRegionEngine { source, .. } => source.status_code(),
|
||||
|
||||
FindLogicalRegions { source, .. } => source.status_code(),
|
||||
|
||||
@@ -50,6 +50,7 @@ macro_rules! add_service {
|
||||
let max_recv_message_size = $builder.config().max_recv_message_size;
|
||||
let max_send_message_size = $builder.config().max_send_message_size;
|
||||
|
||||
use tonic::codec::CompressionEncoding;
|
||||
let service_builder = $service
|
||||
.max_decoding_message_size(max_recv_message_size)
|
||||
.max_encoding_message_size(max_send_message_size)
|
||||
|
||||
@@ -842,6 +842,13 @@ impl Server for HttpServer {
|
||||
let app = self.build(app);
|
||||
let server = axum::Server::bind(&listening)
|
||||
.tcp_nodelay(true)
|
||||
// Enable TCP keepalive to close the dangling established connections.
|
||||
// It's configured to let the keepalive probes first send after the connection sits
|
||||
// idle for 59 minutes, and then send every 10 seconds for 6 times.
|
||||
// So the connection will be closed after roughly 1 hour.
|
||||
.tcp_keepalive(Some(Duration::from_secs(59 * 60)))
|
||||
.tcp_keepalive_interval(Some(Duration::from_secs(10)))
|
||||
.tcp_keepalive_retries(Some(6))
|
||||
.serve(app.into_make_service());
|
||||
|
||||
*shutdown_tx = Some(tx);
|
||||
|
||||
Reference in New Issue
Block a user