Skip to content

Commit

Permalink
[aws-cpp-sdk-s3-crt]: Configure TCP connection-monitoring options
Browse files Browse the repository at this point in the history
Based on awslabs/aws-c-s3#204, this exposes the following
`ClientConfiguration` options to CRT:
- `connect_timeout_ms`: S3 socket connection timeout;
- `enableTcpKeepAlive`: enable TCP keep-alive probes;
- `tcpKeepAliveIntervalMs`: TCP keep-alive wait/probe interval;
- `lowSpeedLimit`: `aws-c-http` TCP connection speed monitoring;
- `requestTimeoutMs`: to provide upper bound on the monitoring interval for `aws-c-http` TCP connection speed monitoring.
  • Loading branch information
grrtrr authored and jmklix committed Oct 25, 2022
1 parent 34fcd4b commit 300c764
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions aws-cpp-sdk-s3-crt/source/S3CrtClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,32 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config, const std::shar
aws_s3_client_config s3CrtConfig;
AWS_ZERO_STRUCT(s3CrtConfig);
s3CrtConfig.region = Aws::Crt::ByteCursorFromCString(config.region.c_str());
s3CrtConfig.connect_timeout_ms = config.connectTimeoutMs;

aws_s3_tcp_keep_alive_options *tcp_keep_alive_options = nullptr;
if (config.enableTcpKeepAlive)
{
const uint16_t keep_intvl = std::max<uint16_t>(15, config.tcpKeepAliveIntervalMs/1000);

tcp_keep_alive_options = static_cast<aws_s3_tcp_keep_alive_options *>(aws_mem_calloc(Aws::get_aws_allocator(),
1, sizeof(*tcp_keep_alive_options)));
tcp_keep_alive_options->keep_alive_interval_sec = keep_intvl;
tcp_keep_alive_options->keep_alive_timeout_sec = keep_intvl;
}
s3CrtConfig.tcp_keep_alive_options = tcp_keep_alive_options;

aws_http_connection_monitoring_options *tcp_monitoring_options = nullptr;
if (config.lowSpeedLimit) {
// Use the same monitor interval default as used by the curl client, but allow override via requestTimeoutMs:
const uint32_t monitor_intvl = std::max<uint32_t>(3, config.requestTimeoutMs/1000);

tcp_monitoring_options = static_cast<aws_http_connection_monitoring_options *>(aws_mem_calloc(Aws::get_aws_allocator(),
1, sizeof(*tcp_monitoring_options)));
tcp_monitoring_options->minimum_throughput_bytes_per_second = config.lowSpeedLimit;
tcp_monitoring_options->allowable_throughput_failure_interval_seconds = monitor_intvl;
}
s3CrtConfig.monitoring_options = tcp_monitoring_options;

Aws::Crt::Io::ClientBootstrap* clientBootstrap = config.clientBootstrap ? config.clientBootstrap.get() : Aws::GetDefaultClientBootstrap();
s3CrtConfig.client_bootstrap = clientBootstrap->GetUnderlyingHandle();

Expand Down Expand Up @@ -257,6 +283,8 @@ void S3CrtClient::init(const S3Crt::ClientConfiguration& config, const std::shar
{
aws_tls_connection_options_clean_up(&tlsOptions);
}
aws_mem_release(Aws::get_aws_allocator(), tcp_keep_alive_options);
aws_mem_release(Aws::get_aws_allocator(), tcp_monitoring_options);
if (!m_s3CrtClient)
{
AWS_LOGSTREAM_FATAL(ALLOCATION_TAG, "Failed to allocate aws_s3_client instance, abort.");
Expand Down

0 comments on commit 300c764

Please sign in to comment.