You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by GitBox <gi...@apache.org> on 2023/01/02 05:00:42 UTC

[GitHub] [rocketmq] mxsm opened a new issue, #5804: Optimize BrokerStatsManager#incTopicPutLatency create statsKey

mxsm opened a new issue, #5804:
URL: https://github.com/apache/rocketmq/issues/5804

   BrokerStatsManager#incTopicPutLatency
   ```java
       public void incTopicPutLatency(final String topic, final int queueId, final int incValue) {
           final String statsKey = String.format("%d@%s", queueId, topic);
           this.statsTable.get(TOPIC_PUT_LATENCY).addValue(statsKey, incValue, 1);
       }
   ```
   when use async-profiler to monitor alloc:
   ![image](https://user-images.githubusercontent.com/15797831/210196257-e153a5e6-5c95-4b15-9a10-3def110618eb.png)
   You can see what's going on in the results
   ![image](https://user-images.githubusercontent.com/15797831/210196319-b5b72728-2a9e-4700-8ab9-7d175269be3c.png)
   
   use JMH test it:
   ```java
   package com.github.mxsm;
   
   import java.util.concurrent.TimeUnit;
   import org.openjdk.jmh.annotations.Benchmark;
   import org.openjdk.jmh.annotations.BenchmarkMode;
   import org.openjdk.jmh.annotations.Fork;
   import org.openjdk.jmh.annotations.Measurement;
   import org.openjdk.jmh.annotations.Mode;
   import org.openjdk.jmh.annotations.OutputTimeUnit;
   import org.openjdk.jmh.annotations.Scope;
   import org.openjdk.jmh.annotations.State;
   import org.openjdk.jmh.annotations.Threads;
   import org.openjdk.jmh.annotations.Warmup;
   import org.openjdk.jmh.profile.StackProfiler;
   import org.openjdk.jmh.runner.Runner;
   import org.openjdk.jmh.runner.RunnerException;
   import org.openjdk.jmh.runner.options.Options;
   import org.openjdk.jmh.runner.options.OptionsBuilder;
   
   @BenchmarkMode(Mode.Throughput)
   @Warmup(iterations = 3, time = 2)
   @Measurement(iterations = 3, time = 4)
   @Fork(1)
   @State(value = Scope.Benchmark)
   @OutputTimeUnit(TimeUnit.SECONDS)
   public class TimeZoneBenchmark {
   
   
   
       @Benchmark
       @Threads(8)
       public String formate() {
           String statsKey = String.format("%d@%s", 1, "topic");
           return statsKey;
       }
   
       @Benchmark
       @Threads(8)
       public String build() {
           StringBuilder builder = new StringBuilder(100);
         return builder.append("1").append("@").append("topic").toString();
       }
   
       public static void main(String[] args) throws RunnerException {
           Options opt = new OptionsBuilder()
               .include(TimeZoneBenchmark.class.getSimpleName())
               .addProfiler(StackProfiler.class)
               .build();
           new Runner(opt).run();
       }
   
   }
   ```
   result:
   ```
   # JMH version: 1.35                                                                                                          
   # VM version: JDK 1.8.0_202, Java HotSpot(TM) 64-Bit Server VM, 25.202-b08                                                   
   # VM invoker: D:\Java\jre1.8\bin\java.exe                                                                                    
   # VM options: <none>                                                                                                         
   # Blackhole mode: full + dont-inline hint (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)                   
   # Warmup: 3 iterations, 2 s each                                                                                             
   # Measurement: 3 iterations, 4 s each                                                                                        
   # Timeout: 10 min per iteration                                                                                              
   # Threads: 8 threads, will synchronize iterations                                                                            
   # Benchmark mode: Throughput, ops/time                                                                                       
   # Benchmark: com.github.mxsm.TimeZoneBenchmark.build                                                                         
                                                                                                                                
   # Run progress: 0.00% complete, ETA 00:00:36                                                                                 
   # Fork: 1 of 1                                                                                                               
   # Warmup Iteration   1: 281670107.748 ops/s                                                                                  
   # Warmup Iteration   2: 294751022.585 ops/s                                                                                  
   # Warmup Iteration   3: 296432382.044 ops/s                                                                                  
   Iteration   1: 296893565.805 ops/s                                                                                           
   Iteration   2: 296911950.215 ops/s                                                                                           
   Iteration   3: 297362025.545 ops/s                                                                                           
                                                                                                                                
                                                                                                                                
   Result "com.github.mxsm.TimeZoneBenchmark.build":                                                                            
     297055847.189 ±(99.9%) 4840379.249 ops/s [Average]                                                                         
     (min, avg, max) = (296893565.805, 297055847.189, 297362025.545), stdev = 265317.520                                        
     CI (99.9%): [292215467.940, 301896226.437] (assumes normal distribution)                                                   
                                                                                                                                
                                                                                                                                
   # JMH version: 1.35                                                                                                          
   # VM version: JDK 1.8.0_202, Java HotSpot(TM) 64-Bit Server VM, 25.202-b08                                                   
   # VM invoker: D:\Java\jre1.8\bin\java.exe                                                                                    
   # VM options: <none>                                                                                                         
   # Blackhole mode: full + dont-inline hint (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)                   
   # Warmup: 3 iterations, 2 s each                                                                                             
   # Measurement: 3 iterations, 4 s each                                                                                        
   # Timeout: 10 min per iteration                                                                                              
   # Threads: 8 threads, will synchronize iterations                                                                            
   # Benchmark mode: Throughput, ops/time                                                                                       
   # Benchmark: com.github.mxsm.TimeZoneBenchmark.formate                                                                       
                                                                                                                                
   # Run progress: 50.00% complete, ETA 00:00:18                                                                                
   # Fork: 1 of 1                                                                                                               
   # Warmup Iteration   1: 11176178.079 ops/s                                                                                   
   # Warmup Iteration   2: 12272164.178 ops/s                                                                                   
   # Warmup Iteration   3: 12354547.887 ops/s                                                                                   
   Iteration   1: 12385483.280 ops/s                                                                                            
   Iteration   2: 12457073.897 ops/s                                                                                            
   Iteration   3: 12412801.505 ops/s                                                                                            
                                                                                                                                
                                                                                                                                
   Result "com.github.mxsm.TimeZoneBenchmark.formate":                                                                          
     12418452.894 ±(99.9%) 659115.626 ops/s [Average]                                                                           
     (min, avg, max) = (12385483.280, 12418452.894, 12457073.897), stdev = 36128.352                                            
     CI (99.9%): [11759337.269, 13077568.520] (assumes normal distribution)                                                     
                                                                                                                                
                                                                                                                                
   # Run complete. Total time: 00:00:36                                                                                         
                                                                                                                                
   REMEMBER: The numbers below are just data. To gain reusable insights, you need to follow up on                               
   why the numbers are the way they are. Use profilers (see -prof, -lprof), design factorial                                    
   experiments, perform baseline and negative tests that provide experimental control, make sure                                
   the benchmarking environment is safe on JVM/OS/HW level, ask for reviews from the domain experts.                            
   Do not assume the numbers tell you what you want them to tell.                                                               
                                                                                                                                
   Benchmark                   Mode  Cnt          Score         Error  Units                                                    
   TimeZoneBenchmark.build    thrpt    3  297055847.189 ± 4840379.249  ops/s                                                    
   TimeZoneBenchmark.formate  thrpt    3   12418452.894 ±  659115.626  ops/s                                                    
   ```


-- 
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: commits-unsubscribe@rocketmq.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [rocketmq] RongtongJin closed issue #5804: Optimize BrokerStatsManager#incTopicPutLatency create statsKey

Posted by GitBox <gi...@apache.org>.
RongtongJin closed issue #5804: Optimize BrokerStatsManager#incTopicPutLatency create statsKey
URL: https://github.com/apache/rocketmq/issues/5804


-- 
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: commits-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org