Skip to content

remove mutex lock in a goroutine lifecycle#16

Open
HyungrakJo wants to merge 4 commits intojtolio:masterfrom
HyungrakJo:remove_lock_in_a_go_lifecycle
Open

remove mutex lock in a goroutine lifecycle#16
HyungrakJo wants to merge 4 commits intojtolio:masterfrom
HyungrakJo:remove_lock_in_a_go_lifecycle

Conversation

@HyungrakJo
Copy link
Copy Markdown

@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