-
Notifications
You must be signed in to change notification settings - Fork 8k
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
Add mutex for protect Context.Keys map #1391
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1391 +/- ##
=======================================
Coverage 98.47% 98.47%
=======================================
Files 41 41
Lines 2293 2298 +5
=======================================
+ Hits 2258 2263 +5
Misses 20 20
Partials 15 15
Continue to review full report at Codecov.
|
Hi @AcoNCodes alike pull request have #702 and issue #700 |
@thinkerou this solution more lightweight, focused and without conflicts. The problem exists and forces me to use a fork that does not contain the latest updates. I'm looking forward to solve the problem. |
@night-codes thanks, I don't have any advice, the feature need @javierprovecho and @appleboy agree. |
any update for this pr? |
@AcoNCodes Please fix the conflicts. |
@AcoNCodes why not use |
@thinkerou Performance: var s sync.RWMutex
var w sync.WaitGroup
func main() {
mapTest()
syncMapTest()
}
func mapTest() {
m := map[int]int {1:1}
startTime := time.Now().Nanosecond()
w.Add(1)
go writeMap(m)
w.Add(1)
go writeMap(m)
w.Wait()
endTime := time.Now().Nanosecond()
timeDiff := endTime-startTime
fmt.Println("map:",timeDiff)
}
func writeMap (m map[int]int) {
defer w.Done()
i := 0
for i < 10000 {
s.Lock()
m[1]=1
s.Unlock()
i++
}
}
func readMap (m map[int]int) {
defer w.Done()
i := 0
for i < 10000 {
s.RLock()
_ = m[1]
s.RUnlock()
i++
}
}
func syncMapTest() {
m := sync.Map{}
m.Store(1,1)
startTime := time.Now().Nanosecond()
w.Add(1)
go writeSyncMap(m)
w.Add(1)
go writeSyncMap(m)
w.Wait()
endTime := time.Now().Nanosecond()
timeDiff := endTime-startTime
fmt.Println("sync.Map:",timeDiff)
}
func writeSyncMap (m sync.Map) {
defer w.Done()
i := 0
for i < 10000 {
m.Store(1,1)
i++
}
}
func readSyncMap (m sync.Map) {
defer w.Done()
i := 0
for i < 10000 {
m.Load(1)
i++
}
} |
* Add mutex for protect Context.Keys map * Fix tests Co-authored-by: Nikolay Tolkachov <nik.tolkachov@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
* Add mutex for protect Context.Keys map * Fix tests Co-authored-by: Nikolay Tolkachov <nik.tolkachov@gmail.com> Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@AcoNCodes The PR trigger the performance issue in #2350 |
add a switch to open/close the feature? @appleboy |
See #2351 I add new variable to enable/disable the mutex for protecting Context.Keys map (default as |
We get a panic in a loaded project related with use c.Get / c.Set in many middleware routines.