You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/02/08 09:57:18 UTC

[GitHub] [shardingsphere] TeslaCN opened a new pull request #15292: Reduce overhead of Mod/HashMod sharding algorithm

TeslaCN opened a new pull request #15292:
URL: https://github.com/apache/shardingsphere/pull/15292


   Related to #10626.
   
   ### Before
   ```
   Benchmark                                                (shardingCount)   Mode  Cnt      Score     Error   Units
   ModShardingAlgorithmBenchmark.benchModShardingAlgorithm                1  thrpt    3  17616.614 ± 638.211  ops/ms
   ModShardingAlgorithmBenchmark.benchModShardingAlgorithm              100  thrpt    3    401.371 ±  54.960  ops/ms
   ```
   
   ### After
   
   ```
   Benchmark                                                (shardingCount)   Mode  Cnt       Score      Error   Units
   ModShardingAlgorithmBenchmark.benchModShardingAlgorithm                1  thrpt    3  104468.834 ± 7549.259  ops/ms
   ModShardingAlgorithmBenchmark.benchModShardingAlgorithm              100  thrpt    3    6948.775 ±  254.191  ops/ms
   ```
   
   ### JMH Benchmark
   ```java
   package icu.wwj.jmh.shardingsphere5.code;
   
   import org.apache.shardingsphere.sharding.algorithm.sharding.mod.ModShardingAlgorithm;
   import org.apache.shardingsphere.sharding.api.sharding.standard.PreciseShardingValue;
   import org.openjdk.jmh.Main;
   import org.openjdk.jmh.annotations.Benchmark;
   import org.openjdk.jmh.annotations.Fork;
   import org.openjdk.jmh.annotations.Level;
   import org.openjdk.jmh.annotations.Measurement;
   import org.openjdk.jmh.annotations.OutputTimeUnit;
   import org.openjdk.jmh.annotations.Param;
   import org.openjdk.jmh.annotations.Scope;
   import org.openjdk.jmh.annotations.Setup;
   import org.openjdk.jmh.annotations.State;
   import org.openjdk.jmh.annotations.Warmup;
   
   import java.io.IOException;
   import java.util.Collection;
   import java.util.concurrent.ThreadLocalRandom;
   import java.util.concurrent.TimeUnit;
   import java.util.stream.Collectors;
   import java.util.stream.IntStream;
   
   @Fork(1)
   @Warmup(iterations = 3, time = 5)
   @Measurement(iterations = 3, time = 5)
   @State(Scope.Thread)
   @OutputTimeUnit(TimeUnit.MILLISECONDS)
   public class ModShardingAlgorithmBenchmark {
       
       @Param({"1", "100"})
       private static int shardingCount;
       
       private final ModShardingAlgorithm algorithm = new ModShardingAlgorithm();
       
       private final ThreadLocalRandom random = ThreadLocalRandom.current();
       
       private Collection<String> availableTargets = IntStream.range(0, shardingCount).mapToObj(each -> "ds_" + each).collect(Collectors.toList());
       
       @Setup(Level.Trial)
       public void setup() {
           algorithm.getProps().setProperty("sharding-count", "" + shardingCount);
           algorithm.init();
           availableTargets = IntStream.range(0, shardingCount).mapToObj(each -> "ds_" + each).collect(Collectors.toList());
       }
       
       @Benchmark
       public String benchModShardingAlgorithm() {
           return algorithm.doSharding(availableTargets, new PreciseShardingValue<>("", "", random.nextLong(Long.MAX_VALUE)));
       }
       
       public static void main(String[] args) throws IOException {
           String[] result = new String[1 + args.length];
           result[0] = ModShardingAlgorithmBenchmark.class.getName();
           System.arraycopy(args, 0, result, 1, args.length);
           Main.main(result);
       }
   }
   ```


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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



[GitHub] [shardingsphere] tristaZero merged pull request #15292: Reduce overhead of Mod/HashMod sharding algorithm

Posted by GitBox <gi...@apache.org>.
tristaZero merged pull request #15292:
URL: https://github.com/apache/shardingsphere/pull/15292


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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