feat: first pass at implement resource limitation on a pre-process basis
This commit is contained in:
@@ -27,6 +27,8 @@ Valid resource options include:
|
|||||||
- `--network-ingress`
|
- `--network-ingress`
|
||||||
- `--network-egress`
|
- `--network-egress`
|
||||||
|
|
||||||
|
Resource limits and reservations are applied only during the `run` and `deploy` phases of an application, and will not impact the `build` phase of an application.
|
||||||
|
|
||||||
### Resource Limits
|
### Resource Limits
|
||||||
|
|
||||||
When specified and supported, a resource limit will ensure that your app does not go _over_ the specified value. If this occurs, the underlying scheduler may either cap resource utilization, or it may decide to terminate and reschedule your process.
|
When specified and supported, a resource limit will ensure that your app does not go _over_ the specified value. If this occurs, the underlying scheduler may either cap resource utilization, or it may decide to terminate and reschedule your process.
|
||||||
|
|||||||
@@ -53,3 +53,17 @@ This plugin implements various functionality through `plugn` triggers to integra
|
|||||||
- `scheduler-stop`
|
- `scheduler-stop`
|
||||||
- `scheduler-tags-create`
|
- `scheduler-tags-create`
|
||||||
- `scheduler-tags-destroy`
|
- `scheduler-tags-destroy`
|
||||||
|
|
||||||
|
## Supported Resource Management Properties
|
||||||
|
|
||||||
|
The `docker-local` scheduler supports a minimal list of resource _limits_ and _reservations_. The following properties are supported:
|
||||||
|
|
||||||
|
### Resource Limits
|
||||||
|
|
||||||
|
- cpu: (docker option: `--cpus`), and is specified in number of CPUs a process can access.
|
||||||
|
- memory: (docker option: `--memory`) and should be specified with a suffix of `b` (bytes), `k` (kilobytes), `m` (megabytes), `g` (gigabytes)
|
||||||
|
- memory-swap: (docker option: `--memory-swap`) and should be specified with a suffix of `b` (bytes), `k` (kilobytes), `m` (megabytes), `g` (gigabytes)
|
||||||
|
|
||||||
|
### Resource Reservations
|
||||||
|
|
||||||
|
- memory: (docker option: `--memory-reservation`) and should be specified with a suffix of `b` (bytes), `k` (kilobytes), `m` (megabytes), `g` (gigabytes)
|
||||||
|
|||||||
@@ -248,6 +248,8 @@ echo 'derp.dkr.ecr.us-east-1.amazonaws.com'
|
|||||||
|
|
||||||
### `docker-args-build`
|
### `docker-args-build`
|
||||||
|
|
||||||
|
> Warning: Deprecated, please use `docker-args-process-build` instead
|
||||||
|
|
||||||
- Description:
|
- Description:
|
||||||
- Invoked by: `internal function dokku_build() (build phase)`
|
- Invoked by: `internal function dokku_build() (build phase)`
|
||||||
- Arguments: `$APP $IMAGE_SOURCE_TYPE`
|
- Arguments: `$APP $IMAGE_SOURCE_TYPE`
|
||||||
@@ -271,6 +273,8 @@ echo -n "$STDIN$output"
|
|||||||
|
|
||||||
### `docker-args-deploy`
|
### `docker-args-deploy`
|
||||||
|
|
||||||
|
> Warning: Deprecated, please use `docker-args-process-deploy` instead
|
||||||
|
|
||||||
- Description:
|
- Description:
|
||||||
- Invoked by: `dokku deploy`
|
- Invoked by: `dokku deploy`
|
||||||
- Arguments: `$APP $IMAGE_TAG [$PROC_TYPE $CONTAINER_INDEX]`
|
- Arguments: `$APP $IMAGE_TAG [$PROC_TYPE $CONTAINER_INDEX]`
|
||||||
@@ -289,6 +293,8 @@ verify_app_name "$APP"
|
|||||||
|
|
||||||
### `docker-args-run`
|
### `docker-args-run`
|
||||||
|
|
||||||
|
> Warning: Deprecated, please use `docker-args-process-run` instead
|
||||||
|
|
||||||
- Description:
|
- Description:
|
||||||
- Invoked by: `dokku run`
|
- Invoked by: `dokku run`
|
||||||
- Arguments: `$APP $IMAGE_TAG`
|
- Arguments: `$APP $IMAGE_TAG`
|
||||||
@@ -305,6 +311,42 @@ verify_app_name "$APP"
|
|||||||
# TODO
|
# TODO
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `docker-args-process-deploy`
|
||||||
|
|
||||||
|
- Description: `$PROC_TYPE` may be set to magic `_all_` process type to signify global docker deploy options.
|
||||||
|
- Invoked by: `dokku deploy`
|
||||||
|
- Arguments: `$APP $IMAGE_TAG $IMAGE_SOURCE_TYPE [$PROC_TYPE $CONTAINER_INDEX]`
|
||||||
|
- Example:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
|
||||||
|
verify_app_name "$APP"
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
```
|
||||||
|
|
||||||
|
### `docker-args-process-run`
|
||||||
|
|
||||||
|
- Description: `$PROC_TYPE` may be set to magic `_all_` process type to signify global docker run options.
|
||||||
|
- Invoked by: `dokku run`
|
||||||
|
- Arguments: `$APP $IMAGE_TAG $IMAGE_SOURCE_TYPE [$PROC_TYPE $CONTAINER_INDEX]`
|
||||||
|
- Example:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
APP="$1"; IMAGE_TAG="$2"; IMAGE=$(get_app_image_name $APP $IMAGE_TAG)
|
||||||
|
verify_app_name "$APP"
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
```
|
||||||
|
|
||||||
### `git-post-pull`
|
### `git-post-pull`
|
||||||
|
|
||||||
- Description:
|
- Description:
|
||||||
|
|||||||
2
plugins/resource/.gitignore
vendored
2
plugins/resource/.gitignore
vendored
@@ -4,3 +4,5 @@
|
|||||||
/install
|
/install
|
||||||
/post-delete
|
/post-delete
|
||||||
/report
|
/report
|
||||||
|
/docker-args-process-deploy
|
||||||
|
/docker-args-process-run
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ include ../../common.mk
|
|||||||
GO_ARGS ?= -a
|
GO_ARGS ?= -a
|
||||||
|
|
||||||
SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/report subcommands/reserve subcommands/reserve-clear
|
SUBCOMMANDS = subcommands/limit subcommands/limit-clear subcommands/report subcommands/reserve subcommands/reserve-clear
|
||||||
TRIGGERS = triggers/install triggers/post-delete triggers/report
|
TRIGGERS = triggers/docker-args-process-deploy triggers/install triggers/post-delete triggers/report
|
||||||
build-in-docker: clean
|
build-in-docker: clean
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
-v $$PWD/../..:$(GO_REPO_ROOT) \
|
-v $$PWD/../..:$(GO_REPO_ROOT) \
|
||||||
@@ -23,7 +23,7 @@ subcommands/%: src/subcommands/*/%.go
|
|||||||
go build $(GO_ARGS) -o $@ $<
|
go build $(GO_ARGS) -o $@ $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf commands subcommands triggers install post-delete report
|
rm -rf commands subcommands triggers docker-args-process-deploy docker-args-process-run install post-delete report
|
||||||
|
|
||||||
src-clean:
|
src-clean:
|
||||||
rm -rf .gitignore src triggers vendor Makefile *.go
|
rm -rf .gitignore src triggers vendor Makefile *.go
|
||||||
@@ -35,3 +35,4 @@ triggers/%: src/triggers/*/%.go
|
|||||||
|
|
||||||
triggers-copy:
|
triggers-copy:
|
||||||
cp triggers/* .
|
cp triggers/* .
|
||||||
|
ln -s docker-args-process-deploy docker-args-process-run
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/dokku/dokku/plugins/common"
|
||||||
|
)
|
||||||
|
|
||||||
|
// outputs the process-specific docker options
|
||||||
|
func main() {
|
||||||
|
stdin, err := ioutil.ReadAll(os.Stdin)
|
||||||
|
if err != nil {
|
||||||
|
common.LogFail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
flag.Parse()
|
||||||
|
appName := flag.Arg(0)
|
||||||
|
procType := flag.Arg(3)
|
||||||
|
|
||||||
|
resources, err := common.PropertyGetAll("resource", appName)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Print(string(stdin))
|
||||||
|
common.LogFail(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
limits := make(map[string]string)
|
||||||
|
reservations := make(map[string]string)
|
||||||
|
|
||||||
|
validLimits := map[string]bool{
|
||||||
|
"cpu": true,
|
||||||
|
"memory": true,
|
||||||
|
"memory-swap": true,
|
||||||
|
}
|
||||||
|
validReservations := map[string]bool{
|
||||||
|
"memory": true,
|
||||||
|
}
|
||||||
|
validPrefixes := []string{"_default_.", fmt.Sprintf("%s.", procType)}
|
||||||
|
for _, validPrefix := range validPrefixes {
|
||||||
|
for key, value := range resources {
|
||||||
|
if !strings.HasPrefix(key, validPrefix) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
parts := strings.SplitN(strings.TrimPrefix(key, validPrefix), ".", 2)
|
||||||
|
if parts[0] == "limit" {
|
||||||
|
if !validLimits[parts[1]] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
limits[parts[1]] = value
|
||||||
|
}
|
||||||
|
if parts[0] == "reserve" {
|
||||||
|
if !validReservations[parts[1]] {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
reservations[parts[1]] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range limits {
|
||||||
|
fmt.Print(" --%s=%s ", key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
for key, value := range reservations {
|
||||||
|
fmt.Print(" --%s-reservation=%s ", key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Print(string(stdin))
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"github.com/dokku/dokku/plugins/resource"
|
"github.com/dokku/dokku/plugins/resource"
|
||||||
)
|
)
|
||||||
|
|
||||||
// displays a buildpacks report for one or more apps
|
// displays a resource report for one or more apps
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
appName := flag.Arg(0)
|
appName := flag.Arg(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user