Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mogo
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
mogo
Commits
9f8996ad
Commit
9f8996ad
authored
Jun 28, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update benchmark test
parent
99e11018
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
16 deletions
+63
-16
workerinfo_test.go
operator/workerinfo_test.go
+63
-16
No files found.
operator/workerinfo_test.go
View file @
9f8996ad
...
...
@@ -19,10 +19,11 @@ import (
)
var
(
maxModelId
=
1000
idlist
=
make
([]
string
,
0
,
1000000
)
database
=
"test"
once
=
sync
.
Once
{}
maxModelId
=
1000
idlist
=
make
([]
string
,
0
,
1000000
)
workeridList
=
make
([]
string
,
0
,
1000000
)
database
=
"test"
once
=
sync
.
Once
{}
)
func
ConnectMongoDB
()
(
*
mongo
.
Client
,
error
)
{
...
...
@@ -41,15 +42,20 @@ func ConnectMongoDB() (*mongo.Client, error) {
return
client
,
nil
}
func
initdata
(
client
*
mongo
.
Client
,
count
int
,
running
bool
,
installed
bool
)
[]
string
{
func
initdata
(
client
*
mongo
.
Client
,
count
int
,
running
bool
,
installed
bool
,
workerid
bool
)
[]
string
{
t1
:=
time
.
Now
()
db
:=
NewDBWorker
(
client
,
database
)
dbRunning
:=
NewDBWorkerRunning
(
client
,
database
)
dbInstalled
:=
NewDBWorkerInstalled
(
client
,
database
)
ids
:=
make
([]
string
,
0
,
count
)
// Insert 1,000,000 DbWorkerInfo to operator
for
i
:=
0
;
i
<
count
;
i
++
{
worker
:=
generateAWorker
()
if
workerid
{
ids
=
append
(
ids
,
worker
.
WorkerId
)
}
result
,
err
:=
db
.
InsertWorker
(
context
.
Background
(),
worker
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"insert worker failed with err:%s"
,
err
))
...
...
@@ -88,16 +94,18 @@ func initdata(client *mongo.Client, count int, running bool, installed bool) []s
}
}
id
,
ok
:=
result
.
InsertedID
.
(
primitive
.
ObjectID
)
if
!
ok
{
panic
(
"inserted id is not primitive.ObjectID"
)
if
!
workerid
{
id
,
ok
:=
result
.
InsertedID
.
(
primitive
.
ObjectID
)
if
!
ok
{
panic
(
"inserted id is not primitive.ObjectID"
)
}
ids
=
append
(
ids
,
id
.
Hex
())
}
idlist
=
append
(
idlist
,
id
.
Hex
())
//fmt.Printf("insert worker %s: %v\n", id.Hex(), worker)
}
t2
:=
time
.
Now
()
fmt
.
Printf
(
"init data cost %s
\n
"
,
t2
.
Sub
(
t1
)
.
String
())
return
id
list
return
id
s
}
func
getRandId
(
max
int
)
string
{
...
...
@@ -568,7 +576,7 @@ func BenchmarkDbWorker_UpdateHardware(b *testing.B) {
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
10000
,
false
,
false
)
idlist
=
initdata
(
client
,
10000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
...
...
@@ -599,7 +607,7 @@ func BenchmarkDbWorker_UpdateHardware_Parallel(b *testing.B) {
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
10000
,
false
,
false
)
idlist
=
initdata
(
client
,
10000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
...
...
@@ -618,6 +626,45 @@ func BenchmarkDbWorker_UpdateHardware_Parallel(b *testing.B) {
})
}
func
BenchmarkDbWorker_UpdateGPUUsage_Parallel
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
()
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
b
.
StopTimer
()
db
:=
NewDBWorker
(
client
,
database
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
once
.
Do
(
func
()
{
db
.
Clear
()
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
10000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
b
.
ResetTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
b
.
StopTimer
()
idx
:=
rand
.
Intn
(
len
(
idlist
))
usage
:=
rand
.
Intn
(
10
)
+
50
memfree
:=
int64
(
rand
.
Intn
(
10
)
+
10
)
pwoer
:=
rand
.
Intn
(
10
)
+
20
temp
:=
rand
.
Intn
(
10
)
+
30
gpuusages
:=
[]
types
.
GpuUsage
{
{
0
,
usage
,
memfree
,
pwoer
,
temp
},
{
1
,
usage
+
1
,
memfree
+
1
,
pwoer
+
1
,
temp
+
1
},
{
2
,
usage
+
2
,
memfree
+
2
,
pwoer
+
2
,
temp
+
2
},
}
b
.
StartTimer
()
if
err
:=
db
.
UpdateGPUUsage
(
context
.
Background
(),
idlist
[
idx
],
gpuusages
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"update gpu usage failed with err:%s"
,
err
))
}
}
})
}
func
BenchmarkDbWorker_FindWorkerByInstallModelAndSortByGpuRam
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
()
if
err
!=
nil
{
...
...
@@ -632,7 +679,7 @@ func BenchmarkDbWorker_FindWorkerByInstallModelAndSortByGpuRam(b *testing.B) {
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
10000
,
false
,
false
)
idlist
=
initdata
(
client
,
10000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
b
.
ResetTimer
()
...
...
@@ -664,7 +711,7 @@ func BenchmarkDbWorker_FindWorkerByInstallModelAndSortByGpuRam_Parallel(b *testi
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
10000
,
false
,
false
)
idlist
=
initdata
(
client
,
10000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
b
.
ResetTimer
()
...
...
@@ -700,7 +747,7 @@ func BenchmarkDbWorker_FindWorkerByRunningModelAndSortByWaitTime(b *testing.B) {
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
1000
,
false
,
false
)
idlist
=
initdata
(
client
,
1000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
b
.
ResetTimer
()
...
...
@@ -730,7 +777,7 @@ func BenchmarkDbWorker_FindWorkerByRunningModelAndSortByWaitTime_Parallel(b *tes
if
err
:=
db
.
CreateIndex
(
context
.
Background
());
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"create index failed with err:%s"
,
err
))
}
idlist
=
initdata
(
client
,
1000
,
false
,
false
)
idlist
=
initdata
(
client
,
1000
,
false
,
false
,
true
)
})
b
.
StartTimer
()
b
.
ResetTimer
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment