kezhenxu94 opened a new pull request #7263:
URL: https://github.com/apache/skywalking/pull/7263


   Groovy naturally supports many dynamic features that we don't benefit for 
now but cost performance loss, in this patch we compile our Groovy-based DSL 
scripts statically to optimize performance.
   
   ### Improve the performance of LAL
   - [x] Add a benchmark for the improvement, refer to [the existing 
ones](https://github.com/apache/skywalking/blob/master/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   ```java
   
   class MyBenchmark {
   
       ModuleManager manager;
       DSL dsl;
       LogAnalyzerModuleConfig config;
       FilterSpec filter;
   
   
       @Setup
       public void setup() throws ModuleStartException {
           manager = new ModuleManager();
           config = new LogAnalyzerModuleConfig();
           filter = new FilterSpec(manager, config);
           dsl = DSL.of(manager, new LogAnalyzerModuleConfig(), "filter {\n" +
                                                                "  json {\n" +
                                                                "  }\n" +
                                                                "  // only 
collect abnormal logs (http status code >= 300, or 
commonProperties?.responseFlags is not empty)\n" +
                                                                "  if 
(parsed?.response?.responseCode as Integer < 400 && 
!parsed?.commonProperties?.responseFlags) {\n" +
                                                                "    abort 
{}\n" +
                                                                "  }\n" +
                                                                "  extractor 
{\n" +
                                                                "    if 
(parsed?.response?.responseCode) {\n" +
                                                                "      tag 
'status.code': parsed?.response?.responseCode as int\n" +
                                                                "    }\n" +
                                                                "    tag 
'response.flag': parsed?.commonProperties?.responseFlags\n" +
                                                                "  }\n" +
                                                                "  sink {\n" +
                                                                "    sampler 
{\n" +
                                                                "      if 
(parsed?.commonProperties?.responseFlags) {\n" +
                                                                "        // use 
service:errorCode as sampler id so that each service:errorCode has its own 
sampler,\n" +
                                                                "        // 
e.g. checkoutservice:[upstreamConnectionFailure], 
checkoutservice:[upstreamRetryLimitExceeded]\n" +
                                                                "        
rateLimit(\"${log.service}:${parsed?.commonProperties?.responseFlags}\") {\n" +
                                                                "          qps 
100\n" +
                                                                "        }\n" +
                                                                "      } else 
{\n" +
                                                                "        // use 
service:responseCode as sampler id so that each service:responseCode has its 
own sampler,\n" +
                                                                "        // 
e.g. checkoutservice:500, checkoutservice:404.\n" +
                                                                "        
rateLimit(\"${log.service}:${parsed?.response?.responseCode}\") {\n" +
                                                                "          qps 
100\n" +
                                                                "        }\n" +
                                                                "      }\n" +
                                                                "    }\n" +
                                                                "  }\n" +
                                                                "}"
           );
           dsl.bind(new Binding().log(LogData.newBuilder().build()));
       }
   
       @Benchmark
       public void testDSL(Blackhole bh) throws ModuleStartException {
           dsl.evaluate();
       }
   
       public static void main(String[] args) throws RunnerException {
           LogManager.shutdown();
           Options opt = new OptionsBuilder()
                   .warmupForks(3)
                   .forks(5)
                   .include(MyBenchmark.class.getSimpleName())
                   .addProfiler(GCProfiler.class)
                   .build();
   
           new Runner(opt).run();
       }
   }
   ```
   - [x] The benchmark result.
   
     - Before
     ```text
     Benchmark                                              Mode  Cnt       
Score      Error   Units
     MyBenchmark.testDSL                                   thrpt   25  
246670.893 ± 6418.101   ops/s
     MyBenchmark.testDSL:·gc.alloc.rate                    thrpt   25     
602.013 ±   15.646  MB/sec
     MyBenchmark.testDSL:·gc.alloc.rate.norm               thrpt   25    
2688.000 ±    0.001    B/op
     MyBenchmark.testDSL:·gc.churn.PS_Eden_Space           thrpt   25     
602.247 ±   15.530  MB/sec
     MyBenchmark.testDSL:·gc.churn.PS_Eden_Space.norm      thrpt   25    
2689.112 ±   11.894    B/op
     MyBenchmark.testDSL:·gc.churn.PS_Survivor_Space       thrpt   25       
0.058 ±    0.008  MB/sec
     MyBenchmark.testDSL:·gc.churn.PS_Survivor_Space.norm  thrpt   25       
0.257 ±    0.035    B/op
     MyBenchmark.testDSL:·gc.count                         thrpt   25    
1498.000             counts
     MyBenchmark.testDSL:·gc.time                          thrpt   25    
1636.000                 ms
     ```
   
     - After
     ```text
     Benchmark                                              Mode  Cnt       
Score      Error   Units
     MyBenchmark.testDSL                                   thrpt   25  
385547.228 ± 9829.731   ops/s
     MyBenchmark.testDSL:·gc.alloc.rate                    thrpt   25     
627.257 ±   16.030  MB/sec
     MyBenchmark.testDSL:·gc.alloc.rate.norm               thrpt   25    
1792.000 ±    0.001    B/op
     MyBenchmark.testDSL:·gc.churn.PS_Eden_Space           thrpt   25     
628.196 ±   18.549  MB/sec
     MyBenchmark.testDSL:·gc.churn.PS_Eden_Space.norm      thrpt   25    
1794.442 ±   15.527    B/op
     MyBenchmark.testDSL:·gc.churn.PS_Survivor_Space       thrpt   25       
0.066 ±    0.009  MB/sec
     MyBenchmark.testDSL:·gc.churn.PS_Survivor_Space.norm  thrpt   25       
0.190 ±    0.027    B/op
     MyBenchmark.testDSL:·gc.count                         thrpt   25    
1513.000             counts
     MyBenchmark.testDSL:·gc.time                          thrpt   25    
1798.000                 ms
     ```
   
   - [x] Links/URLs to the theory proof or discussion articles/blogs. 
<links/URLs here>
   - [x] If this pull request closes/resolves/fixes an existing issue, replace 
the issue number. Closes #<issue number>. Not close, related to #7180 
   - [x] Update the [`CHANGES` 
log](https://github.com/apache/skywalking/blob/master/CHANGES.md).
   


-- 
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]


Reply via email to