You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Get() method of domainMap reading more and write less , so using mutex for synchronization is a serious waste of resources, which can be optimized from the following two aspects
Use RWMutex to replace Mutex synchronization block: it can improve the performance of reading and avoid blocking between reading and reading
Narrow the range of locks: Before using Defer to synchronize a large block of statements, we can separate locks, synchronize when reading, and synchronize when writing to reduce blocking time
The core change is insession/tidb.go as below as first edtion
index 911e64f37..236759b15 100644
--- a/session/tidb.go+++ b/session/tidb.go@@ -44,13 +44,11 @@ import (
type domainMap struct {
domains map[string]*domain.Domain
- mu sync.Mutex+ mu sync.RWMutex
}
func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
- dm.mu.Lock()- defer dm.mu.Unlock()-+ dm.mu.RLock()
// If this is the only domain instance, and the caller doesn't provide store.
if len(dm.domains) == 1 && store == nil {
for _, r := range dm.domains {
@@ -60,6 +58,8 @@ func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
key := store.UUID()
d = dm.domains[key]
+ dm.mu.RUnlock()+
if d != nil {
return
}
@@ -92,8 +92,7 @@ func (dm *domainMap) Get(store kv.Storage) (d *domain.Domain, err error) {
if err != nil {
return nil, err
}
- dm.domains[key] = d-+ dm.Set(store, d)
return
}
@@ -103,6 +102,12 @@ func (dm *domainMap) Delete(store kv.Storage) {
dm.mu.Unlock()
}
+func (dm *domainMap) Set(store kv.Storage, domain *domain.Domain) {+ dm.mu.Lock()+ dm.domains[store.UUID()] = domain+ dm.mu.Unlock()+}+
var (
domap = &domainMap{
domains: map[string]*domain.Domain{},
(
The text was updated successfully, but these errors were encountered:
Enhancement
The Get() method of domainMap reading more and write less , so using mutex for synchronization is a serious waste of resources, which can be optimized from the following two aspects
The core change is insession/tidb.go as below as first edtion
The text was updated successfully, but these errors were encountered: