Skip to content

http2: remove unnecessary negative_capacity_ - #19057

Merged
alyssawilk merged 7 commits into
envoyproxy:mainfrom
YaoZengzeng:negative
Nov 30, 2021
Merged

alyssawilk merged 7 commits into
envoyproxy:mainfrom
YaoZengzeng:negative

Conversation

@YaoZengzeng

@YaoZengzeng YaoZengzeng commented Nov 19, 2021 •

Copy link
Copy Markdown
Member

Commit Message: remove negative_capacity_ to make the code easier to understand
Additional Description: fixes part I of #18880
Risk Level: high
Testing: unit
Docs Changes: n/a

@YaoZengzeng

Copy link
Copy Markdown
Member Author

The use of negative_capacity_ is hard to understand.

In my opinion, when the stream destroyed, if the capacity caculated by remaining streams (remaining_streams_) > the capacity caculated by concurrency (concurrent_stream_limit_ - numActiveStreams() - 1), we could increase the ConnectingAndConnectedStreamCapacity and we don't need negative_capacity_ which just complicates the logic.

Because the type of concurrent_stream_limit_ and numActiveStreams() is uint32_t, when concurrent_stream_limit_ < numActiveStreams() + 1, then (concurrent_stream_limit_ - numActiveStreams() - 1) could result overflow. Obviously, in this case, we should increase ConnectingAndConnectedStreamCapacity. So compare concurrent_stream_limit_ and
numActiveStreams() + 1 directly to avoid overflow.

@alyssawilk WDYT :)

@YaoZengzeng

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19057 (comment) was created by @YaoZengzeng.

see: more, trace.

@yanavlasov

Copy link
Copy Markdown
Contributor

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19057 (comment) was created by @yanavlasov.

see: more, trace.

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @RyanTheOptimist

@RyanTheOptimist RyanTheOptimist left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of minor cosmetic comments.

if (trackStreamCapacity() && (client.remaining_streams_ > client.concurrent_stream_limit_ -
client.numActiveStreams() - 1 ||
had_negative_capacity)) {
// The capacity caculated by concurrency could be negative, in this case, efficient client

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: calculated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should this be "effective" instead of "efficient"?

Comment thread tools/spelling/spelling_dictionary.txt Outdated
cacert
cacheable
cacheability
caculated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a typo and we probably don't want to include it here, do we?

nanos
natively
ndk
negative

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I'm surprised that "negative" is not already known!

@YaoZengzeng

Copy link
Copy Markdown
Member Author

@RyanTheOptimist updated.

@RyanTheOptimist

Copy link
Copy Markdown
Contributor

/assign @alyssawilk

@YaoZengzeng

Copy link
Copy Markdown
Member Author

@alyssawilk PTAL at this one :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I like the simplification of removing the negative capacity member variable, I think this if statement was already hard to read and is now really hard to read :-)

Let's break it up. Something like
// We don't update the capacity for HTTP/3
if (trackStreamCapacity()) {
// If the effective client capacity was limited by max total streams...
bool limited_by_concurrency = ...
// The capacity calculated by concurrency could be negative [maybe explicitly call out SETTINGS frame
bool has_newly_available_capacity = ...
if (limited_by_concurrency && has_newly_available_capacity) {
state.incr....
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alyssawilk updated!

@YaoZengzeng

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19057 (comment) was created by @YaoZengzeng.

see: more, trace.

@YaoZengzeng

Copy link
Copy Markdown
Member Author

/retest

@repokitteh-read-only

Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #19057 (comment) was created by @YaoZengzeng.

see: more, trace.

Signed-off-by: YaoZengzeng <[email protected]>
Signed-off-by: YaoZengzeng <[email protected]>
Signed-off-by: YaoZengzeng <[email protected]>
This reverts commit 705684d.

Signed-off-by: YaoZengzeng <[email protected]>
Signed-off-by: YaoZengzeng <[email protected]>
client.numActiveStreams() - 1 ||
had_negative_capacity)) {
state_.incrConnectingAndConnectedStreamCapacity(1);
// We don't update the capacity for HTTP/3 as the stream count should only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment got truncated?

@alyssawilk alyssawilk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!
/wait

// If the effective client capacity was limited by concurrency, increase connecting capacity.
bool limited_by_concurrency =
client.remaining_streams_ > client.concurrent_stream_limit_ - client.numActiveStreams() - 1;
// The capacity calculated by concurrency could be negative (maybe explicitly call out SETTINGS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"maybe explicitly call out SETTINGS frame"
Oops, I didn't mean this one to be a literal suggestion :-P

// The capacity calculated by concurrency could be negative if a SETTINGS frame lowered the number of
// allowed streams. In this case, effective client capacity was still limited by concurrency, compare
// client.concurrent_stream_limit_ and client.numActiveStreams() directly to avoid overflow.

Signed-off-by: YaoZengzeng <[email protected]>
@alyssawilk
alyssawilk enabled auto-merge (squash) November 30, 2021 14:48
@YaoZengzeng

Copy link
Copy Markdown
Member Author

@alyssawilk thanks for your review, it's always need a lot of time to sync because of time difference 😄

@alyssawilk

Copy link
Copy Markdown
Contributor

and with US holidays! Thanks again for your patience - it's wonderful seeing this area of code cleaned up!

@alyssawilk
alyssawilk merged commit 3baae86 into envoyproxy:main Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants