Skip to content

threads: allowing for multiple main threads for multi-envoy use case#21277

Merged
alyssawilk merged 3 commits intoenvoyproxy:mainfrom
alyssawilk:mainthread
May 16, 2022
Merged

threads: allowing for multiple main threads for multi-envoy use case#21277
alyssawilk merged 3 commits intoenvoyproxy:mainfrom
alyssawilk:mainthread

Conversation

@alyssawilk
Copy link
Copy Markdown
Contributor

Risk Level: low
Testing: turned off assertions in multi-envoy test
Docs Changes: n/a
Release Notes: n/a
part of envoyproxy/envoy-mobile#332

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

cc @jpsim an alternate to envoyproxy/envoy-mobile#2268

mutable absl::Mutex mutex_;

std::atomic<uint32_t> skip_asserts_{};
absl::flat_hash_map<std::thread::id, uint32_t> main_threads_to_usage_count_;
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.

Should this have ABSL_GUARDED_BY(mutex_)?

@jpsim
Copy link
Copy Markdown
Contributor

jpsim commented May 12, 2022

Nice! Happy to approve after you've had a chance to consider my comment.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
jpsim
jpsim previously approved these changes May 12, 2022
Copy link
Copy Markdown
Contributor

@jpsim jpsim left a comment

Choose a reason for hiding this comment

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

Thanks Alyssa 🙏

// result in the correct result even without a lock.
return std::this_thread::get_id() == main_thread_id_;
absl::MutexLock lock(&mutex_);
return main_threads_to_usage_count_.find(std::this_thread::get_id()) !=
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.

When I originally added this @htuch was concerned that a mutex-lock while checking, even under an ASSERT, might introduce serialization in tests run with ASSERTs enabled, and reduce the chance of hitting unrelated races.

But looking at the code I don't see this as a big problem -- the lock is only held during a single hash lookup.

OTOH it looks very easy to use a thread_local bool here to do the inMainThread check. Any reason not to do that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wasn't worried about major contention blocking causing performance distortion (I think), but probably just differences in timing when there is some correlated access. If there is no easy way to do this and remote singleton, let's go with this PR, but if thread_local works I agree it might be a bit better.

@jmarantz
Copy link
Copy Markdown
Contributor

/wait

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

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

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

using a thread_local bool is not required to get this in; could be a follow-up if we feel like it.

@alyssawilk alyssawilk merged commit 79f4d0d into envoyproxy:main May 16, 2022
@alyssawilk
Copy link
Copy Markdown
Contributor Author

@jpsim if you bump main on your branch it should pass. If not ping me back!

@jpsim
Copy link
Copy Markdown
Contributor

jpsim commented May 16, 2022

I'll let you know, thanks everyone!

jpsim added a commit to envoyproxy/envoy-mobile that referenced this pull request May 16, 2022
Pulls in envoyproxy/envoy#21277 to unblock
further progress on multi-engine support.

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit to envoyproxy/envoy-mobile that referenced this pull request May 17, 2022
* Pulls in envoyproxy/envoy#21277 to unblock further progress on multi-engine support
* Updates Docker build image to the same version used in Envoy
* Updates LLVM to 14.0.0
* Updates Python to 3.10

Diff: envoyproxy/envoy@efbbb04...d88f31b

Signed-off-by: JP Simard <jp@jpsim.com>
ravenblackx pushed a commit to ravenblackx/envoy that referenced this pull request Jun 8, 2022
…nvoyproxy#21277)

Risk Level: low
Testing: turned off assertions in multi-envoy test
Docs Changes: n/a
Release Notes: n/a
part of envoyproxy/envoy-mobile#332

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
jpsim added a commit that referenced this pull request Nov 29, 2022
* Pulls in #21277 to unblock further progress on multi-engine support
* Updates Docker build image to the same version used in Envoy
* Updates LLVM to 14.0.0
* Updates Python to 3.10

Diff: efbbb04...d88f31b

Signed-off-by: JP Simard <jp@jpsim.com>
@alyssawilk alyssawilk deleted the mainthread branch April 5, 2023 16:35
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