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
5c2b377e
Commit
5c2b377e
authored
May 10, 2024
by
luxq
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update worker info and test
parent
53d9845c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
164 additions
and
230 deletions
+164
-230
workerinfo.go
db/workerinfo.go
+12
-56
workerinfo_test.go
db/workerinfo_test.go
+103
-136
worker.go
types/worker.go
+49
-38
No files found.
db/workerinfo.go
View file @
5c2b377e
...
@@ -95,28 +95,12 @@ func (d *dbWorker) UpdateNodeInfo(ctx context.Context, id string, nodeInfo *type
...
@@ -95,28 +95,12 @@ func (d *dbWorker) UpdateNodeInfo(ctx context.Context, id string, nodeInfo *type
return
err
return
err
}
}
func
(
d
*
dbWorker
)
FindWorkerByInstalledModelId
(
ctx
context
.
Context
,
modelId
string
)
([]
*
DbWorkerInfo
,
error
)
{
func
(
d
*
dbWorker
)
FindWorkerByRunningModelAndSortByWaitTime
(
ctx
context
.
Context
,
modelId
string
,
limit
int
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one installed model's mode_id is equal modelId
selector
:=
bson
.
M
{
"model_infos.installed_models.model_id"
:
modelId
}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
)
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
)
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
// find all worker that at least one running model's mode_id is equal modelId
// sort by wait time
findOptions
:=
options
.
Find
()
findOptions
:=
options
.
Find
()
findOptions
.
SetLimit
(
limit
)
findOptions
.
SetLimit
(
int64
(
limit
)
)
findOptions
.
SetSort
(
bson
.
D
{{
"
hardware.gpu.usag
e"
,
1
}})
findOptions
.
SetSort
(
bson
.
D
{{
"
model_infos.running_models.wait_tim
e"
,
1
}})
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
...
@@ -132,27 +116,15 @@ func (d *dbWorker) FindWorkerByRunningModelIdWithLimit(ctx context.Context, mode
...
@@ -132,27 +116,15 @@ func (d *dbWorker) FindWorkerByRunningModelIdWithLimit(ctx context.Context, mode
return
workers
,
nil
return
workers
,
nil
}
}
func
(
d
*
dbWorker
)
FindWorkerByRunningModelId
(
ctx
context
.
Context
,
modelId
string
)
([]
*
DbWorkerInfo
,
error
)
{
func
(
d
*
dbWorker
)
FindWorkerByInstallModelAndSortByGpuRam
(
ctx
context
.
Context
,
modelId
string
,
performance
int
,
ram
int
,
limit
int
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one running model's mode_id is equal modelId
// find all worker that at least one installed model's mode_id is equal modelId
selector
:=
bson
.
M
{
"model_infos.running_models.model_id"
:
modelId
}
// sort by gpu ram
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
)
findOptions
:=
options
.
Find
()
if
err
!=
nil
{
findOptions
.
SetLimit
(
int64
(
limit
))
return
nil
,
err
findOptions
.
SetSort
(
bson
.
D
{{
"hardware.gpu.ram"
,
1
}})
}
defer
cursor
.
Close
(
ctx
)
var
workers
[]
*
DbWorkerInfo
if
err
=
cursor
.
All
(
ctx
,
&
workers
);
err
!=
nil
{
return
nil
,
err
}
return
workers
,
nil
}
func
(
d
*
dbWorker
)
FindWorkerByGpuModel
(
ctx
context
.
Context
,
model
string
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one gpu model is equal model.
selector
:=
bson
.
M
{
"hardware.gpu.model"
:
model
}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
)
selector
:=
bson
.
M
{
"model_infos.installed_models.model_id"
:
modelId
,
"hardware.gpu.performance"
:
bson
.
M
{
"$gte"
:
performance
},
"hardware.gpu.ram"
:
bson
.
M
{
"$gte"
:
ram
}}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
,
findOptions
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -163,21 +135,5 @@ func (d *dbWorker) FindWorkerByGpuModel(ctx context.Context, model string) ([]*D
...
@@ -163,21 +135,5 @@ func (d *dbWorker) FindWorkerByGpuModel(ctx context.Context, model string) ([]*D
return
nil
,
err
return
nil
,
err
}
}
return
workers
,
nil
return
workers
,
nil
}
func
(
d
*
dbWorker
)
FindWorkerByGpuRam
(
ctx
context
.
Context
,
ram
uint
)
([]
*
DbWorkerInfo
,
error
)
{
// find all worker that at least one gpu ram is greater or equal than ram.
selector
:=
bson
.
M
{
"hardware.gpu.ram"
:
bson
.
M
{
"$gte"
:
ram
}}
cursor
,
err
:=
d
.
col
.
Find
(
ctx
,
selector
)
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
}
}
db/workerinfo_test.go
View file @
5c2b377e
This diff is collapsed.
Click to expand it.
types/worker.go
View file @
5c2b377e
...
@@ -6,65 +6,71 @@ type NodeInfo struct {
...
@@ -6,65 +6,71 @@ type NodeInfo struct {
DeviceIp
string
`bson:"device_ip" json:"device_ip"`
DeviceIp
string
`bson:"device_ip" json:"device_ip"`
}
}
type
InstalledModelInfo
struct
{
type
InstalledModel
struct
{
ModelId
string
`bson:"model_id" json:"model_id"`
ModelID
string
`bson:"model_id" json:"model_id"`
DiskSize
uint64
`bson:"disk_size" json:"disk_size"`
DiskSize
int
`bson:"disk_size" json:"disk_size"`
InstalledTime
int64
`bson:"installed_time" json:"installed_time"`
LastRunTime
int64
`bson:"last_run_time" json:"last_run_time"`
}
}
type
RunningModelInfo
struct
{
type
RunningModel
struct
{
ModelId
string
`bson:"model_id" json:"model_id"`
ModelID
string
`bson:"model_id" json:"model_id"`
StartedTime
uint64
`bson:"started_time" json:"started_time"`
GpuSeq
int
`bson:"gpu_seq" json:"gpu_seq"`
LatestTime
uint64
`bson:"latest_time" json:"latest_time"`
GpuRAM
int
`bson:"gpu_ram" json:"gpu_ram"`
RunCount
uint64
`bson:"run_count" json:"run_count"`
StartedTime
int64
`bson:"started_time" json:"started_time"`
GpuRamUsed
uint64
`bson:"gpu_ram" json:"gpu_ram"`
LastWorkTime
int64
`bson:"last_work_time" json:"last_work_time"`
TotalRunCount
int
`bson:"total_run_count" json:"total_run_count"`
WaitTime
int
`bson:"wait_time" json:"wait_time"`
}
}
type
ModelInfo
struct
{
type
ModelInfo
struct
{
InstalledModels
[]
*
InstalledModelInfo
`bson:"installed_models" json:"installed_models"`
InstalledModels
[]
*
InstalledModel
`bson:"installed_models" json:"installed_models"`
RunningModels
[]
*
RunningModelInfo
`bson:"running_models" json:"running_models"`
RunningModels
[]
*
RunningModel
`bson:"running_models" json:"running_models"`
}
type
DeviceInfo
struct
{
DeviceType
string
`bson:"device_type" json:"device_type"`
DeviceModel
string
`bson:"device_model" json:"device_model"`
DeviceParam
string
`bson:"device_param" json:"device_param"`
DevicePower
uint64
`bson:"device_power" json:"device_power"`
}
}
type
DeviceUsage
struct
{
type
HardwareInfo
struct
{
DeviceType
string
`bson:"device_type" json:"device_type"`
CPU
*
CpuInfo
`bson:"CPU" json:"CPU"`
DeviceUsage
uint64
`bson:"device_usage" json:"device_usage"`
GPU
[]
*
GpuInfo
`bson:"GPU" json:"GPU"`
RAM
*
RamInfo
`bson:"RAM" json:"RAM"`
DISK
*
DiskInfo
`bson:"DISK" json:"DISK"`
NET
*
NetInfo
`bson:"NET" json:"NET"`
}
}
type
CpuInfo
struct
{
type
CpuInfo
struct
{
Model
string
`bson:"model" json:"model"`
Model
string
`bson:"model" json:"model "`
Core
uint
`bson:"core" json:"core"`
Number
int
`bson:"number" json:"number"`
Usage
uint
`bson:"usage" json:"usage"`
Cores
int
`bson:"cores" json:"cores"`
Threads
int
`bson:"threads" json:"threads"`
Usage
int
`bson:"usage" json:"usage"`
}
}
type
GpuInfo
struct
{
type
GpuInfo
struct
{
Model
string
`bson:"model" json:"model"`
Seq
int
`bson:"seq" json:"seq"`
Ram
uint
`bson:"ram" json:"ram"`
UUID
string
`bson:"uuid" json:"uuid"`
Usage
uint
`bson:"usage" json:"usage"`
Model
string
`bson:"model" json:"model "`
Occupy
uint
`bson:"occupy" json:"occupy"`
Performance
int
`bson:"performance" json:"performance"`
Temp
uint
`bson:"temp" json:"temp"`
PowerRating
int
`bson:"power_rating" json:"power_rating"`
MemTotal
int
`bson:"mem_total" json:"mem_total"`
MemFree
int
`bson:"mem_free" json:"mem_free"`
Usage
int
`bson:"usage" json:"usage"`
Temp
int
`bson:"temp" json:"temp "`
PowerRt
int
`bson:"power_rt" json:"power_rt"`
}
}
type
RamInfo
struct
{
type
RamInfo
struct
{
Size
uint
`bson:"size" json:"size
"`
Total
int
`bson:"total" json:"total
"`
Usage
uint
`bson:"usage" json:"usag
e"`
Free
int
`bson:"free" json:"fre
e"`
}
}
type
DiskInfo
struct
{
type
DiskInfo
struct
{
Size
uint
`bson:"size" json:"size
"`
Total
int
`bson:"total" json:"total
"`
Usage
uint
`bson:"usage" json:"usag
e"`
Free
int
`bson:"free" json:"fre
e"`
}
}
type
HardwareInfo
struct
{
type
NetInfo
struct
{
Cpu
[]
*
CpuInfo
`bson:"cpu" json:"cpu"`
IP
string
`bson:"ip" json:"ip"`
Gpu
[]
*
GpuInfo
`bson:"gpu" json:"gpu"`
Mac
string
`bson:"mac" json:"mac"`
Ram
*
RamInfo
`bson:"ram" json:"ram"`
Bandwidth
int
`bson:"bandwidth" json:"bandwidth"`
Disk
*
DiskInfo
`bson:"disk" json:"disk"`
}
}
type
WorkerInfo
struct
{
type
WorkerInfo
struct
{
...
@@ -73,3 +79,8 @@ type WorkerInfo struct {
...
@@ -73,3 +79,8 @@ type WorkerInfo struct {
ModelInofs
*
ModelInfo
`bson:"model_infos" json:"model_infos"`
ModelInofs
*
ModelInfo
`bson:"model_infos" json:"model_infos"`
Hardware
*
HardwareInfo
`bson:"hardware" json:"hardware"`
Hardware
*
HardwareInfo
`bson:"hardware" json:"hardware"`
}
}
type
WorkerModelInfo
struct
{
WorkerId
string
`bson:"worker_id" json:"worker_id"`
ModelId
string
`bson:"model_id" json:"model_id"`
}
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