Skip to content

stats: Add API Scope::scopeFromStatName and use it to skip some symbol table locks during routing recompute from control-plane update.#14418

Merged
jmarantz merged 14 commits intoenvoyproxy:masterfrom
jmarantz:scope-from-stat-name
Jan 6, 2021
Merged

stats: Add API Scope::scopeFromStatName and use it to skip some symbol table locks during routing recompute from control-plane update.#14418
jmarantz merged 14 commits intoenvoyproxy:masterfrom
jmarantz:scope-from-stat-name

Conversation

@jmarantz
Copy link
Copy Markdown
Contributor

@jmarantz jmarantz commented Dec 15, 2020

Commit Message: Adds an API for constructing scopes from StatName without holding a string representation, which helps avoid taking a lock. It was previously thought that scopes were not created on the hot-path, so this was presumed not to be necessary. But flame-graphs and code analysis suggest we can still contend on VirtualCluster creation, which involves making scopes.

As of now we are not trying to remove all creation of scopes from strings, but that is something we may want to consider as a follow-up.
Additional Description:
Risk Level: medium
Testing: //test/...
Docs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
…lang-tidy.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@mattklein123 mattklein123 self-assigned this Dec 18, 2020
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz changed the title WiP stats: Add API Scope::scopeFromStatName and use it to skip some symbol table locks during routing recompute from control-plane update. stats: Add API Scope::scopeFromStatName and use it to skip some symbol table locks during routing recompute from control-plane update. Dec 29, 2020
@jmarantz jmarantz marked this pull request as ready for review December 29, 2020 22:02
@jmarantz
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #14418 (comment) was created by @jmarantz.

see: more, trace.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz jmarantz removed the waiting label Jan 4, 2021
snowp
snowp previously requested changes Jan 4, 2021
Copy link
Copy Markdown
Contributor

@snowp snowp left a comment

Choose a reason for hiding this comment

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

Looks right to me, just some comment comments :)

* @param name supplies the scope's namespace prefix.
*/
virtual ScopePtr createScope(const std::string& name) PURE;
virtual ScopePtr scopeFromStatName(StatName name) PURE;
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.

Doxygen docs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

*
* @param scope The scope in which to create the counter.
* @param elements The vector of mixed DynamicName and StatName
* @param tags optionally specified tags.
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.

remove?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

* @return A counter named using the joined elements.
*/
static ScopePtr scopeFromElements(Scope& scope, const ElementVec& elements);
static ScopePtr scopeFromStatNames(Scope& scope, const StatNameVec& names);
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 its own doxygen comments?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks generally LGTM with small comments. Should there be some explicit tests for the new functionality vs. the implicit testing we have here?

/wait

struct StatNameProvider {
StatNameProvider(absl::string_view name, Stats::SymbolTable& symbol_table)
: stat_name_storage_(std::make_unique<Stats::StatNameManagedStorage>(name, symbol_table)) {}
std::unique_ptr<Stats::StatNameManagedStorage> stat_name_storage_;
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.

Is there any reason this needs to be heap allocated within the struct? Can it be inline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I thought there was some order-of-init issue but evidently not. Done.

Comment on lines +132 to +135
auto new_scope = std::make_unique<ScopeImpl>(*this, stat_name_storage.statName());
Thread::LockGuard lock(lock_);
scopes_.emplace(new_scope.get());
return new_scope;
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.

nit: can you just call scopeFromStatName?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, good catch, thanks.

Comment on lines +77 to +80
* @param scope The scope in which to create the counter.
* @param elements The vector of mixed DynamicName and StatName
* @param tags optionally specified tags.
* @return A counter named using the joined elements.
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 think these are out of date.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
@jmarantz
Copy link
Copy Markdown
Contributor Author

jmarantz commented Jan 5, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

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

🐱

Caused by: a #14418 (comment) was created by @jmarantz.

see: more, trace.

mattklein123
mattklein123 previously approved these changes Jan 5, 2021
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

This LGTM though I would still prefer to have some explicit stats tests of the new behavior?

Signed-off-by: Joshua Marantz <jmarantz@google.com>
Signed-off-by: Joshua Marantz <jmarantz@google.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 dismissed snowp’s stale review January 5, 2021 21:47

Comments addressed

@jmarantz jmarantz merged commit 8424857 into envoyproxy:master Jan 6, 2021
@jmarantz jmarantz deleted the scope-from-stat-name branch January 6, 2021 00:48
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.

3 participants