You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2021/06/25 02:21:21 UTC

[GitHub] [servicecomb-service-center] DFSOrange commented on a change in pull request #1070: cache use concurrentmap

DFSOrange commented on a change in pull request #1070:
URL: https://github.com/apache/servicecomb-service-center/pull/1070#discussion_r658425986



##########
File path: datasource/mongo/sd/dep_cache.go
##########
@@ -23,25 +23,31 @@ import (
 
 	"github.com/apache/servicecomb-service-center/datasource/mongo/client/model"
 	"github.com/apache/servicecomb-service-center/datasource/sdcommon"
+	cmap "github.com/orcaman/concurrent-map"
 	"go.mongodb.org/mongo-driver/bson"
 )
 
 type depStore struct {
-	dirty      bool
-	d          *DocStore
-	indexCache *IndexCache
+	dirty bool
+	// the key is documentID, is value is mongo document.
+	concurrentMap cmap.ConcurrentMap

Review comment:
       > 为何不用sync.Map
   
   主要有两个原因:
   1. [官方文档](https://golang.org/pkg/sync/#Map)介绍sync.map主要适用于两个场景1.key写入一次而读多次2.多个goroutine读写不相交的键值对,在实例服务变化频繁场景下不满足以上两个约束
   2. concurrentmap使用分片hash,sync.mapz是两层map(read+dirty),理论性能前者更好




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org