Repository: alibaba/sentinel-golang
Pull request #328 (2020-11-21 08:39:10)

Refine benchmark cases

### Describe what this PR does / why we need it


### Does this pull request fix one issue?

<!--If that, add "Fixes #xxxx" below in the next line. For example, Fixes #15. Otherwise, add "NONE" -->

### Describe how you did it


### Describe how to verify it


### Special notes for reviews

codecov-io: # [Codecov](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=h1) Report
> Merging [#328](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=desc) (286ceef) into [master](https://codecov.io/gh/alibaba/sentinel-golang/commit/8d33c7c0e0bb6448a6f7f66e6118208954651bf9?el=desc) (8d33c7c) will **decrease** coverage by `0.27%`.
> The diff coverage is `0.00%`.

[![Impacted file tree graph](https://codecov.io/gh/alibaba/sentinel-golang/pull/328/graphs/tree.svg?width=650&height=150&src=pr&token=SrpzbhKA3E)](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
- Coverage   50.91%   50.63%   -0.28%     
==========================================
  Files          68       69       +1     
  Lines        3814     3835      +21     
==========================================
  Hits         1942     1942              
- Misses       1606     1624      +18     
- Partials      266      269       +3     
```


| [Impacted Files](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [core/circuitbreaker/circuit\_breaker.go](https://codecov.io/gh/alibaba/sentinel-golang/pull/328/diff?src=pr&el=tree#diff-Y29yZS9jaXJjdWl0YnJlYWtlci9jaXJjdWl0X2JyZWFrZXIuZ28=) | `65.46% <0.00%> (-2.70%)` | :arrow_down: |
| [core/stat/base/leap\_array.go](https://codecov.io/gh/alibaba/sentinel-golang/pull/328/diff?src=pr&el=tree#diff-Y29yZS9zdGF0L2Jhc2UvbGVhcF9hcnJheS5nbw==) | `70.40% <0.00%> (-1.47%)` | :arrow_down: |
| [tests/benchmark/env\_init.go](https://codecov.io/gh/alibaba/sentinel-golang/pull/328/diff?src=pr&el=tree#diff-dGVzdHMvYmVuY2htYXJrL2Vudl9pbml0Lmdv) | `0.00% <0.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=footer). Last update [8d33c7c...286ceef](https://codecov.io/gh/alibaba/sentinel-golang/pull/328?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/go.sum b/go.sum
index 979b38a..e41669e 100644
--- a/go.sum
+++ b/go.sum
@@ -1,8 +1,11 @@
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
 github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
+github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
 github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
 github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -10,13 +13,19 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
 github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
+github.com/shirou/gopsutil v2.19.12+incompatible h1:WRstheAymn1WOPesh+24+bZKFkqrdCR8JOc77v4xV3Q=
 github.com/shirou/gopsutil v2.19.12+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
+github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
 github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
 github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+go.uber.org/atomic v1.6.0 h1:Ezj3JGmsOnG1MoRWQkPBsKLe9DwWD9QeXzTRzzldNVk=
 go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
+go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
 go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
 go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -28,6 +37,7 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
 golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
 golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
@@ -39,5 +49,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
 gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
 honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=


Test patch:
diff --git a/tests/benchmark/circuitbreaker/circuitbreaker_benchmark_test.go b/tests/benchmark/circuitbreaker/circuitbreaker_benchmark_test.go
index 3a9f83b..906623c 100644
--- a/tests/benchmark/circuitbreaker/circuitbreaker_benchmark_test.go
+++ b/tests/benchmark/circuitbreaker/circuitbreaker_benchmark_test.go
@@ -4,195 +4,186 @@ import (
 	"log"
 	"testing"
 
-	"github.com/alibaba/sentinel-golang/api"
+	sentinel "github.com/alibaba/sentinel-golang/api"
 	"github.com/alibaba/sentinel-golang/core/circuitbreaker"
+	"github.com/alibaba/sentinel-golang/tests/benchmark"
 )
 
-func doCheck() {
-	if se, err := api.Entry("abc"); err == nil {
+const (
+	resSlowRt     = "abc-slowRt"
+	resErrorRatio = "abc-errorRatio"
+	resErrorCount = "abc-errorCount"
+)
+
+func doCheck(res string) {
+	if se, err := sentinel.Entry(res); err == nil {
 		se.Exit()
 	} else {
 		log.Fatalf("Block err: %s", err.Error())
 	}
 }
 
-func loadSlowRequestRatioRule() {
-	rule := &circuitbreaker.Rule{
-		Resource:         "abc",
+func init() {
+	benchmark.InitSentinel()
+	rule1 := &circuitbreaker.Rule{
+		Resource:         resSlowRt,
 		Strategy:         circuitbreaker.SlowRequestRatio,
 		RetryTimeoutMs:   1000,
 		MinRequestAmount: 5,
 		StatIntervalMs:   1000,
-		MaxAllowedRtMs:   20,
-		Threshold:        0.1,
+		MaxAllowedRtMs:   100000,
+		Threshold:        0.99,
 	}
-	circuitbreaker.LoadRules([]*circuitbreaker.Rule{rule})
-}
-
-func loadErrorRatioRule() {
-	rule := &circuitbreaker.Rule{
-		Resource:         "abc",
+	rule2 := &circuitbreaker.Rule{
+		Resource:         resErrorRatio,
 		Strategy:         circuitbreaker.ErrorRatio,
 		RetryTimeoutMs:   1000,
 		MinRequestAmount: 5,
 		StatIntervalMs:   1000,
-		Threshold:        0.3,
+		Threshold:        0.99,
 	}
-	circuitbreaker.LoadRules([]*circuitbreaker.Rule{rule})
-}
-
-func loadErrorCountRule() {
-	rule := &circuitbreaker.Rule{
-		Resource:         "abc",
+	rule3 := &circuitbreaker.Rule{
+		Resource:         resErrorCount,
 		Strategy:         circuitbreaker.ErrorCount,
 		RetryTimeoutMs:   1000,
 		MinRequestAmount: 5,
 		StatIntervalMs:   1000,
-		Threshold:        10.0,
+		Threshold:        10000.0,
+	}
+	_, err := circuitbreaker.LoadRules([]*circuitbreaker.Rule{rule1, rule2, rule3})
+	if err != nil {
+		panic(err)
 	}
-	circuitbreaker.LoadRules([]*circuitbreaker.Rule{rule})
 }
 
 func Benchmark_SlowRequestRatio_SlotCheck_4(b *testing.B) {
-	loadSlowRequestRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resSlowRt)
 		}
 	})
 }
 
 func Benchmark_SlowRequestRatio_SlotCheck_8(b *testing.B) {
-	loadSlowRequestRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resSlowRt)
 		}
 	})
 }
 
 func Benchmark_SlowRequestRatio_SlotCheck_16(b *testing.B) {
-	loadSlowRequestRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resSlowRt)
 		}
 	})
 }
 
 func Benchmark_SlowRequestRatio_SlotCheck_32(b *testing.B) {
-	loadSlowRequestRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(32)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resSlowRt)
 		}
 	})
 }
 
 func Benchmark_ErrorRatio_SlotCheck_4(b *testing.B) {
-	loadErrorRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorRatio)
 		}
 	})
 }
 
 func Benchmark_ErrorRatio_SlotCheck_8(b *testing.B) {
-	loadErrorRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorRatio)
 		}
 	})
 }
 
 func Benchmark_ErrorRatio_SlotCheck_16(b *testing.B) {
-	loadErrorRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorRatio)
 		}
 	})
 }
 
 func Benchmark_ErrorRatio_SlotCheck_32(b *testing.B) {
-	loadErrorRatioRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(32)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorRatio)
 		}
 	})
 }
 
 func Benchmark_ErrorCount_SlotCheck_4(b *testing.B) {
-	loadErrorCountRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorCount)
 		}
 	})
 }
 
 func Benchmark_ErrorCount_SlotCheck_8(b *testing.B) {
-	loadErrorCountRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorCount)
 		}
 	})
 }
 
 func Benchmark_ErrorCount_SlotCheck_16(b *testing.B) {
-	loadErrorCountRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorCount)
 		}
 	})
 }
 
 func Benchmark_ErrorCount_SlotCheck_32(b *testing.B) {
-	loadErrorCountRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(32)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resErrorCount)
 		}
 	})
 }
