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
dae37c71
Commit
dae37c71
authored
May 30, 2024
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update test
parent
dea45e42
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
99 additions
and
1 deletion
+99
-1
workerInstalledInfo.go
operator/workerInstalledInfo.go
+22
-1
workerInstalledInfo_test.go
operator/workerInstalledInfo_test.go
+77
-0
No files found.
operator/workerInstalledInfo.go
View file @
dae37c71
...
...
@@ -46,7 +46,7 @@ func (d *WorkerInstalledOperator) FindWorkerByModelId(ctx context.Context, model
// sort by wait time
findOptions
:=
options
.
Find
()
findOptions
.
SetLimit
(
int64
(
limit
))
findOptions
.
SetSort
(
bson
.
D
{{
"
exec_tim
e"
,
1
}})
findOptions
.
SetSort
(
bson
.
D
{{
"
gpu_fre
e"
,
1
}})
selector
:=
bson
.
M
{
"model_id"
:
modelId
}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
...
...
@@ -61,3 +61,24 @@ func (d *WorkerInstalledOperator) FindWorkerByModelId(ctx context.Context, model
}
return
workers
,
nil
}
func
(
d
*
WorkerInstalledOperator
)
FindWorkerByModelIdAndGpuMem
(
ctx
context
.
Context
,
modelId
int
,
mem
int64
,
limit
int
)
([]
*
WorkerInstalledInfo
,
error
)
{
// find all worker that at least one installed model's mode_id is equal modelId
// sort by gpu_free
findOptions
:=
options
.
Find
()
findOptions
.
SetLimit
(
int64
(
limit
))
findOptions
.
SetSort
(
bson
.
D
{{
"gpu_free"
,
1
}})
selector
:=
bson
.
M
{
"model_id"
:
modelId
,
"gpu_free"
:
bson
.
M
{
"$gte"
:
mem
}}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
if
err
!=
nil
{
return
nil
,
err
}
defer
cursor
.
Close
(
ctx
)
var
workers
[]
*
WorkerInstalledInfo
if
err
=
cursor
.
All
(
ctx
,
&
workers
);
err
!=
nil
{
return
nil
,
err
}
return
workers
,
nil
}
operator/workerInstalledInfo_test.go
View file @
dae37c71
...
...
@@ -105,6 +105,83 @@ func BenchmarkWorkerInstalledOperator_UpdateGpuFree_Parallel(b *testing.B) {
})
}
func
BenchmarkWorkerInstalledOperator_FindWorkerByModelId
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
,
"admin"
,
"admin"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorkerInstalled
(
client
,
database
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
id
:=
rand
.
Intn
(
maxModelId
)
_
,
err
:=
db
.
FindWorkerByModelId
(
context
.
Background
(),
id
,
10
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
}
}
func
BenchmarkWorkerInstalledOperator_FindWorkerByModelId_Parallel
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
,
"admin"
,
"admin"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorkerInstalled
(
client
,
database
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
id
:=
rand
.
Intn
(
maxModelId
)
_
,
err
:=
db
.
FindWorkerByModelId
(
context
.
Background
(),
id
,
10
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
}
})
}
func
BenchmarkWorkerInstalledOperator_FindWorkerByModelIdAndGpuMem
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
,
"admin"
,
"admin"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorkerInstalled
(
client
,
database
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
id
:=
rand
.
Intn
(
maxModelId
)
mem
:=
rand
.
Intn
(
100
)
+
12000
_
,
err
:=
db
.
FindWorkerByModelIdAndGpuMem
(
context
.
Background
(),
id
,
int64
(
mem
),
10
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
}
}
func
BenchmarkWorkerInstalledOperator_FindWorkerByModelIdAndGpuMem_Parallel
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
,
"admin"
,
"admin"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorkerInstalled
(
client
,
database
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
id
:=
rand
.
Intn
(
maxModelId
)
mem
:=
rand
.
Intn
(
100
)
+
12000
_
,
err
:=
db
.
FindWorkerByModelIdAndGpuMem
(
context
.
Background
(),
id
,
int64
(
mem
),
10
)
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
}
})
}
func
TestWorkerInstalledOperator_UpdateGpuFree
(
t
*
testing
.
T
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
,
"admin"
,
"admin"
)
if
err
!=
nil
{
...
...
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