Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(lang/syncx): add benchmark for RWMutex #89

Merged
merged 1 commit into from
Nov 1, 2021

Conversation

SilverRainZ
Copy link
Member

@SilverRainZ SilverRainZ commented Sep 29, 2021

This PR adds benchmark for lang/syncx.RMMutex.

go test -v -cpuprofile cpu.pprof -cpu=1,4,8 -run=NOTEST -bench=BenchmarkRWMutex -benchtime=100000x -count=10 -timeout=60m > x.txt && benchstat x.txt
Result
name                              time/op
RWMutex100Read/syncx-1            17.7ns ± 8%
RWMutex100Read/syncx-1-4          16.3ns ± 0%
RWMutex100Read/syncx-1-8          16.3ns ± 0%
RWMutex100Read/sync-1             15.6ns ± 0%
RWMutex100Read/sync-1-4           15.6ns ± 1%
RWMutex100Read/sync-1-8           15.6ns ± 1%
RWMutex100Read/syncx-4            16.3ns ± 0%
RWMutex100Read/syncx-4-4          4.29ns ±10%
RWMutex100Read/syncx-4-8          4.26ns ± 1%
RWMutex100Read/sync-4             15.6ns ± 0%
RWMutex100Read/sync-4-4           31.1ns ± 2%
RWMutex100Read/sync-4-8           32.4ns ± 8%
RWMutex100Read/syncx-16           16.5ns ± 2%
RWMutex100Read/syncx-16-4         7.59ns ±91%
RWMutex100Read/syncx-16-8         6.48ns ±34%
RWMutex100Read/sync-16            15.6ns ± 0%
RWMutex100Read/sync-16-4          31.6ns ± 8%
RWMutex100Read/sync-16-8          31.1ns ± 7%
RWMutex100Read/syncx-64           16.6ns ± 1%
RWMutex100Read/syncx-64-4         12.6ns ±72%
RWMutex100Read/syncx-64-8         21.2ns ±20%
RWMutex100Read/sync-64            15.7ns ± 0%
RWMutex100Read/sync-64-4          30.4ns ±12%
RWMutex100Read/sync-64-8          31.0ns ± 7%
RWMutex100Read/syncx-256          17.1ns ± 2%
RWMutex100Read/syncx-256-4        19.0ns ±62%
RWMutex100Read/syncx-256-8        20.4ns ±23%
RWMutex100Read/sync-256           16.1ns ± 1%
RWMutex100Read/sync-256-4         29.9ns ±13%
RWMutex100Read/sync-256-8         32.3ns ±12%
RWMutex1Write99Read/syncx-1       18.8ns ± 1%
RWMutex1Write99Read/syncx-1-4     18.9ns ± 1%
RWMutex1Write99Read/syncx-1-8     18.8ns ± 0%
RWMutex1Write99Read/sync-1        15.7ns ± 1%
RWMutex1Write99Read/sync-1-4      15.9ns ± 3%
RWMutex1Write99Read/sync-1-8      15.8ns ± 1%
RWMutex1Write99Read/syncx-4       18.8ns ± 1%
RWMutex1Write99Read/syncx-4-4     29.9ns ±22%
RWMutex1Write99Read/syncx-4-8     33.0ns ±20%
RWMutex1Write99Read/sync-4        17.5ns ±11%
RWMutex1Write99Read/sync-4-4      35.1ns ± 3%
RWMutex1Write99Read/sync-4-8      35.6ns ± 3%
RWMutex1Write99Read/syncx-16      18.8ns ± 1%
RWMutex1Write99Read/syncx-16-4    39.6ns ±29%
RWMutex1Write99Read/syncx-16-8    39.3ns ±27%
RWMutex1Write99Read/sync-16       15.8ns ± 2%
RWMutex1Write99Read/sync-16-4     50.5ns ± 6%
RWMutex1Write99Read/sync-16-8     54.5ns ± 6%
RWMutex1Write99Read/syncx-64      19.0ns ± 1%
RWMutex1Write99Read/syncx-64-4    44.3ns ±12%
RWMutex1Write99Read/syncx-64-8    44.1ns ±15%
RWMutex1Write99Read/sync-64       15.8ns ± 1%
RWMutex1Write99Read/sync-64-4     62.3ns ± 6%
RWMutex1Write99Read/sync-64-8     65.2ns ± 7%
RWMutex1Write99Read/syncx-256     19.2ns ± 3%
RWMutex1Write99Read/syncx-256-4   40.1ns ±62%
RWMutex1Write99Read/syncx-256-8   36.7ns ±26%
RWMutex1Write99Read/sync-256      16.2ns ± 1%
RWMutex1Write99Read/sync-256-4    76.0ns ± 7%
RWMutex1Write99Read/sync-256-8    70.0ns ± 4%
RWMutex10Write90Read/syncx-1      41.3ns ± 1%
RWMutex10Write90Read/syncx-1-4    42.0ns ± 9%
RWMutex10Write90Read/syncx-1-8    40.8ns ± 2%
RWMutex10Write90Read/sync-1       16.3ns ± 2%
RWMutex10Write90Read/sync-1-4     16.6ns ± 1%
RWMutex10Write90Read/sync-1-8     16.6ns ± 1%
RWMutex10Write90Read/syncx-4      42.0ns ± 2%
RWMutex10Write90Read/syncx-4-4    77.3ns ±12%
RWMutex10Write90Read/syncx-4-8    76.1ns ±10%
RWMutex10Write90Read/sync-4       16.6ns ± 0%
RWMutex10Write90Read/sync-4-4     34.9ns ± 9%
RWMutex10Write90Read/sync-4-8     34.6ns ± 6%
RWMutex10Write90Read/syncx-16     41.8ns ± 8%
RWMutex10Write90Read/syncx-16-4   78.0ns ± 3%
RWMutex10Write90Read/syncx-16-8   78.9ns ± 7%
RWMutex10Write90Read/sync-16      16.7ns ±11%
RWMutex10Write90Read/sync-16-4    34.7ns ± 8%
RWMutex10Write90Read/sync-16-8    44.7ns ± 6%
RWMutex10Write90Read/syncx-64     53.9ns ±28%
RWMutex10Write90Read/syncx-64-4   94.8ns ±20%
RWMutex10Write90Read/syncx-64-8   79.4ns ± 6%
RWMutex10Write90Read/sync-64      16.9ns ± 3%
RWMutex10Write90Read/sync-64-4    34.1ns ± 3%
RWMutex10Write90Read/sync-64-8    37.6ns ±14%
RWMutex10Write90Read/syncx-256    43.5ns ± 4%
RWMutex10Write90Read/syncx-256-4  80.4ns ±13%
RWMutex10Write90Read/syncx-256-8  76.7ns ±12%
RWMutex10Write90Read/sync-256     17.1ns ± 4%
RWMutex10Write90Read/sync-256-4   22.2ns ± 7%
RWMutex10Write90Read/sync-256-8   21.9ns ± 9%
RWMutex50Write50Read/syncx-1       145ns ± 3%
RWMutex50Write50Read/syncx-1-4     144ns ± 2%
RWMutex50Write50Read/syncx-1-8     167ns ±15%
RWMutex50Write50Read/sync-1       20.6ns ± 1%
RWMutex50Write50Read/sync-1-4     20.6ns ± 1%
RWMutex50Write50Read/sync-1-8     20.6ns ± 0%
RWMutex50Write50Read/syncx-4       159ns ±18%
RWMutex50Write50Read/syncx-4-4     182ns ± 2%
RWMutex50Write50Read/syncx-4-8     187ns ± 3%
RWMutex50Write50Read/sync-4       21.4ns ±10%
RWMutex50Write50Read/sync-4-4     38.5ns ± 5%
RWMutex50Write50Read/sync-4-8     38.8ns ± 5%
RWMutex50Write50Read/syncx-16      144ns ± 3%
RWMutex50Write50Read/syncx-16-4    183ns ± 1%
RWMutex50Write50Read/syncx-16-8    186ns ± 1%
RWMutex50Write50Read/sync-16      20.9ns ±10%
RWMutex50Write50Read/sync-16-4    40.5ns ± 4%
RWMutex50Write50Read/sync-16-8    40.9ns ± 2%
RWMutex50Write50Read/syncx-64      144ns ± 2%
RWMutex50Write50Read/syncx-64-4    184ns ± 2%
RWMutex50Write50Read/syncx-64-8    186ns ± 2%
RWMutex50Write50Read/sync-64      20.7ns ± 6%
RWMutex50Write50Read/sync-64-4    40.2ns ± 3%
RWMutex50Write50Read/sync-64-8    40.3ns ± 3%
RWMutex50Write50Read/syncx-256     134ns ± 3%
RWMutex50Write50Read/syncx-256-4   211ns ± 6%
RWMutex50Write50Read/syncx-256-8   201ns ± 4%
RWMutex50Write50Read/sync-256     22.1ns ±28%
RWMutex50Write50Read/sync-256-4   36.3ns ± 4%
RWMutex50Write50Read/sync-256-8   36.0ns ± 3%

