kezhenxu94 opened a new issue #2837: [Performance Improvement] Improve SolrJ Agent Plugin's performance URL: https://github.com/apache/skywalking/issues/2837 Please answer these questions before submitting your issue. - Why do you submit this issue? - [ ] Question or discussion - [ ] Bug - [ ] Requirement - [x] Feature or performance improvement ___ ### Requirement or improvement - Please describe about your requirements or improvement suggestions. https://github.com/apache/skywalking/blob/7f2277091dcab2ee7c2cabb414622d4fd99064e8/apm-sniffer/apm-sdk-plugin/solrj-7.x-plugin/src/main/java/org/apache/skywalking/apm/plugin/solrj/SolrClientInterceptor.java#L195-L201 the two methods use `String.format` to concat strings, and in my memory, `String.format` is more expensive than `+` operator. the two methods would be called very frequently in real scenario, and I think improve this is not trivial. What do you think @wu-sheng ? > in the code I posted above, replacing the `String.format` with `+` operator won't effect the readability too much, that's why I think it's worth improving. Below is my benchmark and result: ```java @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) @State(Scope.Thread) @Fork(2) @Warmup(iterations = 4) @Measurement(iterations = 5) public class StringFormatBenchmarkTest { @Benchmark public void testStringFormat() { for (int i = 0; i < 100; i++) { String.format("solrJ/%s%s/%s", i, i, i); } } @Benchmark public void testStringConcat() { for (int i = 0; i < 100; i++) { String a = "solrJ/" + i + i + "/" + i; } } @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.MICROSECONDS) public static void main(String[] args) throws RunnerException { Options options = new OptionsBuilder().include(StringFormatBenchmarkTest.class.getSimpleName()).build(); new Runner(options).run(); } } ``` ```text # JMH version: 1.21 # VM version: JDK 1.8.0_181, Java HotSpot(TM) 64-Bit Server VM, 25.181-b13 # VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/jre/bin/java # VM options: -javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=51939:/Applications/IntelliJ IDEA.app/Contents/bin -Dfile.encoding=UTF-8 # Warmup: 4 iterations, 10 s each # Measurement: 5 iterations, 10 s each # Timeout: 10 min per iteration # Threads: 1 thread, will synchronize iterations # Benchmark mode: Throughput, ops/time # Benchmark: org.apache.skywalking.apm.plugin.solrj.StringFormatBenchmark.testStringConcat ``` ## Result ``` Benchmark Mode Cnt Score Error Units StringFormatBenchmark.testStringConcat thrpt 10 326.444 ± 46.432 ops/ms StringFormatBenchmark.testStringFormat thrpt 10 6.094 ± 1.065 ops/ms ```
---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
