karouani / javasimon

Automatically exported from code.google.com/p/javasimon
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

SqlNormalizer is CPU expensive during JDBC profiling #125

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When using the javasimon JDBC driver to obtain JDBC performance profiling I've 
found that the SqlNormalizer is using excessive CPU, to the point that it is 
noticeably affecting the performance itself.

I am using Hibernate as the ORM library which already formats SQL in a 
consistent pattern.  Can an option be added to the Javasimon JDBC Driver that 
disables SQL normalisation?

Below is a snippet from a thread dump showing a stacktrace containing the 
SqlNormalizer.  CPU sampling using JVisualVM also showed that the SqlNormaliser 
was a CPU hog.

"pool-8-thread-1" prio=6 tid=0x000000001a0d4000 nid=0x1ec0 runnable 
[0x0000000022a4b000]
   java.lang.Thread.State: RUNNABLE
        at java.util.Arrays.copyOf(Unknown Source)
        at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source)
        at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source)
        at java.lang.AbstractStringBuilder.append(Unknown Source)
        at java.lang.StringBuffer.append(Unknown Source)
        - locked <0x000000009ce39ec0> (a java.lang.StringBuffer)
        at java.util.regex.Matcher.appendReplacement(Unknown Source)
        at java.util.regex.Matcher.replaceAll(Unknown Source)
        at org.javasimon.utils.Replacer.process(Replacer.java:88)
        at org.javasimon.jdbc4.SqlNormalizer.applyReplacers(SqlNormalizer.java:114)
        at org.javasimon.jdbc4.SqlNormalizer.normalize(SqlNormalizer.java:97)
        at org.javasimon.jdbc4.SqlNormalizer.<init>(SqlNormalizer.java:78)
        at org.javasimon.jdbc4.SimonStatement.prepare(SimonStatement.java:122)
        at org.javasimon.jdbc4.SimonStatement.executeBatch(SimonStatement.java:346)
        at com.jolbox.bonecp.StatementHandle.executeBatch(StatementHandle.java:424)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
        at org.hibernate.jdbc.BatchingBatcher.addToBatch(BatchingBatcher.java:56)

Original issue reported on code.google.com by Steven.J...@gmail.com on 3 Jul 2014 at 3:52

GoogleCodeExporter commented 8 years ago
I need to check it. That normalization is there for a reason, otherwise you 
could end up with tons of simons - each for every call even, if someone does 
sqls with string concatenation (not that I approve). We can add an option to 
disable it, but then even one single exception in your code can cause problems. 
BTW: What version do you use?

If you can come up with a patch that works in your situation that would be best.

Original comment by virgo47 on 3 Jul 2014 at 6:18

GoogleCodeExporter commented 8 years ago
Thanks for the quick response.  I'm using 3.5.1.  I'll see about creating a 
patch.

Original comment by Steven.J...@gmail.com on 4 Jul 2014 at 12:48

GoogleCodeExporter commented 8 years ago
Closed here - moved to https://github.com/virgo47/javasimon/issues/2

Original comment by virgo47 on 29 Oct 2014 at 10:01