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
vicotor
mogo
Commits
53d9845c
Commit
53d9845c
authored
May 08, 2024
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add new case
parent
f3ae077b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
58 additions
and
0 deletions
+58
-0
workerinfo.go
db/workerinfo.go
+21
-0
workerinfo_test.go
db/workerinfo_test.go
+37
-0
No files found.
db/workerinfo.go
View file @
53d9845c
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"mogo/types"
"mogo/types"
)
)
...
@@ -111,6 +112,26 @@ func (d *dbWorker) FindWorkerByInstalledModelId(ctx context.Context, modelId str
...
@@ -111,6 +112,26 @@ func (d *dbWorker) FindWorkerByInstalledModelId(ctx context.Context, modelId str
return
workers
,
nil
return
workers
,
nil
}
}
func
(
d
*
dbWorker
)
FindWorkerByRunningModelIdWithLimit
(
ctx
context
.
Context
,
modelId
string
,
limit
int64
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one running model's mode_id is equal modelId
findOptions
:=
options
.
Find
()
findOptions
.
SetLimit
(
limit
)
findOptions
.
SetSort
(
bson
.
D
{{
"hardware.gpu.usage"
,
1
}})
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
if
err
!=
nil
{
return
nil
,
err
}
defer
cursor
.
Close
(
ctx
)
var
workers
[]
*
DbWorkerInfo
if
err
=
cursor
.
All
(
ctx
,
&
workers
);
err
!=
nil
{
return
nil
,
err
}
return
workers
,
nil
}
func
(
d
*
dbWorker
)
FindWorkerByRunningModelId
(
ctx
context
.
Context
,
modelId
string
)
([]
*
DbWorkerInfo
,
error
)
{
func
(
d
*
dbWorker
)
FindWorkerByRunningModelId
(
ctx
context
.
Context
,
modelId
string
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one running model's mode_id is equal modelId
// find all worker that at least one running model's mode_id is equal modelId
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
...
...
db/workerinfo_test.go
View file @
53d9845c
...
@@ -363,6 +363,43 @@ func BenchmarkDbWorker_FindWorkerByRunningModelId_Parallel(b *testing.B) {
...
@@ -363,6 +363,43 @@ func BenchmarkDbWorker_FindWorkerByRunningModelId_Parallel(b *testing.B) {
})
})
}
}
func
BenchmarkDbWorker_FindWorkerByRunningModelIdWithLimit
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorker
(
client
,
database
,
collection
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
runningModelId
:=
getRandId
(
100
)
if
w
,
err
:=
db
.
FindWorkerByRunningModelIdWithLimit
(
context
.
Background
(),
runningModelId
,
10
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
else
if
len
(
w
)
==
0
{
b
.
Logf
(
"FindWorkerByRunningModelId find %d with id %s
\n
"
,
len
(
w
),
runningModelId
)
}
}
}
func
BenchmarkDbWorker_FindWorkerByRunningModelIdWithLimit_Parallel
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorker
(
client
,
database
,
collection
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
runningModelId
:=
getRandId
(
100
)
if
w
,
err
:=
db
.
FindWorkerByRunningModelIdWithLimit
(
context
.
Background
(),
runningModelId
,
10
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
else
if
len
(
w
)
==
0
{
b
.
Logf
(
"FindWorkerByRunningModelId find %d with id %s
\n
"
,
len
(
w
),
runningModelId
)
}
}
})
}
func
BenchmarkDbWorker_FindWorkerByInstalledModelId
(
b
*
testing
.
B
)
{
func
BenchmarkDbWorker_FindWorkerByInstalledModelId
(
b
*
testing
.
B
)
{
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
)
client
,
err
:=
ConnectMongoDB
(
"mongodb://localhost:27017"
)
if
err
!=
nil
{
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