Skip to content

stats: Optimize stat-matcher rejection by prefix #17027

Closed

Description

@jmarantz

Currently when we have a stats-matcher expression with a prefix, the following algorithm is used implemented here:

bool ThreadLocalStoreImpl::checkAndRememberRejection(StatName name,

It is essentially:

bool checkAndRememberRejection(StatName stat_name) {
  if (stat_name is in rejection_set_) {
    return true; // reject a stat-name we've already seen.
  }
  std::string elaborated_name = symbol_table_.toString(stat_name); // expensive & takes lock
  if (stat_matcher_.test(elaborated_name)) {
    rejection_set_.insert(stat_name);                              // costs memory
    return true;
  }
  return true;
}

The implementation is more complex and expensive than this because there's a rejection set both in thread_local_store.cc's central cache and also in its TLS caches. And there's also a trivial optimization for when all stats are rejected (which will result in a somewhat dysfunctional Envoy for various reasons).

One interesting use-case is to drop all cluster-stats using a prefix-match of "cluster.". We can optimize this case because we could compute a StatName for the prefix up front when populating the stat-matcher, and we could use SymbolTableImpl::Encoding::decodeSymbols to match a StatName for "cluster.foo" against a prefix "cluster." without allocating memory or taking a lock.

This would also eliminate (I think) the need to bother with remembering the rejected stats in a map.

Note: similar optimization could also be made for suffix-matches like ".foo" or even internal matches like ".foo." or ".foo.bar.". However they would add code complexity so I'm just thinking now have doing what's needed for cluster-matching, but may turn out to be useful in the future.

Activity

  1. self-assigned this
    on Jun 17, 2021
  2. added a commit that references this issue on Jul 9, 2021
    dd7bab7
  3. added a commit that references this issue on Sep 30, 2021
    1e2fc32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions