Hariomlokhande-coder opened a new pull request, #4398:
URL: https://github.com/apache/hertzbeat/pull/4398

   ## What's changed?
   
   Closes #4388.
   
   `NginxCollectImpl.regexNginxStatusMatch()` called `Pattern.compile()` on 
`REGEX_SERVER`, `REGEX_KEYS` and `REGEX_VALUES` on every invocation, even 
though all three are compile-time constants:
   
   ```java
   private static final String REGEX_KEYS = "server\s+(\w+)\s+(\w+)\s+(\w+)";
   private static final String REGEX_VALUES = "(\d+) (\d+) (\d+)";
   private static final String REGEX_SERVER = "(\w+): (\d+)";
   ...
   Pattern pattern  = Pattern.compile(REGEX_SERVER);
   Pattern pattern1 = Pattern.compile(REGEX_KEYS);
   Pattern pattern2 = Pattern.compile(REGEX_VALUES);
   ```
   
   That method is reached from `collect()`, so the same unchanging patterns 
were recompiled once per collection cycle for every Nginx monitor.
   
   This change holds them as `static final Pattern` fields, compiled once at 
class load, and reuses the instances. The constants are used nowhere else in 
the file, so the change is local to `NginxCollectImpl`.
   
   ## Verification
   
   - `NginxCollectImplTest`: 7 tests, 0 failures
   - `checkstyle:check` passes
   
   A small benchmark of the two shapes (2,000,000 iterations, same three 
patterns) measured roughly 7.8s for recompile-per-call versus 6.9s for 
compile-once. Modest, but it is wasted work on a path that runs on every 
collection interval.
   
   ## Checklist
   
   - [x]  I have read the [Contributing 
Guide](https://hertzbeat.apache.org/docs/community/code_style_and_quality_guide)
   - [x]  I have written the necessary doc or comment.
   - [x]  I have added the necessary unit tests and all cases have passed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to