Skip to content

Commit

Permalink
Added leased_concurrency to metrics and instrumented http connection …
Browse files Browse the repository at this point in the history
…manager and stream managers. (#392)
  • Loading branch information
JonathanHenson authored Oct 11, 2022
1 parent db41119 commit 82fb7ed
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/aws/http/connection_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct aws_http_manager_metrics {
size_t available_concurrency;
/* The number of requests that are awaiting concurrency to be made available from the HTTP manager. */
size_t pending_concurrency_acquires;
/* The number of connections (http/1.1) or streams (for h2 via. stream manager) currently vended to user. */
size_t leased_concurrency;
};

/*
Expand Down
3 changes: 2 additions & 1 deletion source/connection_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct aws_http_connection_manager {
/*
* The number of all established, idle connections. So
* that we don't have compute the size of a linked list every time.
* It doesn't contribute to internal refcount as AWS_HCMCT_OPEN_CONNECTION inclues all idle connections as well.
* It doesn't contribute to internal refcount as AWS_HCMCT_OPEN_CONNECTION includes all idle connections as well.
*/
size_t idle_connection_count;

Expand Down Expand Up @@ -1555,5 +1555,6 @@ void aws_http_connection_manager_fetch_metrics(
AWS_FATAL_ASSERT(aws_mutex_lock((struct aws_mutex *)(void *)&manager->lock) == AWS_OP_SUCCESS);
out_metrics->available_concurrency = manager->idle_connection_count;
out_metrics->pending_concurrency_acquires = manager->pending_acquisition_count;
out_metrics->leased_concurrency = manager->internal_ref[AWS_HCMCT_VENDED_CONNECTION];
AWS_FATAL_ASSERT(aws_mutex_unlock((struct aws_mutex *)(void *)&manager->lock) == AWS_OP_SUCCESS);
}
1 change: 1 addition & 0 deletions source/http2_stream_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ void aws_http2_stream_manager_fetch_metrics(
out_metrics->pending_concurrency_acquires =
stream_manager->synced_data.internal_refcount_stats[AWS_SMCT_PENDING_ACQUISITION];
out_metrics->available_concurrency = all_available_streams_num;
out_metrics->leased_concurrency = stream_manager->synced_data.internal_refcount_stats[AWS_SMCT_OPEN_STREAM];
s_unlock_synced_data((struct aws_http2_stream_manager *)(void *)stream_manager);
} /* END CRITICAL SECTION */
}
3 changes: 3 additions & 0 deletions tests/test_stream_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ TEST_CASE(h2_sm_mock_fetch_metric) {
/* Acquired 1 stream, and we hold one connection, the max streams per connection is 2. */
ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 1);
ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 0);
ASSERT_UINT_EQUALS(out_metrics.leased_concurrency, 1);

ASSERT_SUCCESS(s_sm_stream_acquiring(1));

Expand All @@ -902,6 +903,7 @@ TEST_CASE(h2_sm_mock_fetch_metric) {
aws_http2_stream_manager_fetch_metrics(s_tester.stream_manager, &out_metrics);
ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 0);
ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 0);
ASSERT_UINT_EQUALS(out_metrics.leased_concurrency, 2);

ASSERT_SUCCESS(s_sm_stream_acquiring(10));
ASSERT_SUCCESS(s_wait_on_fake_connection_count(5));
Expand All @@ -910,6 +912,7 @@ TEST_CASE(h2_sm_mock_fetch_metric) {
aws_http2_stream_manager_fetch_metrics(s_tester.stream_manager, &out_metrics);
ASSERT_UINT_EQUALS(out_metrics.available_concurrency, 0);
ASSERT_UINT_EQUALS(out_metrics.pending_concurrency_acquires, 2);
ASSERT_UINT_EQUALS(out_metrics.leased_concurrency, 10);

ASSERT_SUCCESS(s_complete_all_fake_connection_streams());
/* Still have two more streams that have not been completed */
Expand Down

0 comments on commit 82fb7ed

Please sign in to comment.