qxo commented on issue #3068: improve ContextManager.stopSpan performance: call 
ThreadLocal only once
URL: https://github.com/apache/skywalking/pull/3068#issuecomment-511207714
 
 
   and ContextManageStopSpanBenchmark code:
   ```
   import java.util.concurrent.TimeUnit;
   
   import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
   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.Warmup;
   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;
   import org.openjdk.jmh.runner.options.TimeValue;
   
   @Fork(0)
   @Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
   @Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
   @BenchmarkMode(Mode.Throughput)
   @OutputTimeUnit(TimeUnit.MILLISECONDS)
   @State(Scope.Benchmark)
   public class ContextManageStopSpanBenchmark {
   
       // private static final AbstractSpan TEST_SPAN =
       // ContextManager.createLocalSpan("test");
   
       @Benchmark
       public Object getThreadLocalOnce1() {
           final AbstractSpan span = ContextManager.createLocalSpan("test");
           ContextManager.stopSpan(span);
           return span;
       }
   
       @Benchmark
       public Object getThreadLocalTwice() {
           final AbstractSpan span = ContextManager.createLocalSpan("test");
           ContextManager.get();
            ContextManager.stopSpan(span);
           return span;
       }
       
       @Benchmark
       public Object getThreadLocalFour() {
           final AbstractSpan span = ContextManager.createLocalSpan("test");
           ContextManager.get();
           ContextManager.get();
           ContextManager.get();
           ContextManager.stopSpan(span);
           return span;
       }
   
       public static void main(String[] args) throws RunnerException {
           Options opt = new 
OptionsBuilder().include(ContextManageStopSpanBenchmark.class.getSimpleName())
                   
.mode(Mode.Throughput).warmupIterations(8).measurementIterations(8).forks(3)
                   
.measurementTime(TimeValue.seconds(1)).warmupTime(TimeValue.seconds(1)).threads(4)
                   .timeUnit(TimeUnit.MILLISECONDS).build();
           new Runner(opt).run();
       }
   }
   ```
   required ContextManager.get from "private" to "default"
   I done for the pull, change code as you wish:)

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

Reply via email to