Skip to content

avoid contending on single process-wide precompiled regexes #37

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

Merged
merged 3 commits into from
Mar 27, 2025

Conversation

iximeow
Copy link
Contributor

@iximeow iximeow commented Mar 27, 2025

precompiling the Regex instances is good! but being behind
lazy_static! means all threads are contending an implicit futex
somewhere in the lazy_static implementation. on a 32-core system with 32
logs to process in parallel, this ends up with the top symbol in
perf stat to be something in futex and an awful lot of total time
waiting on system stuff for no apparent reason.

having set of Regex bundles per-thread keeps contention down at the
cost of a bit more init on the multi-processor case, but overall at
least on my system brings a 31-file benchmark down from 4.6 seconds to
about 2.2 seconds.

i included a bonus second change to make the read buffers a bit larger but that's not nearly as useful

iximeow and others added 3 commits March 27, 2025 07:19
precompiling the `Regex` instances is good! but being behind
`lazy_static!` means all threads are contending an implicit futex
somewhere in the lazy_static implementation. on a 32-core system with 32
logs to process in parallel, this ends up with the top symbol in
`perf stat` to be something in `futex` and an awful lot of total time
waiting on _system stuff_ for no apparent reason.

having set of Regex bundles per-thread keeps contention down at the
cost of a bit more init on the multi-processor case, but overall at
least on my system brings a 31-file benchmark down from 4.6 seconds to
about 2.2 seconds.
no reason to limit to 128k really, probably not a big deal either way
@indirect indirect merged commit 2b2fe64 into rubytogether:main Mar 27, 2025
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.

2 participants