@@ -104,8 +104,13 @@ const double s_s3_express_p50_request_latency_ms = 0.004;
104104 * achieved. This is required to hard limit the number of connections we open for extremely small request sizes. The
105105 * number below is arbitrary until we come up with more sophisticated math.
106106 */
107- const uint32_t s_s3_minimum_tokens = 500 ;
107+ const uint32_t s_s3_minimum_tokens = 10 ;
108108
109+ /*
110+ * Represents a rough estimate of the tokens used by a request we do not have the idea of type or payload for.
111+ * This is hard to set and hence is an approximation.
112+ */
113+ const uint32_t s_s3_default_tokens = 500 ;
109114/**
110115 * Default max part size is 5GiB as the server limit.
111116 */
@@ -242,8 +247,7 @@ uint32_t aws_s3_client_get_max_active_connections(
242247void s_s3_client_init_tokens (struct aws_s3_client * client ) {
243248 AWS_PRECONDITION (client );
244249
245- aws_atomic_store_int (
246- & client -> token_bucket , aws_max_u32 ((uint32_t )client -> throughput_target_gbps * 1024 , s_s3_minimum_tokens ));
250+ aws_atomic_store_int (& client -> token_bucket , (uint32_t )client -> throughput_target_gbps * 1024 );
247251}
248252
249253/* Releases tokens back after request is complete. */
@@ -329,10 +333,13 @@ bool s_s3_client_acquire_tokens(struct aws_s3_client *client, struct aws_s3_requ
329333 break ;
330334 }
331335 default : {
332- required_tokens = s_s3_minimum_tokens ;
336+ required_tokens = s_s3_default_tokens ;
333337 }
334338 }
335339
340+ // Ensure we are using atleast minimum number of tokens irrespective of payload size.
341+ required_tokens = aws_max_u32 (required_tokens , s_s3_minimum_tokens );
342+
336343 if ((uint32_t )aws_atomic_load_int (& client -> token_bucket ) > required_tokens ) {
337344 // do we need error handling here?
338345 aws_atomic_fetch_sub (& client -> token_bucket , required_tokens );
0 commit comments