Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grid: cleaning up pools #34802

Merged
merged 5 commits into from
Jun 20, 2024
Merged

grid: cleaning up pools #34802

merged 5 commits into from
Jun 20, 2024

Conversation

alyssawilk
Copy link
Contributor

@alyssawilk alyssawilk commented Jun 18, 2024

Changing the grid to make the HTTP/2 and HTTP/3 pools explicit

Risk Level: medium
Testing: n/a
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #34802 was opened by alyssawilk.

see: more, trace.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Contributor

@RyanTheOptimist RyanTheOptimist left a comment

Choose a reason for hiding this comment

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

Nice! Thanks for doing this.

ConnectionPool::Callbacks& callbacks, const Instance::StreamOptions& options);

// This holds state for a single connection attempt to a specific pool.
class ConnectionAttemptCallbacks : public ConnectionPool::Callbacks,
public LinkedObject<ConnectionAttemptCallbacks> {
public:
ConnectionAttemptCallbacks(WrapperCallbacks& parent, PoolIterator it);
ConnectionAttemptCallbacks(WrapperCallbacks& parent, ConnectionPool::Instance* pool);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be an Instance& if it is non-null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ConnectionPool::InstancePtr http3_pool_;
ConnectionPool::InstancePtr http2_pool_;
// A convenience list to allow taking actions on all pools.
std::list<ConnectionPool::Instance*> pools_;
Copy link
Contributor

Choose a reason for hiding this comment

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

A list involves heap allocations and pointer chasing. What would you think of absl::InlinedVector instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

// Attempt to create a new stream for pool().
StreamCreationResult newStream();
// Attempt to create a new stream for pool.
StreamCreationResult newStream(ConnectionPool::Instance* pool);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


return --pools_.end();
setupPool(*pools_.back());
return (pools_.back());
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: no need for the extra ()s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -325,13 +325,13 @@ ConnectionPool::Cancellable* ConnectivityGrid::newStream(Http::ResponseDecoder&
} else {
// Before skipping to the next pool, make sure it has been created.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might want to tweak this comment since "skipping to the next pool" is a tag less clear than "using the h2 pool"?

Copy link
Contributor

Choose a reason for hiding this comment

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

ping

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry failed to reply to the comment but this is done.

https://github.com/envoyproxy/envoy/pull/34802/files#diff-73ca9471d18d5a018082744075e2cd0c5257089b2a4bd48047350b0a94b0f894R326

Make sure the HTTP/2 pool is created.

}
auto wrapped_callback =
std::make_unique<WrapperCallbacks>(*this, decoder, pool, callbacks, overriding_options);
std::make_unique<WrapperCallbacks>(*this, decoder, callbacks, overriding_options);
Copy link
Contributor

Choose a reason for hiding this comment

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

OOC, why move pool from the constructor to newStream?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's a property of an attempt not of a wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, heh. Sure, good point. Thanks!

ConnectionPool::Cancellable* ret = wrapped_callback.get();
LinkedList::moveIntoList(std::move(wrapped_callback), wrapped_callbacks_);
if (wrapped_callbacks_.front()->newStream() == StreamCreationResult::ImmediateResult) {
if (wrapped_callbacks_.front()->newStream(pool) == StreamCreationResult::ImmediateResult) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This predates you, but might as well use ret instead of wrapped_callbacks_.front().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return nullptr;
}
return static_cast<ConnectionPool::MockInstance*>(&*pools_.front());
return static_cast<ConnectionPool::MockInstance*>(http3_pool_.get());
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this method is no longer returning the first element from a list, I think the name first isn't correct any longer. Shall we rename it http3Pool() or some such?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

ASSERT_TRUE(optional_it1.has_value());
EXPECT_EQ("HTTP/3", (**optional_it1)->protocolDescription());
auto pool1 = ConnectivityGridForTest::forceCreateNextPool(grid);
ASSERT_TRUE(pool1);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think we typically use explicit nullptr checks. ASSERT_TRUE(pool1 != nullptr). (Here and on line 990)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

// Always start with the HTTP/3 pool if it exists.
ConnectionPool::Instance* pool = http3_pool_ ? http3_pool_.get() : http2_pool_.get();
if (!pool) {
pool = createNextPool();
Copy link
Contributor

Choose a reason for hiding this comment

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

Having read through the rest of this PR, I think that we should eliminate createNextPool(). In this method, we have an explict if() down on line 320 which controls if we're doing h2 or h3. Can we simply inline the initialization of http2_pool_ and http3_pool_ there and eliminate createNextPool() since the next is a list operation which we really don't seem to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SG. Would it be Ok to do this in a follow-up? I have another clean up PR Pending plus the actual underlying fix I want to do. added a TODO in the .h file

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM!

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Contributor

@RyanTheOptimist RyanTheOptimist left a comment

Choose a reason for hiding this comment

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

LGTM, modulo the unresolved comment

// Always start with the HTTP/3 pool if it exists.
ConnectionPool::Instance* pool = http3_pool_ ? http3_pool_.get() : http2_pool_.get();
if (!pool) {
pool = createNextPool();
Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM!

@@ -325,13 +325,13 @@ ConnectionPool::Cancellable* ConnectivityGrid::newStream(Http::ResponseDecoder&
} else {
// Before skipping to the next pool, make sure it has been created.
Copy link
Contributor

Choose a reason for hiding this comment

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

ping

}
auto wrapped_callback =
std::make_unique<WrapperCallbacks>(*this, decoder, pool, callbacks, overriding_options);
std::make_unique<WrapperCallbacks>(*this, decoder, callbacks, overriding_options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, heh. Sure, good point. Thanks!

@alyssawilk alyssawilk enabled auto-merge (squash) June 20, 2024 15:48
@alyssawilk alyssawilk merged commit 7faeb05 into envoyproxy:main Jun 20, 2024
49 of 51 checks passed
antoniovleonti pushed a commit to antoniovleonti/envoy that referenced this pull request Jun 26, 2024
Changing the grid to make the HTTP/2 and HTTP/3 pools explicit

Risk Level: medium
Testing: n/a
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: antoniovleonti <leonti@google.com>
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.

None yet

2 participants