regex - Java : Matcher.find using high cpu utilization -


i using mod security rules https://github.com/spiderlabs/owasp-modsecurity-crs sanitize user input data. facing cpu shoot , delay in matching user input mod security rule regular expressions. overall contains 500+ regular expression check different types of attacks(xss , badrobots , generic , sql). each request , go through parameters , check against these 500 regular expressions. using matcher.find check parameters. in case parameters fall in infinite looping , tackled using below technique.

cancelling long running regex match?.

sanitize user request took around ~500 ms , cpu % shoots up. analyzed using visualvm.java.net test suite runner.

cpu profile output

enter image description here

please me reduce cpu usage % , load average?

if possible, compile regexes once , keep them around, rather repeatedly (implicitly) compiling (especially inside loop).
see java.util.regex - importance of pattern.compile()? more info.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -