csimplestring/go-left-right

[Discussion] readerIndicator is not conclusively faster than RWMutex

Closed this issue · 1 comments

Hi,

I tried rewriting the project but used a linked left-right approach. also I thought the readerInicator looked a lot like an RWMutex, so I tried with that in stead.

I think the resulting code is a lot more readable: linked-left-right

But I also found that this solution performed quite a lot better in moderate load situations (break-even about 50 goroutines)

your master branch:

goos: linux
goarch: amd64
pkg: github.com/csimplestring/go-left-right
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
BenchmarkLRMap_Write-8                   9962917               111.4 ns/op
BenchmarkLockMap_Write-8                18546358                62.40 ns/op
BenchmarkLRMap_Read-8                    3806511               272.0 ns/op
BenchmarkLockMap_Read-8                  6499641               170.4 ns/op
BenchmarkLRMap_Read_Write_5_1-8             1575            812337 ns/op
BenchmarkLockMap_Read_Write_5_1-8           1669            675591 ns/op
BenchmarkLRMap_Read_Write_10_1-8            1281           1380485 ns/op
BenchmarkLockMap_Read_Write_10_1-8          1042           1107362 ns/op
BenchmarkLRMap_Read_Write_50_1-8             531           2365397 ns/op
BenchmarkLockMap_Read_Write_50_1-8           268           4396724 ns/op
BenchmarkLRMap_Read_Write_100_1-8            331           3951561 ns/op
BenchmarkLockMap_Read_Write_100_1-8          136           8815394 ns/op
BenchmarkLRMap_Read_Write_500_1-8             70          15398926 ns/op
BenchmarkLockMap_Read_Write_500_1-8          139           8690447 ns/op
PASS
ok      github.com/csimplestring/go-left-right  31.352s

my branch MikkelHJuul/linked-left-right:

goos: linux
goarch: amd64
pkg: github.com/csimplestring/go-left-right
cpu: Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
BenchmarkLRMap_Write-8                   9037975               124.6 ns/op
BenchmarkLockMap_Write-8                19078170                61.88 ns/op
BenchmarkLRMap_Read-8                    4329091               248.6 ns/op
BenchmarkLockMap_Read-8                  6337088               182.4 ns/op
BenchmarkLRMap_Read_Write_5_1-8             3476            359224 ns/op
BenchmarkLockMap_Read_Write_5_1-8           1406            801319 ns/op
BenchmarkLRMap_Read_Write_10_1-8            2132            548529 ns/op
BenchmarkLockMap_Read_Write_10_1-8          1041           1186699 ns/op
BenchmarkLRMap_Read_Write_50_1-8             526           2256797 ns/op
BenchmarkLockMap_Read_Write_50_1-8           290           4430084 ns/op
BenchmarkLRMap_Read_Write_100_1-8            254           4453970 ns/op
BenchmarkLockMap_Read_Write_100_1-8          148           8315832 ns/op
PASS
ok      github.com/csimplestring/go-left-right  29.527s

It's a fun data structure to work with :)

Thanks for sharing. I was sick last week so can not reply instantly. There are some variants on the reader-indicator from the original creator, which can help you
http://concurrencyfreaks.blogspot.com/2013/12/left-right-no-version-variant.html
http://concurrencyfreaks.blogspot.com/2013/12/left-right-state-machine.html

happy to know you enjoy this.