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
0ff8d5c5
Commit
0ff8d5c5
authored
May 11, 2024
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update test
parent
fd96d122
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
6 deletions
+11
-6
workerRunningInfo.go
db/workerRunningInfo.go
+2
-2
workerinfo_test.go
db/workerinfo_test.go
+9
-4
No files found.
db/workerRunningInfo.go
View file @
0ff8d5c5
...
...
@@ -10,7 +10,7 @@ import (
type
DbWorkerRunningInfo
struct
{
ID
string
`bson:"_id,omitempty" json:"id"`
WorkerId
string
`bson:"worker_id" json:"worker_id"`
ModelId
string
`bson:"model_id" json:"model_id"`
ModelId
int
`bson:"model_id" json:"model_id"`
WaitTime
int
`bson:"wait_time" json:"wait_time"`
}
...
...
@@ -36,7 +36,7 @@ func (d *dbWorkerRunning) UpdateWaitTime(ctx context.Context, id string, waitTim
return
err
}
func
(
d
*
dbWorkerRunning
)
FindWorkerByModelId
(
ctx
context
.
Context
,
modelId
string
,
limit
int
)
([]
*
DbWorkerRunningInfo
,
error
)
{
func
(
d
*
dbWorkerRunning
)
FindWorkerByModelId
(
ctx
context
.
Context
,
modelId
int
,
limit
int
)
([]
*
DbWorkerRunningInfo
,
error
)
{
// find all worker that at least one running model's mode_id is equal modelId
// sort by wait time
findOptions
:=
options
.
Find
()
...
...
db/workerinfo_test.go
View file @
0ff8d5c5
...
...
@@ -47,9 +47,10 @@ func initdata(client *mongo.Client) []string {
{
// add worker running info to dbRunning
for
_
,
model
:=
range
worker
.
Models
.
RunningModels
{
id
,
_
:=
strconv
.
Atoi
(
model
.
ModelID
)
runningInfo
:=
&
DbWorkerRunningInfo
{
WorkerId
:
worker
.
WorkerId
,
ModelId
:
model
.
ModelID
,
ModelId
:
id
,
WaitTime
:
model
.
WaitTime
,
}
_
,
err
:=
dbRunning
.
InsertWorker
(
context
.
Background
(),
runningInfo
)
...
...
@@ -75,6 +76,10 @@ func getRandId(max int) string {
return
strconv
.
Itoa
(
rand
.
Intn
(
max
)
+
1
)
}
func
getRandIdInt
(
max
int
)
int
{
return
rand
.
Intn
(
max
)
+
1
}
func
generateAWroker
()
*
DbWorkerInfo
{
return
&
DbWorkerInfo
{
WorkerId
:
uuid
.
NewString
(),
...
...
@@ -462,11 +467,11 @@ func BenchmarkDbWorkerRunning_FindWorkerByModelId(b *testing.B) {
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
db
:=
NewDBWorkerRunning
(
client
,
database
,
c
ollection
)
db
:=
NewDBWorkerRunning
(
client
,
database
,
workerRunningC
ollection
)
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
modelId
:=
getRandId
(
100
)
modelId
:=
getRandId
Int
(
100
)
if
w
,
err
:=
db
.
FindWorkerByModelId
(
context
.
Background
(),
modelId
,
10
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
else
if
len
(
w
)
==
0
{
...
...
@@ -484,7 +489,7 @@ func BenchmarkDbWorkerRunning_FindWorkerByModelId_Parallel(b *testing.B) {
defer
db
.
client
.
Disconnect
(
context
.
Background
())
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
for
pb
.
Next
()
{
modelId
:=
getRandId
(
100
)
modelId
:=
getRandId
Int
(
100
)
if
w
,
err
:=
db
.
FindWorkerByModelId
(
context
.
Background
(),
modelId
,
10
);
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"find worker failed with err:%s"
,
err
))
}
else
if
len
(
w
)
==
0
{
...
...
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