From 1c8c14cb32884c1a0885e669509e2152f1d3e5e8 Mon Sep 17 00:00:00 2001 From: 554325746@qq.com <554325746@qq.com> Date: 星期一, 08 七月 2019 09:48:02 +0800 Subject: [PATCH] struct to map[string]float32] --- dbpersoninfo.go | 66 ++++++++++++++++++++------------- 1 files changed, 40 insertions(+), 26 deletions(-) diff --git a/dbpersoninfo.go b/dbpersoninfo.go index b42ab0d..7846cd9 100644 --- a/dbpersoninfo.go +++ b/dbpersoninfo.go @@ -7,9 +7,11 @@ "sync" "encoding/base64" - "basic.com/pubsub/cache.git/esutil" - "basic.com/pubsub/cache.git/shardmap" - "basic.com/pubsub/protomsg.git" + "test/cache/esutil" + "test/cache/shardmap" +// "basic.com/pubsub/cache.git/esutil" +// "basic.com/pubsub/cache.git/shardmap" +// "basic.com/pubsub/protomsg.git" "basic.com/valib/gosdk.git" ) @@ -17,34 +19,50 @@ var querynum = flag.Int("querynum", 10, "the query number from database") var threadnum = flag.Int("threadnum",32, "the number of thread to deal data.") -var Cmap *shardmap.ShardMap +type CmapItem struct { + sync.Mutex + cam map[string]*shardmap.ShardMap +} + +var Cmap *CmapItem + func Init(){ flag.Parse() gosdk.InitFaceExtractor(16, 0) - Cmap = shardmap.New(uint8(*threadnum)) + Cmap = &CmapItem{ + cam: make(map[string]*shardmap.ShardMap), + } temptime := time.Now() var wg sync.WaitGroup + for i:=0; i<*threadnum; i++ { j := i*(*querynum) wg.Add(1) go func(qs int){ defer wg.Done() - - escache, err := esutil.DbPersoninfos(qs, *querynum) + escache, err := esutil.DbPersoninfos(qs, *querynum) if err != nil { fmt.Println(err) return } - for _, value := range escache { - Cmap.Set(value.FaceFeature,value) + Cmap.Lock() + + for _, value := range escache{ + if _, ok :=Cmap.cam[value.Tableid]; !ok { + Cmap.cam[value.Tableid]=shardmap.New(uint8(*threadnum)) + } + + Cmap.cam[value.Tableid].Set(value.Id,value.FaceFeature) } + + Cmap.Unlock() + }(j) } wg.Wait() - fmt.Println("get number of es: ", Cmap.GetLen()) fmt.Println("time of get data from es.", time.Since(temptime)) fmt.Println() } @@ -54,34 +72,30 @@ // Getdbpersonmsg("") //} -func Getdbpersonmsg(teststring string, IsCompare bool) ([]byte) { +func Getdbpersonmsg(tableid, teststring string, IsCompare bool) ([]byte) { - var binfos protomsg.Binfos - + var buf []byte if !IsCompare { return nil } if teststring == "" { - testcache, _:= esutil.DbPersoninfos(0,1) - teststring = testcache[0].FaceFeature + return nil } + for id, value := range Cmap.cam{ + if id == tableid{ + fmt.Println(id) + buf =value.Walk(Printest, teststring) + } + } + fmt.Println() - fmt.Println("======鍗庝附鐨勫垎鍓茬嚎============") fmt.Println() firsttime := time.Now() - Rscore := Cmap.Walk(Printest, teststring) - - binfos.Infos = append(binfos.Infos, Rscore...) - binfosbytes, err := binfos.Marshal() - if err != nil { - fmt.Println(err) - return nil - } fmt.Println(time.Since(firsttime)) - return binfosbytes + return buf } func Printest(ci, co string ) (float32){ @@ -92,7 +106,7 @@ // return -1 //} - co_d, err := base64.StdEncoding.DecodeString(co) + co_d, err := base64.StdEncoding.DecodeString(co) if err != nil { fmt.Println("co_d : error : ", err) return -1 -- Gitblit v1.8.0