Skip to content

Oximeter: cache compiled regex.#10698

Open
jmcarp wants to merge 1 commit into
mainfrom
jmcarp/oximeter-lazy-regex
Open

Oximeter: cache compiled regex.#10698
jmcarp wants to merge 1 commit into
mainfrom
jmcarp/oximeter-lazy-regex

Conversation

@jmcarp

@jmcarp jmcarp commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Per #10552, oximeter spends about 2/3 of its cpu time compiling TIMESERIES_NAME_REGEX. This happens because we check each incoming sample against the regex in validate_timeseries_name, and compile the regex each time that function is invoked. To fix, this patch compiles TIMESERIES_NAME_REGEX at most once using LazyLock.

Note: oximeter's observed cpu use isn't particularly high, but its throughput is more of a concern. When oximeter's database batcher receives samples faster than it can flush them from its queue, it drops old samples. So until we make a larger architectural change, such as sharding oximeter, we need to maintain high throughput in order to avoid dropping samples under high volume. This change alone may not avoid all dropped samples reported in #10552, but it should help, and has no obvious downsides.

Part of #10552.

Per #10552, oximeter spends about 2/3 of its cpu time compiling
`TIMESERIES_NAME_REGEX`. This happens because we check each incoming sample
against the regex in `validate_timeseries_name`, and compile the regex each
time that function is invoked. To fix, this patch compiles
`TIMESERIES_NAME_REGEX` at most once using `LazyLock`.

Note: oximeter's observed cpu use isn't particularly high, but its throughput
is more of a concern. When oximeter's database batcher receives samples faster
than it can flush them from its queue, it drops old samples. So until we make a
larger architectural change, such as sharding oximeter, we need to maintain
high throughput in order to avoid dropping samples under high volume. This
change alone may not avoid all dropped samples reported in #10552, but it
should help, and has no obvious downsides.

Part of #10552.
@jmcarp jmcarp requested a review from bnaecker June 30, 2026 19:47
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.

1 participant