Highlights

Hint: For benchmark "RWMutex100Read/syncx-256-8",

  • "syncx" means that we are benching syncx.RMutex
  • 256 is number of contestants (goroutine)
  • 8 is number of CPU (P)
  • syncx.RWMutex has all-round advantages over sync.RWMutex in read-only and 1write99read asituation:
  • The more CPUs, the more obvious the advantage of syncx.RWMutex
RWMutex100Read/syncx-1            17.7ns ± 8%
RWMutex100Read/syncx-1-4          16.3ns ± 0%
RWMutex100Read/syncx-1-8          16.3ns ± 0%
RWMutex100Read/sync-1             15.6ns ± 0%
RWMutex100Read/sync-1-4           15.6ns ± 1%
RWMutex100Read/sync-1-8           15.6ns ± 1%

RWMutex100Read/syncx-256          17.1ns ± 2%
RWMutex100Read/syncx-256-4        19.0ns ±62%
RWMutex100Read/syncx-256-8        20.4ns ±23%
RWMutex100Read/sync-256           16.1ns ± 1%
RWMutex100Read/sync-256-4         29.9ns ±13%
RWMutex100Read/sync-256-8         32.3ns ±12%

RWMutex1Write99Read/syncx-256     19.2ns ± 3%
RWMutex1Write99Read/syncx-256-4   40.1ns ±62%
RWMutex1Write99Read/syncx-256-8   36.7ns ±26%
RWMutex1Write99Read/sync-256      16.2ns ± 1%
RWMutex1Write99Read/sync-256-4    76.0ns ± 7%
RWMutex1Write99Read/sync-256-8    70.0ns ± 4%
  • syncx.RWMutex has no advantage over sync.RWMutex when there are more write operations than read.