diff --git a/tests/benchmark/entry/entry_benchmark_test.go b/tests/benchmark/entry/entry_benchmark_test.go
index 9bca1b8..400a4a0 100644
--- a/tests/benchmark/entry/entry_benchmark_test.go
+++ b/tests/benchmark/entry/entry_benchmark_test.go
@@ -2,246 +2,114 @@ package entry
 
 import (
 	"fmt"
-	"log"
-	"math/rand"
-	"sort"
 	"testing"
-	"time"
 
 	sentinel "github.com/alibaba/sentinel-golang/api"
 	"github.com/alibaba/sentinel-golang/core/base"
-	"github.com/alibaba/sentinel-golang/core/config"
 	"github.com/alibaba/sentinel-golang/core/stat"
-	"github.com/alibaba/sentinel-golang/logging"
+	"github.com/alibaba/sentinel-golang/tests/benchmark"
 )
 
-var numbers = make([]int, 0)
-
-func initNumberWith50() {
-	numbers = make([]int, 0, 50)
-	for i := 0; i < 50; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-
-func initNumberWith100() {
-	numbers = make([]int, 0, 100)
-	for i := 0; i < 100; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-
-func initNumberWith200() {
-	numbers = make([]int, 0, 200)
-	for i := 0; i < 200; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-
-func initNumberWith500() {
-	numbers = make([]int, 0, 500)
-	for i := 0; i < 500; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-
-func initNumberWith1000() {
-	numbers = make([]int, 0, 1000)
-	for i := 0; i < 1000; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-
-func initNumberWith2000() {
-	numbers = make([]int, 0, 2000)
-	for i := 0; i < 2000; i++ {
-		numbers = append(numbers, rand.Int())
-	}
-}
-func initNumberWith4000() {
-	numbers = make([]int, 0, 4000)
-	for i := 0; i < 4000; i++ {
-		numbers = append(numbers, rand.Int())
-	}
+func init() {
+	benchmark.InitSentinel()
 }
 
-func doSomething() {
-	sort.Ints(numbers)
-	//rand.Shuffle(len(numbers), func(i, j int) { numbers[i], numbers[j] = numbers[j], numbers[i] })
+func newSlotChain() *base.SlotChain {
+	slotChain := base.NewSlotChain()
+	slotChain.AddStatPrepareSlot(stat.DefaultResourceNodePrepareSlot)
+	slotChain.AddStatSlot(stat.DefaultSlot)
+	return slotChain
 }
 
-func doSomethingWithSentinel() {
-	e, b := sentinel.Entry("benchmark_stat_entry")
+func sentinelEntry(sc *base.SlotChain) {
+	e, b := sentinel.Entry("entry_benchmark_test", sentinel.WithSlotChain(sc))
 	if b != nil {
-		fmt.Println("Blocked")
+		fmt.Println("blocked")
 	} else {
-		doSomething()
 		e.Exit()
 	}
 }
 
-func init() {
-	rand.Seed(time.Now().UnixNano())
-	// We should initialize Sentinel first.
-	conf := config.NewDefaultConfig()
-	// for testing, logging output to console
-	conf.Sentinel.Log.Logger = logging.NewConsoleLogger()
-	conf.Sentinel.Log.Metric.FlushIntervalSec = 0
-	conf.Sentinel.Stat.System.CollectIntervalMs = 0
-	err := sentinel.InitWithConfig(conf)
-	if err != nil {
-		log.Fatal(err)
-	}
-}
-
-func Benchmark_SlotChain_Full_Global(b *testing.B) {
-	initNumberWith50()
+func Benchmark_Entry_Concurrency_1(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		e, b := sentinel.Entry("Benchmark_SlotChain_Full_Global", sentinel.WithSlotChain(sentinel.GlobalSlotChain()))
-		if b != nil {
-			logging.Warn("Blocked")
-		} else {
-			doSomething()
-			e.Exit()
+	b.SetParallelism(1)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
 		}
-	}
+	})
 }
 
-func Benchmark_SlotChain_Custom_Empty(b *testing.B) {
-	initNumberWith50()
-	sc := base.NewSlotChain()
-	sc.AddStatPrepareSlot(stat.DefaultResourceNodePrepareSlot)
-	sc.AddStatSlot(stat.DefaultSlot)
+func Benchmark_Entry_Concurrency_4(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		e, b := sentinel.Entry("Benchmark_Custom_Empty_SlotChain", sentinel.WithSlotChain(sc))
-		if b != nil {
-			logging.Warn("Blocked")
-		} else {
-			doSomething()
-			e.Exit()
+	b.SetParallelism(4)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
 		}
-	}
-}
-
-func Benchmark_Single_Directly_50(b *testing.B) {
-	initNumberWith50()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_50(b *testing.B) {
-	initNumberWith50()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
-}
-
-func Benchmark_Single_Directly_100(b *testing.B) {
-	initNumberWith100()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_100(b *testing.B) {
-	initNumberWith100()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	})
 }
 
-func Benchmark_Single_Directly_200(b *testing.B) {
-	initNumberWith200()
+func Benchmark_Entry_Concurrency_8(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_200(b *testing.B) {
-	initNumberWith200()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	b.SetParallelism(8)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
+		}
+	})
 }
 
-func Benchmark_Single_Directly_500(b *testing.B) {
-	initNumberWith500()
+func Benchmark_Entry_Concurrency_16(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_500(b *testing.B) {
-	initNumberWith500()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	b.SetParallelism(16)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
+		}
+	})
 }
 
-func Benchmark_Single_Directly_1000(b *testing.B) {
-	initNumberWith1000()
+func Benchmark_Entry_Concurrency_32(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_1000(b *testing.B) {
-	initNumberWith1000()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	b.SetParallelism(32)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
+		}
+	})
 }
 
-func Benchmark_Single_Directly_2000(b *testing.B) {
-	initNumberWith2000()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_2000(b *testing.B) {
-	initNumberWith2000()
+func Benchmark_Entry_Concurrency_48(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	b.SetParallelism(48)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
+		}
+	})
 }
 
-func Benchmark_Single_Directly_4000(b *testing.B) {
-	initNumberWith4000()
+func Benchmark_Entry_Concurrency_64(b *testing.B) {
+	sc := newSlotChain()
 	b.ReportAllocs()
 	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomething()
-	}
-}
-func Benchmark_Single_StatEntry_4000(b *testing.B) {
-	initNumberWith4000()
-	b.ReportAllocs()
-	b.ResetTimer()
-	for i := 0; i < b.N; i++ {
-		doSomethingWithSentinel()
-	}
+	b.SetParallelism(64)
+	b.RunParallel(func(pb *testing.PB) {
+		for pb.Next() {
+			sentinelEntry(sc)
+		}
+	})
 }
diff --git a/tests/benchmark/entry/entry_comparison_benchmark_test.go b/tests/benchmark/entry/entry_comparison_benchmark_test.go
new file mode 100644
index 0000000..1938a51
--- /dev/null
+++ b/tests/benchmark/entry/entry_comparison_benchmark_test.go
@@ -0,0 +1,230 @@
+package entry
+
+import (
+	"fmt"
+	"math/rand"
+	"sort"
+	"testing"
+
+	sentinel "github.com/alibaba/sentinel-golang/api"
+	"github.com/alibaba/sentinel-golang/core/base"
+	"github.com/alibaba/sentinel-golang/core/stat"
+	"github.com/alibaba/sentinel-golang/logging"
+)
+
+var numbers = make([]int, 0)
+
+func initNumberWith50() {
+	numbers = make([]int, 0, 50)
+	for i := 0; i < 50; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func initNumberWith100() {
+	numbers = make([]int, 0, 100)
+	for i := 0; i < 100; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func initNumberWith200() {
+	numbers = make([]int, 0, 200)
+	for i := 0; i < 200; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func initNumberWith500() {
+	numbers = make([]int, 0, 500)
+	for i := 0; i < 500; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func initNumberWith1000() {
+	numbers = make([]int, 0, 1000)
+	for i := 0; i < 1000; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func initNumberWith2000() {
+	numbers = make([]int, 0, 2000)
+	for i := 0; i < 2000; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+func initNumberWith4000() {
+	numbers = make([]int, 0, 4000)
+	for i := 0; i < 4000; i++ {
+		numbers = append(numbers, rand.Int())
+	}
+}
+
+func doSomething() {
+	sort.Ints(numbers)
+	//rand.Shuffle(len(numbers), func(i, j int) { numbers[i], numbers[j] = numbers[j], numbers[i] })
+}
+
+func doSomethingWithSentinel() {
+	e, b := sentinel.Entry("benchmark_entry_comparison")
+	if b != nil {
+		fmt.Println("Blocked")
+	} else {
+		doSomething()
+		e.Exit()
+	}
+}
+
+func Benchmark_SlotChain_Full_Global(b *testing.B) {
+	initNumberWith50()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		e, b := sentinel.Entry("Benchmark_SlotChain_Full_Global", sentinel.WithSlotChain(sentinel.GlobalSlotChain()))
+		if b != nil {
+			logging.Warn("Blocked")
+		} else {
+			doSomething()
+			e.Exit()
+		}
+	}
+}
+
+func Benchmark_SlotChain_Custom_Empty(b *testing.B) {
+	initNumberWith50()
+	sc := base.NewSlotChain()
+	sc.AddStatPrepareSlot(stat.DefaultResourceNodePrepareSlot)
+	sc.AddStatSlot(stat.DefaultSlot)
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		e, b := sentinel.Entry("Benchmark_Custom_Empty_SlotChain", sentinel.WithSlotChain(sc))
+		if b != nil {
+			logging.Warn("Blocked")
+		} else {
+			doSomething()
+			e.Exit()
+		}
+	}
+}
+
+func Benchmark_Single_Directly_50(b *testing.B) {
+	initNumberWith50()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_50(b *testing.B) {
+	initNumberWith50()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_100(b *testing.B) {
+	initNumberWith100()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_100(b *testing.B) {
+	initNumberWith100()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_200(b *testing.B) {
+	initNumberWith200()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_200(b *testing.B) {
+	initNumberWith200()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_500(b *testing.B) {
+	initNumberWith500()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_500(b *testing.B) {
+	initNumberWith500()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_1000(b *testing.B) {
+	initNumberWith1000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_1000(b *testing.B) {
+	initNumberWith1000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_2000(b *testing.B) {
+	initNumberWith2000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_2000(b *testing.B) {
+	initNumberWith2000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
+
+func Benchmark_Single_Directly_4000(b *testing.B) {
+	initNumberWith4000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomething()
+	}
+}
+func Benchmark_Single_StatEntry_4000(b *testing.B) {
+	initNumberWith4000()
+	b.ReportAllocs()
+	b.ResetTimer()
+	for i := 0; i < b.N; i++ {
+		doSomethingWithSentinel()
+	}
+}
diff --git a/tests/benchmark/entry/entry_benchmark_concurrency_test.go b/tests/benchmark/entry/entry_comparison_concurrency_benchmark_test.go
similarity index 97%
rename from tests/benchmark/entry/entry_benchmark_concurrency_test.go
rename to tests/benchmark/entry/entry_comparison_concurrency_benchmark_test.go
index 19f2878..731d6a3 100644
--- a/tests/benchmark/entry/entry_benchmark_concurrency_test.go
+++ b/tests/benchmark/entry/entry_comparison_concurrency_benchmark_test.go
@@ -19,7 +19,7 @@ func doSomethingWithSize() {
 }
 
 func doSomethingWithSentinelForConcurrency() {
-	e, b := sentinel.Entry("benchmark_stat_entry")
+	e, b := sentinel.Entry("benchmark_entry_comparison_concurrency")
 	if b != nil {
 		fmt.Println("Blocked")
 	} else {
diff --git a/tests/benchmark/env_init.go b/tests/benchmark/env_init.go
new file mode 100644
index 0000000..be46d60
--- /dev/null
+++ b/tests/benchmark/env_init.go
@@ -0,0 +1,22 @@
+package benchmark
+
+import (
+	"log"
+
+	sentinel "github.com/alibaba/sentinel-golang/api"
+	"github.com/alibaba/sentinel-golang/core/config"
+	"github.com/alibaba/sentinel-golang/logging"
+)
+
+func InitSentinel() {
+	// We should initialize Sentinel first.
+	conf := config.NewDefaultConfig()
+	// for testing, logging output to console
+	conf.Sentinel.Log.Logger = logging.NewConsoleLogger()
+	conf.Sentinel.Log.Metric.FlushIntervalSec = 0
+	conf.Sentinel.Stat.System.CollectIntervalMs = 0
+	err := sentinel.InitWithConfig(conf)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
diff --git a/tests/benchmark/flow/flow_benchmark_test.go b/tests/benchmark/flow/flow_benchmark_test.go
index 6ccd7e3..1bc651c 100644
--- a/tests/benchmark/flow/flow_benchmark_test.go
+++ b/tests/benchmark/flow/flow_benchmark_test.go
@@ -5,33 +5,36 @@ import (
 	"math"
 	"testing"
 
-	"github.com/alibaba/sentinel-golang/api"
+	sentinel "github.com/alibaba/sentinel-golang/api"
 	"github.com/alibaba/sentinel-golang/core/flow"
+	"github.com/alibaba/sentinel-golang/tests/benchmark"
 )
 
-func doCheck() {
-	if se, err := api.Entry("abc"); err == nil {
+const (
+	resReject = "abc-reject"
+	resWarmUp = "abc-warmup"
+)
+
+func doCheck(res string) {
+	if se, err := sentinel.Entry(res); err == nil {
 		se.Exit()
 	} else {
 		log.Fatalf("Block err: %s", err.Error())
 	}
 }
 
-func loadDirectRejectRule() {
-	rule := &flow.Rule{
-		Resource:               "abc",
+func init() {
+	benchmark.InitSentinel()
+	rule1 := &flow.Rule{
+		Resource:               resReject,
 		TokenCalculateStrategy: flow.Direct,
 		ControlBehavior:        flow.Reject,
 		Threshold:              math.MaxFloat64,
 		StatIntervalInMs:       1000,
 		RelationStrategy:       flow.CurrentResource,
 	}
-	flow.LoadRules([]*flow.Rule{rule})
-}
-
-func loadWarmUpRejectRule() {
-	rule := &flow.Rule{
-		Resource:               "abc",
+	rule2 := &flow.Rule{
+		Resource:               resWarmUp,
 		TokenCalculateStrategy: flow.WarmUp,
 		ControlBehavior:        flow.Reject,
 		Threshold:              math.MaxFloat64,
@@ -39,101 +42,96 @@ func loadWarmUpRejectRule() {
 		WarmUpColdFactor:       3,
 		StatIntervalInMs:       1000,
 	}
-	flow.LoadRules([]*flow.Rule{rule})
+	_, err := flow.LoadRules([]*flow.Rule{rule1, rule2})
+	if err != nil {
+		panic(err)
+	}
 }
 
 func Benchmark_DirectReject_SlotCheck_4(b *testing.B) {
-	loadDirectRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_DirectReject_SlotCheck_8(b *testing.B) {
-	loadDirectRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_DirectReject_SlotCheck_16(b *testing.B) {
-	loadDirectRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_DirectReject_SlotCheck_32(b *testing.B) {
-	loadDirectRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(32)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_WarmUpReject_SlotCheck_4(b *testing.B) {
-	loadWarmUpRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_WarmUpReject_SlotCheck_8(b *testing.B) {
-	loadWarmUpRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resWarmUp)
 		}
 	})
 }
 
 func Benchmark_WarmUpReject_SlotCheck_16(b *testing.B) {
-	loadWarmUpRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resWarmUp)
 		}
 	})
 }
 
 func Benchmark_WarmUpReject_SlotCheck_32(b *testing.B) {
-	loadWarmUpRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(32)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resWarmUp)
 		}
 	})
 }
diff --git a/tests/benchmark/hotspot/hotspot_benchmark_test.go b/tests/benchmark/hotspot/hotspot_benchmark_test.go
index 04744c0..f994f86 100644
--- a/tests/benchmark/hotspot/hotspot_benchmark_test.go
+++ b/tests/benchmark/hotspot/hotspot_benchmark_test.go
@@ -5,172 +5,154 @@ import (
 	"math"
 	"testing"
 
-	"github.com/alibaba/sentinel-golang/api"
+	sentinel "github.com/alibaba/sentinel-golang/api"
 	"github.com/alibaba/sentinel-golang/core/hotspot"
+	"github.com/alibaba/sentinel-golang/tests/benchmark"
 )
 
-func doCheck() {
-	if se, err := api.Entry("abc"); err == nil {
-		se.Exit()
-	} else {
-		log.Fatalf("Block err: %s", err.Error())
-	}
-}
+const (
+	resReject      = "resReject"
+	resConcurrency = "resConcurrency"
+	resThrottling  = "resThrottling"
+)
 
-func initConcurrencyRule() {
-	_, err := hotspot.LoadRules([]*hotspot.Rule{
-		{
-			Resource:      "abc",
-			MetricType:    hotspot.Concurrency,
-			ParamIndex:    0,
-			Threshold:     math.MaxInt64,
-			DurationInSec: 0,
-		},
-	})
-	if err != nil {
-		log.Fatalf("Unexpected error: %+v", err)
+func init() {
+	benchmark.InitSentinel()
+	rule1 := &hotspot.Rule{
+		Resource:      resConcurrency,
+		MetricType:    hotspot.Concurrency,
+		ParamIndex:    0,
+		Threshold:     math.MaxInt64,
+		DurationInSec: 0,
 	}
-}
-
-func initQPSRejectRule() {
-	_, err := hotspot.LoadRules([]*hotspot.Rule{
-		{
-			Resource:        "abc",
-			MetricType:      hotspot.QPS,
-			ControlBehavior: hotspot.Reject,
-			ParamIndex:      0,
-			Threshold:       math.MaxInt64,
-			BurstCount:      0,
-			DurationInSec:   1,
-		},
-	})
+	rule2 := &hotspot.Rule{
+		Resource:        resReject,
+		MetricType:      hotspot.QPS,
+		ControlBehavior: hotspot.Reject,
+		ParamIndex:      0,
+		Threshold:       math.MaxInt64,
+		BurstCount:      0,
+		DurationInSec:   1,
+	}
+	rule3 := &hotspot.Rule{
+		Resource:          resThrottling,
+		MetricType:        hotspot.QPS,
+		ControlBehavior:   hotspot.Throttling,
+		ParamIndex:        0,
+		Threshold:         math.MaxInt64,
+		BurstCount:        0,
+		DurationInSec:     1,
+		MaxQueueingTimeMs: 0,
+	}
+	_, err := hotspot.LoadRules([]*hotspot.Rule{rule1, rule2, rule3})
 	if err != nil {
-		log.Fatalf("Unexpected error: %+v", err)
+		panic(err)
 	}
 }
 
-func initQPSThrottlingRule() {
-	_, err := hotspot.LoadRules([]*hotspot.Rule{
-		{
-			Resource:          "abc",
-			MetricType:        hotspot.QPS,
-			ControlBehavior:   hotspot.Throttling,
-			ParamIndex:        0,
-			Threshold:         math.MaxInt64,
-			BurstCount:        0,
-			DurationInSec:     1,
-			MaxQueueingTimeMs: 0,
-		},
-	})
-	if err != nil {
-		log.Fatalf("Unexpected error: %+v", err)
+func doCheck(res string) {
+	if se, err := sentinel.Entry(res); err == nil {
+		se.Exit()
+	} else {
+		log.Fatalf("Block err: %s", err.Error())
 	}
 }
 
 func Benchmark_Concurrency_Concurrency4(b *testing.B) {
-	initConcurrencyRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resConcurrency)
 		}
 	})
 }
 
 func Benchmark_Concurrency_Concurrency8(b *testing.B) {
-	initConcurrencyRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resConcurrency)
 		}
 	})
 }
 
 func Benchmark_Concurrency_Concurrency16(b *testing.B) {
-	initConcurrencyRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resConcurrency)
 		}
 	})
 }
 
 func Benchmark_QPS_Reject_Concurrency4(b *testing.B) {
-	initQPSRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resConcurrency)
 		}
 	})
 }
 
 func Benchmark_QPS_Reject_Concurrency8(b *testing.B) {
-	initQPSRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_QPS_Reject_Concurrency16(b *testing.B) {
-	initQPSRejectRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resReject)
 		}
 	})
 }
 
 func Benchmark_QPS_Throttling_Concurrency4(b *testing.B) {
-	initQPSThrottlingRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(4)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resThrottling)
 		}
 	})
 }
 
 func Benchmark_QPS_Throttling_Concurrency8(b *testing.B) {
-	initQPSThrottlingRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(8)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resThrottling)
 		}
 	})
 }
 
 func Benchmark_QPS_Throttling_Concurrency16(b *testing.B) {
-	initQPSThrottlingRule()
 	b.ReportAllocs()
 	b.ResetTimer()
 	b.SetParallelism(16)
 	b.RunParallel(func(pb *testing.PB) {
 		for pb.Next() {
-			doCheck()
+			doCheck(resThrottling)
 		}
 	})
 }
