Skip to content

Introduce an interface RWLock to implement lock free in production mode#94

Merged
unrolled merged 2 commits intounrolled:v1from
lunny:lunny/lock_free
May 27, 2021
Merged

Introduce an interface RWLock to implement lock free in production mode#94
unrolled merged 2 commits intounrolled:v1from
lunny:lunny/lock_free

Conversation

@lunny
Copy link
Contributor

@lunny lunny commented May 13, 2021

Improvement after #90 #92

goos: darwin
goarch: amd64
pkg: github.com/unrolled/render
cpu: Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
(Before)BenchmarkHTML-8          1341072               892.2 ns/op
(After)   BenchmarkHTML-8          1374212               855.5 ns/op
PASS

@lunny lunny changed the title This PR introduce an interface RWLock to implement lock free in production mode Introduce an interface RWLock to implement lock free in production mode May 13, 2021
@zeripath
Copy link
Contributor

I think Rlocks are really very fast to take out especially if there isn't ever a write lock.

It would be good to benchmark this to prove that it does make a difference.

@zeripath
Copy link
Contributor

So running the benchmarks it looks like surprisingly this is slower. But I think it's all within the bounds of error.

master	BenchmarkBigHTMLBuffers-12    	  933356	      1240 ns/op	     376 B/op	      11 allocs/op
91	BenchmarkBigHTMLBuffers-12    	  912496	      1220 ns/op	     376 B/op	      11 allocs/op
92 	BenchmarkBigHTMLBuffers-12    	  879910	      1223 ns/op	     376 B/op	      11 allocs/op
93 	BenchmarkBigHTMLBuffers-12    	  946242	      1255 ns/op	     376 B/op	      11 allocs/op
94 	BenchmarkBigHTMLBuffers-12    	  915399	      1258 ns/op	     376 B/op	      11 allocs/op
master	BenchmarkSmallHTMLBuffers-12    	  862422	      1407 ns/op	     464 B/op	      14 allocs/op
91	BenchmarkSmallHTMLBuffers-12    	  866845	      1327 ns/op	     464 B/op	      14 allocs/op
92	BenchmarkSmallHTMLBuffers-12    	  864735	      1316 ns/op	     464 B/op	      14 allocs/op
93	BenchmarkSmallHTMLBuffers-12    	  835960	      1316 ns/op	     464 B/op	      14 allocs/op
94	BenchmarkSmallHTMLBuffers-12    	  838126	      1352 ns/op	     464 B/op	      14 allocs/op

@lunny
Copy link
Contributor Author

lunny commented May 14, 2021

When I test with 5s, another suprsing result.

go test -bench=BenchmarkHTML -cpu=12 -benchtime=5s
goos: darwin
goarch: amd64
pkg: github.com/unrolled/render
cpu: Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
(Before) BenchmarkHTML-12         7135489               817.8 ns/op
(After)   BenchmarkHTML-12         7400484               776.3 ns/op
PASS
ok      github.com/unrolled/render      6.716s

@zeripath
Copy link
Contributor

I get:

master  BenchmarkHTML-12    	 9416479	       654.9 ns/op
#91	BenchmarkHTML-12    	 9254259	       676.1 ns/op
#92	BenchmarkHTML-12    	 9732022	       645.7 ns/op
#93	BenchmarkHTML-12    	 9386546	       651.7 ns/op
#94	BenchmarkHTML-12    	 9203570	       656.3 ns/op

The small differences are probably because the templates contains a lock itself - which we can't really escape from.

@unrolled
Copy link
Owner

Can you merge master into this PR?

@lunny
Copy link
Contributor Author

lunny commented May 27, 2021

Can you merge master into this PR?

Did you mean branch v1?

@unrolled
Copy link
Owner

Thanks for the PR!

@unrolled unrolled merged commit fb5b5ba into unrolled:v1 May 27, 2021
@lunny lunny deleted the lunny/lock_free branch May 27, 2021 15:47
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