RWMutex10Write90Read/syncx-256    43.5ns ± 4%
RWMutex10Write90Read/syncx-256-4  80.4ns ±13%
RWMutex10Write90Read/syncx-256-8  76.7ns ±12%
RWMutex10Write90Read/sync-256     17.1ns ± 4%
RWMutex10Write90Read/sync-256-4   22.2ns ± 7%
RWMutex10Write90Read/sync-256-8   21.9ns ± 9%

RWMutex50Write50Read/syncx-256     134ns ± 3%
RWMutex50Write50Read/syncx-256-4   211ns ± 6%
RWMutex50Write50Read/syncx-256-8   201ns ± 4%
RWMutex50Write50Read/sync-256     22.1ns ±28%
RWMutex50Write50Read/sync-256-4   36.3ns ± 4%
RWMutex50Write50Read/sync-256-8   36.0ns ± 3%

@SilverRainZ SilverRainZ marked this pull request as ready for review September 30, 2021 03:14
zhangyunhao116
zhangyunhao116 previously approved these changes Oct 9, 2021
luchsh
luchsh previously approved these changes Oct 28, 2021
@SilverRainZ SilverRainZ merged commit fd6d3cb into develop Nov 1, 2021
@SilverRainZ SilverRainZ deleted the perf/bench-rwmutex branch November 1, 2021 10:07
zhangyunhao116 added a commit that referenced this pull request Jan 18, 2022
* release: 20210913 (#83) (#88)

* feat: circuitbreaker.panel use skipmap (#78)

* fix(metainfo): fix misuse of append (#79)

* fix(lscq): add write barrier for LSCQ Pointer (#80)

* feat(metainfo): improve backward APIs (#81)

* release: 20210913 (#83) (#93)

* feat: circuitbreaker.panel use skipmap (#78)

* fix(metainfo): fix misuse of append (#79)

* fix(lscq): add write barrier for LSCQ Pointer (#80)

* feat(metainfo): improve backward APIs (#81)

* chore(skipmap,skipset): remove duplicated code generation declaration (#87)

* fix(lscq): cas2 use runtime.noescape (#94)

* feat: add fastrand.Read() (#90)

Co-authored-by: liyichao <[email protected]>

* doc: add badge to link to godoc (#99)

* ci: skip golang related workflows when there are only doc changes (#101)

* ci: add workflow for feishu/lark notification (#100)

* ci: add workflow for feishu/lark notification

* ci: fix typo

* ci: also send feishu notification on issue opened

Co-authored-by: Jonathan Lu <[email protected]>

* feat(metainfo): define standard for backward prefix (#102)

* feat(fastrand): support Read,Shuffle,Perm (#103)

* feat(fastrand): Read remove temp buffer (#104)

* ci: add github workflow for performance regression check (#95)

* ci: add github workflow for performance regression check

Comment "/benchdiff" to trigger this check

* ci: add comments to pr-benchdiff.yml

* ci: report benchdiff result to PR_HEAD's check run

* ci: various changes

- support "pull_reqeust" event
- filter deleted go packages
- post a comment on job started
- post a comment on job failed

* ci: let xargs ignore empty line

* ci: skip benchdiff when there are only doc changes

* ci: set -x for debugging

* ci: make sure we are using github default branch as baseline

* ci: set benchtime=1s for benchdiff

* chore: add github issue forms (#105)

* test(lang/syncx): add benchmark for RWMutex (#89)

* fix(xxhash3): add fallback to fix panic occurs on non avx2, non sse2 machine (#108)

Co-authored-by: Ye Li <[email protected]>

* feat: add zset (#98)

* feat: add zset

* chore(zset): update comment

* docs(zset): add readme

* chore: some code style fixes

* chore(zset): rename Float64RangeOpt -> RangeOpt

* chore(zset): comment style fixes

* chore(zset): add a todo about maxLevel

* chore(zset): another comment fix

* chore(zset): move skiplist impl to another file

* chore(zset): add license header for opt.go

* chore: add myself as zset's CODEOWNER

* zset: don't use z.Range(0, z.Len()-1)

* doc: remove redundant section

* fix(zset): break when key is not exist

* chore(zset): simplify func name

* chore(zset): update cheatsheet

* chore(zset): meaningful const

* refactor(zset): optionalArray.init()

* docs: update zset readme

* docs(zset): also add @zhangyunhao116 as code owner

* docs(zset): some grammar fixes

* docs: fix docs typo (#109)

* feat: auto tuning gc (#112)

* feat: auto tuning gc

* doc: gctuner

* fix: gctuner tests data race (#113)

* fix: gctuner tests data race

* chore: add owner

* chore(ci): use self-hosted runner (#114)

* chore(ci): use self-hosted runner

* fix lint

Co-authored-by: Shengyu Zhang <[email protected]>
Co-authored-by: ziposcar <[email protected]>
Co-authored-by: liyichao <[email protected]>
Co-authored-by: Shengyu Zhang <[email protected]>
Co-authored-by: Jonathan Lu <[email protected]>
Co-authored-by: Pure White <[email protected]>
Co-authored-by: lyeeeeee <[email protected]>
Co-authored-by: Ye Li <[email protected]>
Co-authored-by: chyroc <[email protected]>
Co-authored-by: Joway <[email protected]>
Co-authored-by: Joway <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants