mirror of
https://github.com/m1k1o/neko-rooms.git
synced 2026-11-03 07:01:35 -06:00
implement resources server side.
This commit is contained in:
+20
-1
@@ -281,6 +281,23 @@ components:
|
||||
type: string
|
||||
example: /home/neko/.config/chromium
|
||||
|
||||
RoomResources:
|
||||
type: object
|
||||
properties:
|
||||
cpu_shares:
|
||||
type: number
|
||||
description: relative weight vs. other containers
|
||||
nano_cpus:
|
||||
type: number
|
||||
description: in units of 10^-9 CPUs
|
||||
shm_size:
|
||||
type: number
|
||||
description: in bytes
|
||||
default: 2000000000
|
||||
memory:
|
||||
type: number
|
||||
description: in bytes
|
||||
|
||||
RoomSettings:
|
||||
type: object
|
||||
properties:
|
||||
@@ -292,7 +309,7 @@ components:
|
||||
example: m1k1o/neko:latest
|
||||
max_connections:
|
||||
type: number
|
||||
example: 10
|
||||
default: 10
|
||||
user_pass:
|
||||
type: string
|
||||
example: neko
|
||||
@@ -336,6 +353,8 @@ components:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/RoomMount'
|
||||
resources:
|
||||
$ref: '#/components/schemas/RoomResources'
|
||||
browser_policy:
|
||||
$ref: '#/components/schemas/BrowserPolicy'
|
||||
|
||||
|
||||
@@ -28,7 +28,14 @@ func (manager *ApiManagerCtx) roomsList(w http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
|
||||
func (manager *ApiManagerCtx) roomCreate(w http.ResponseWriter, r *http.Request) {
|
||||
request := types.RoomSettings{}
|
||||
// Default values
|
||||
request := types.RoomSettings{
|
||||
MaxConnections: 10,
|
||||
Resources: types.RoomResources{
|
||||
ShmSize: 2 * 1e9,
|
||||
},
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
http.Error(w, err.Error(), 400)
|
||||
return
|
||||
|
||||
@@ -407,9 +407,15 @@ func (manager *RoomManagerCtx) Create(settings types.RoomSettings) (string, erro
|
||||
"SYS_ADMIN",
|
||||
},
|
||||
// Total shm memory usage
|
||||
ShmSize: 2 * 10e9,
|
||||
ShmSize: settings.Resources.ShmSize,
|
||||
// Mounts specs used by the container
|
||||
Mounts: mounts,
|
||||
// Resources contains container's resources (cgroups config, ulimits...)
|
||||
Resources: container.Resources{
|
||||
CPUShares: settings.Resources.CPUShares,
|
||||
NanoCPUs: settings.Resources.NanoCPUs,
|
||||
Memory: settings.Resources.Memory,
|
||||
},
|
||||
}
|
||||
|
||||
networkingConfig := &network.NetworkingConfig{
|
||||
@@ -528,12 +534,23 @@ func (manager *RoomManagerCtx) GetSettings(id string) (*types.RoomSettings, erro
|
||||
}
|
||||
}
|
||||
|
||||
var roomResources types.RoomResources
|
||||
if container.HostConfig != nil {
|
||||
roomResources = types.RoomResources{
|
||||
CPUShares: container.HostConfig.CPUShares,
|
||||
NanoCPUs: container.HostConfig.NanoCPUs,
|
||||
ShmSize: container.HostConfig.ShmSize,
|
||||
Memory: container.HostConfig.Memory,
|
||||
}
|
||||
}
|
||||
|
||||
settings := types.RoomSettings{
|
||||
Name: labels.Name,
|
||||
NekoImage: labels.NekoImage,
|
||||
MaxConnections: labels.Epr.Max - labels.Epr.Min + 1,
|
||||
Mounts: mounts,
|
||||
BrowserPolicy: browserPolicy,
|
||||
Resources: roomResources,
|
||||
}
|
||||
|
||||
err = settings.FromEnv(container.Config.Env)
|
||||
|
||||
+10
-2
@@ -54,6 +54,13 @@ type RoomMount struct {
|
||||
ContainerPath string `json:"container_path"`
|
||||
}
|
||||
|
||||
type RoomResources struct {
|
||||
CPUShares int64 `json:"cpu_shares"` // relative weight vs. other containers
|
||||
NanoCPUs int64 `json:"nano_cpus"` // in units of 10^-9 CPUs
|
||||
ShmSize int64 `json:"shm_size"` // in bytes
|
||||
Memory int64 `json:"memory"` // in bytes
|
||||
}
|
||||
|
||||
type RoomSettings struct {
|
||||
Name string `json:"name"`
|
||||
NekoImage string `json:"neko_image"`
|
||||
@@ -75,8 +82,9 @@ type RoomSettings struct {
|
||||
|
||||
BroadcastPipeline string `json:"broadcast_pipeline,omitempty"`
|
||||
|
||||
Envs map[string]string `json:"envs"`
|
||||
Mounts []RoomMount `json:"mounts"`
|
||||
Envs map[string]string `json:"envs"`
|
||||
Mounts []RoomMount `json:"mounts"`
|
||||
Resources RoomResources `json:"resources"`
|
||||
|
||||
BrowserPolicy *BrowserPolicy `json:"browser_policy,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user