@@ -628,7 +628,8 @@ struct aws_s3_client *aws_s3_client_new(
628628
629629 aws_atomic_init_int (& client -> stats .num_requests_stream_queued_waiting , 0 );
630630 aws_atomic_init_int (& client -> stats .num_requests_streaming_response , 0 );
631- aws_atomic_init_int (& client -> stats .total_weight , 0 );
631+ client -> stats .total_weight = 0.0 ;
632+ aws_mutex_init (& client -> stats .total_weight_mutex );
632633 aws_atomic_init_int (& client -> stats .total_required_connections , 0 );
633634 aws_atomic_init_int (& client -> stats .cached_max_connections , 0 );
634635 aws_atomic_init_int (& client -> stats .last_max_connections_update_ns , 0 );
@@ -862,6 +863,7 @@ struct aws_s3_client *aws_s3_client_new(
862863 }
863864 aws_client_bootstrap_release (client -> client_bootstrap );
864865 aws_mutex_clean_up (& client -> synced_data .lock );
866+ aws_mutex_clean_up (& client -> stats .total_weight_mutex );
865867
866868 aws_mem_release (client -> allocator , client -> network_interface_names_cursor_array );
867869 for (size_t i = 0 ; i < aws_array_list_length (& client -> network_interface_names ); i ++ ) {
@@ -966,6 +968,7 @@ static void s_s3_client_finish_destroy_default(struct aws_s3_client *client) {
966968 aws_mem_release (client -> allocator , client -> tcp_keep_alive_options );
967969
968970 aws_mutex_clean_up (& client -> synced_data .lock );
971+ aws_mutex_clean_up (& client -> stats .total_weight_mutex );
969972
970973 AWS_ASSERT (aws_linked_list_empty (& client -> synced_data .pending_meta_request_work ));
971974 AWS_ASSERT (aws_linked_list_empty (& client -> threaded_data .meta_requests ));
@@ -2369,6 +2372,7 @@ void aws_s3_client_update_connections_threaded(struct aws_s3_client *client) {
23692372
23702373 struct aws_s3_request * request = aws_s3_client_dequeue_request_threaded (client );
23712374 struct aws_s3_meta_request * meta_request = request -> meta_request ;
2375+ const uint32_t max_active_connections = aws_s3_client_get_max_active_connections (client , meta_request );
23722376 /* As the request removed from the queue. Decrement the preparing track */
23732377 -- meta_request -> client_process_work_threaded_data .num_request_being_prepared ;
23742378 if (request -> is_noop ) {
@@ -2395,18 +2399,16 @@ void aws_s3_client_update_connections_threaded(struct aws_s3_client *client) {
23952399 bool should_allocate_connection = false;
23962400 uint32_t current_connections = (uint32_t )aws_atomic_load_int (& meta_request -> num_requests_network );
23972401
2398- if (meta_request -> weight > 0.0 ) {
2399- size_t total_weight = aws_atomic_load_int (& client -> stats .total_weight );
2400- if (total_weight > 0 ) {
2402+ if (meta_request -> weight > (double )0 ) {
2403+ aws_mutex_lock (& client -> stats .total_weight_mutex );
2404+ double total_weight = client -> stats .total_weight ;
2405+ aws_mutex_unlock (& client -> stats .total_weight_mutex );
2406+ if (total_weight > (double )0 ) {
24012407 /* Calculate: (meta_request->weight / client->total_weight) * 300 */
2402- double weight_ratio = meta_request -> weight / ( double ) total_weight ;
2408+ double weight_ratio = meta_request -> weight / total_weight ;
24032409 uint32_t allowed_connections = (uint32_t )(weight_ratio * client_max_active_connections );
24042410
2405- /* Apply max_active_connections_override if set */
2406- if (meta_request -> max_active_connections_override > 0 ) {
2407- allowed_connections =
2408- aws_min_u32 (allowed_connections , meta_request -> max_active_connections_override );
2409- }
2411+ allowed_connections = aws_min_u32 (allowed_connections , max_active_connections );
24102412
24112413 should_allocate_connection = (current_connections < allowed_connections );
24122414 } else {
0 commit comments