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

remove mutex lock in a goroutine lifecycle #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

HyungrakJo
Copy link

@HyungrakJo HyungrakJo commented Aug 11, 2022

There is a performance loss due to mutex locks in situations where goroutines are frequently created/exited.

  1. I used lock free pool as goroutine id pool.
  2. In order to get the "Values" corresponding to the goroutine id, I made it possible to access without contention by using a pre-assigned array instead of map. It is assumed that the array can grow variably and holds write locks only when it needs to be grown.

It was confirmed that there is a significant performance difference by modifying the benchmark test case.

  • before
BenchmarkGetValue-10    	    2514	    551195 ns/op
BenchmarkSetValues-10    	    6830	    166487 ns/op
  • after
BenchmarkGetValue-10    	    4240	    505839 ns/op
BenchmarkSetValues-10    	   15340	     76396 ns/op

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.

1 participant