Commit 69d23d31 authored by luxq's avatar luxq

add parallel test

parent 750e4516
Pipeline #746 canceled with stages
......@@ -138,3 +138,41 @@ func BenchmarkDbWorkerInfo_UpdateResource(b *testing.B) {
}
//fmt.Println("update failed:", ufailed)
}
func BenchmarkDbWorkerInfo_UpdateResource_Parallel(b *testing.B) {
client, err := ConnectMongoDB("mongodb://localhost:27017")
if err != nil {
log.Fatal(err)
}
nresource := &types.ModelInfo{
InstalledModels: []*types.InstalledModelInfo{
&types.InstalledModelInfo{
ModelId: getRandId(100),
DiskSize: 101,
},
&types.InstalledModelInfo{
ModelId: getRandId(100),
DiskSize: 44,
},
},
RunningModels: []*types.RunningModelInfo{
&types.RunningModelInfo{
ModelId: getRandId(100),
StartedTime: uint64((time.Now().Add(-time.Hour)).Unix()),
LatestTime: uint64(time.Now().Add(-time.Minute * 20).Unix()),
RunCount: 101,
GpuRamUsed: 80,
},
},
}
db := NewDBWorker(client, "test", "workers")
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
idx := rand.Intn(len(idlist))
if err := db.UpdateModel(context.Background(), idlist[idx].(string), nresource); err != nil {
panic(fmt.Sprintf("update worker failed with err:%s", err))
}
}
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment