Skip to content

Commit 55f2245

Browse files
author
Krish
committed
why even cache?
1 parent 4bb643e commit 55f2245

File tree

2 files changed

+9
-56
lines changed

2 files changed

+9
-56
lines changed

include/aws/s3/private/s3_client_impl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,6 @@ struct aws_s3_client {
381381

382382
/* Sum of connection requirements from all active meta requests */
383383
struct aws_atomic_var total_required_connections;
384-
385-
/* Cached max connections value for hysteresis */
386-
struct aws_atomic_var cached_max_connections;
387-
388-
/* Timestamp of last connection limit change for hysteresis */
389-
struct aws_atomic_var last_max_connections_update_ns;
390384
} stats;
391385

392386
struct {

source/s3_client.c

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -191,43 +191,14 @@ static uint32_t s_get_system_fd_limit(void) {
191191
#endif
192192
}
193193

194-
/**
195-
* Determine if connection pool should be resized based on hysteresis mechanism.
196-
* Returns true only if both conditions are met:
197-
* 1. Absolute difference exceeds threshold (max(current_max / 10, 10))
198-
* 2. Time since last resize exceeds 1 second
199-
*/
200-
static bool s_should_resize_connection_pool(
201-
uint32_t current_max,
202-
uint32_t new_max,
203-
uint64_t current_time_ns,
204-
uint64_t last_resize_timestamp_ns) {
205-
206-
/* Calculate threshold: 10% or 10 connections, whichever is larger */
207-
uint32_t threshold = aws_max_u32(current_max / 10, 10);
208-
209-
/* Check if change is significant */
210-
uint32_t diff = (new_max > current_max) ? (new_max - current_max) : (current_max - new_max);
211-
212-
if (diff < threshold) {
213-
return false;
214-
}
215-
216-
/* Check minimum time interval (0.01 second = 1e7 nanoseconds) */
217-
uint64_t min_interval_ns = 10000000ULL;
218-
if (last_resize_timestamp_ns > 0 && (current_time_ns - last_resize_timestamp_ns < min_interval_ns)) {
219-
return false;
220-
}
221-
222-
return true;
223-
}
224-
225194
/**
226195
* Calculate dynamic connection limit based on sum of active meta request requirements.
227196
* Returns the minimum of: total required connections, client override, and system FD limit.
228197
* Applies hysteresis to prevent rapid changes.
229198
*/
230-
static uint32_t s_get_dynamic_max_active_connections(struct aws_s3_client *client) {
199+
static uint32_t s_get_dynamic_max_active_connections(
200+
struct aws_s3_client *client,
201+
struct aws_s3_meta_request *meta_request) {
231202
AWS_PRECONDITION(client);
232203

233204
/* Load sum of all meta request requirements */
@@ -260,6 +231,11 @@ static uint32_t s_get_dynamic_max_active_connections(struct aws_s3_client *clien
260231
new_max = aws_min_u32(new_max, client->max_active_connections_override);
261232
}
262233

234+
/* respect meta request level overrides */
235+
if (meta_request && meta_request->max_active_connections_override > 0) {
236+
new_max = aws_min_u32(new_max, meta_request->max_active_connections_override);
237+
}
238+
263239
/* Apply system FD limit (checked dynamically) */
264240
uint32_t system_fd_limit = s_get_system_fd_limit();
265241

@@ -274,21 +250,6 @@ static uint32_t s_get_dynamic_max_active_connections(struct aws_s3_client *clien
274250

275251
new_max = aws_min_u32(new_max, system_fd_limit);
276252

277-
/* Apply hysteresis to prevent rapid changes */
278-
uint32_t cached_max = (uint32_t)aws_atomic_load_int(&client->stats.cached_max_connections);
279-
uint64_t last_update_ns = (uint64_t)aws_atomic_load_int(&client->stats.last_max_connections_update_ns);
280-
uint64_t current_time_ns = 0;
281-
aws_high_res_clock_get_ticks(&current_time_ns);
282-
283-
/* If cached value exists and hysteresis check fails, return cached value */
284-
if (cached_max > 0 && !s_should_resize_connection_pool(cached_max, new_max, current_time_ns, last_update_ns)) {
285-
return cached_max;
286-
}
287-
288-
/* Update cached value and timestamp */
289-
aws_atomic_store_int(&client->stats.cached_max_connections, (size_t)new_max);
290-
aws_atomic_store_int(&client->stats.last_max_connections_update_ns, (size_t)current_time_ns);
291-
292253
/* Log warning if system limit is the bottleneck */
293254
if (new_max == system_fd_limit &&
294255
(total > system_fd_limit ||
@@ -321,7 +282,7 @@ uint32_t aws_s3_client_get_max_active_connections(
321282

322283
/* Check feature flag - use dynamic scaling if enabled */
323284
if (client->enable_dynamic_connection_scaling) {
324-
return s_get_dynamic_max_active_connections(client);
285+
return s_get_dynamic_max_active_connections(client, meta_request);
325286
}
326287
uint32_t max_active_connections = client->ideal_connection_count;
327288
if (client->max_active_connections_override > 0 &&
@@ -631,8 +592,6 @@ struct aws_s3_client *aws_s3_client_new(
631592
client->stats.total_weight = 0.0;
632593
aws_mutex_init(&client->stats.total_weight_mutex);
633594
aws_atomic_init_int(&client->stats.total_required_connections, 0);
634-
aws_atomic_init_int(&client->stats.cached_max_connections, 0);
635-
aws_atomic_init_int(&client->stats.last_max_connections_update_ns, 0);
636595

637596
*((uint32_t *)&client->max_active_connections_override) = client_config->max_active_connections_override;
638597

0 commit comments

Comments
 (0)