diff --git a/tests/benchmark/isolation/isolation_slot_benchmark_test.go b/tests/benchmark/isolation/isolation_slot_benchmark_test.go
index 7adc1db..4f176c8 100644
--- a/tests/benchmark/isolation/isolation_slot_benchmark_test.go
+++ b/tests/benchmark/isolation/isolation_slot_benchmark_test.go
@@ -5,23 +5,25 @@ import (
 	"math"
 	"testing"
 
-	"github.com/alibaba/sentinel-golang/api"
+	sentinel "github.com/alibaba/sentinel-golang/api"
 	"github.com/alibaba/sentinel-golang/core/isolation"
+	"github.com/alibaba/sentinel-golang/tests/benchmark"
 )
 
 func init() {
+	benchmark.InitSentinel()
 	rule := &isolation.Rule{
 		Resource:   "abc",
 		MetricType: isolation.Concurrency,
 		Threshold:  math.MaxInt32,
 	}
 	if _, err := isolation.LoadRules([]*isolation.Rule{rule}); err != nil {
-		log.Fatalf("Load rule err: %s", err.Error())
+		panic(err)
 	}
 }
 
 func doCheck() {
-	if se, err := api.Entry("abc"); err == nil {
+	if se, err := sentinel.Entry("abc"); err == nil {
 		se.Exit()
 	} else {
 		log.Fatalf("Block err: %s", err.Error())