Don't create exceptions in RegexExtractor on failed extractions - #6759
Open
ashrafiucse wants to merge 1 commit into
Open
Don't create exceptions in RegexExtractor on failed extractions#6759ashrafiucse wants to merge 1 commit into
ashrafiucse wants to merge 1 commit into
Conversation
Every failed extraction called RegexExtractor#removeGroups, which parsed the (still absent) group-count variable with Integer#parseInt. Parsing null always throws a NumberFormatException, which was caught and silently discarded, so each failing extraction paid for creating an exception. In failure-heavy test runs the failed extractions are the hot path, e.g. the reporter of the issue measured thousands of discarded exceptions per second. Parse the internal group-count and match-count variables without relying on exceptions. The parsing behaves like before: absent variables yield the previous default values, and values that are present but not numbers still log a warning. Closes apache#6240
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RegexExtractornow parses its internal group-count and match-count variables (<refname>_g,<refname>_matchNr) without relying on exceptions, via a smallparseIntOrDefaulthelper. Values that are present but not numbers still log the same warning as before; absent variables yield the previous default values, so behavior is unchanged.Motivation and Context
Fixes #6240
Every failed extraction calls
RegexExtractor#removeGroups, which parsed the (still absent) group-count variable withInteger#parseInt. Parsingnullalways throws aNumberFormatException, which was caught and silently discarded:So each failing extraction paid for creating and discarding an exception. In failure-heavy test runs (which are exactly the scenario a load test exercises against a struggling system), failed extractions are the hot path.
I verified this against a locally built distribution with
-Xlog:exceptions=info(which reports every thrown exception, including caught ones): a test plan with a non-matching extractor over 200 iterations produced exactly 200NumberFormatExceptions, all inRegexExtractor.removeGroups(one per failed extraction, and nothing visible in jmeter.log). A matching-extractor control run produced zero. With this change the failing run produces zero exceptions.For scale: the exception costs roughly 0.5 µs per failed extraction, so this is a modest but free win, and it also removes the pointless churn. The remaining
parseIntcall inside the helper only triggers for well-formed digit strings.How Has This Been Tested?
TestRegexExtractor:testNoMatchOnFreshVariablesAppliesDefault: the previously exception-throwing path (no match, no prior group variables) applies the default and leaves no group variables behindtestNoMatchCleansUpPreviousGroupVariables: group variables from an earlier successful extraction are cleaned up on failuretestNoMatchWithTamperedGroupCountVariable: a corrupted<refname>_gvalue is handled (warn + default) without breaking the extractiontestAllMatchesWithTamperedMatchNumberVariable: a corrupted<refname>_matchNrvalue does not break all-matches modeTestRegexExtractortests and the full:src:components:testsuite (553 tests) pass./gradlew classes stylepassesTypes of changes
Checklist:
xdocs/changes.xml)