From abf6fc25f76529aeb88e64239e32e487f38776b6 Mon Sep 17 00:00:00 2001 From: Zack Pollard Date: Wed, 5 Jun 2024 11:45:53 +0100 Subject: [PATCH] chore: change default thumbnail concurrency and auto-detect container core count (#9981) * feat: automatically detect amount of CPU cores and allow overriding with CPU_CORES env var * chore: change default thumbnail concurrency to 3 --- .dockerignore | 1 + docker/scripts/get-cpus.sh | 49 +++++++++++++++++++ docs/docs/administration/system-settings.md | 5 ++ docs/docs/install/environment-variables.md | 21 ++++---- server/Dockerfile | 1 + server/src/config.ts | 2 +- .../services/system-config.service.spec.ts | 2 +- server/start.sh | 6 +++ 8 files changed, 75 insertions(+), 12 deletions(-) create mode 100755 docker/scripts/get-cpus.sh diff --git a/.dockerignore b/.dockerignore index fc95d2c6ab..7559cf366a 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,6 +4,7 @@ design/ docker/ +!docker/scripts docs/ e2e/ fastlane/ diff --git a/docker/scripts/get-cpus.sh b/docker/scripts/get-cpus.sh new file mode 100755 index 0000000000..7e5ca78a1b --- /dev/null +++ b/docker/scripts/get-cpus.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +set -eu + +LOG_LEVEL="${IMMICH_LOG_LEVEL:='info'}" + +logDebug() { + if [ "$LOG_LEVEL" = "debug" ] || [ "$LOG_LEVEL" = "verbose" ]; then + echo "DEBUG: $1" >&2 + fi +} + +if [ -f /sys/fs/cgroup/cgroup.controllers ]; then + logDebug "cgroup v2 detected." + if [ -f /sys/fs/cgroup/cpu.max ]; then + read -r quota period \*1 | server | api, microservices | -| `IMMICH_CONFIG_FILE` | Path to config file | | server | api, microservices | -| `IMMICH_WEB_ROOT` | Path of root index.html | `/usr/src/app/www` | server | api | -| `IMMICH_REVERSE_GEOCODING_ROOT` | Path of reverse geocoding dump directory | `/usr/src/resources` | server | microservices | -| `NO_COLOR` | Set to `true` to disable color-coded log output | `false` | server, machine learning | | +| Variable | Description | Default | Containers | Workers | +| :------------------------------ | :---------------------------------------------- | :--------------------------: | :----------------------- | :----------------- | +| `TZ` | Timezone | | server | microservices | +| `IMMICH_ENV` | Environment (production, development) | `production` | server, machine learning | api, microservices | +| `IMMICH_LOG_LEVEL` | Log Level (verbose, debug, log, warn, error) | `log` | server, machine learning | api, microservices | +| `IMMICH_MEDIA_LOCATION` | Media Location | `./upload`\*1 | server | api, microservices | +| `IMMICH_CONFIG_FILE` | Path to config file | | server | api, microservices | +| `IMMICH_WEB_ROOT` | Path of root index.html | `/usr/src/app/www` | server | api | +| `IMMICH_REVERSE_GEOCODING_ROOT` | Path of reverse geocoding dump directory | `/usr/src/resources` | server | microservices | +| `NO_COLOR` | Set to `true` to disable color-coded log output | `false` | server, machine learning | | +| `CPU_CORES` | Amount of cores available to the immich server | auto-detected cpu core count | server | | \*1: With the default `WORKDIR` of `/usr/src/app`, this path will resolve to `/usr/src/app/upload`. It only need to be set if the Immich deployment method is changing. diff --git a/server/Dockerfile b/server/Dockerfile index 28b4ed0960..c61f181a8f 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -54,6 +54,7 @@ COPY --from=web /usr/src/app/build ./www COPY server/resources resources COPY server/package.json server/package-lock.json ./ COPY server/start*.sh ./ +COPY "docker/scripts/get-cpus.sh" ./ RUN npm link && npm install -g @immich/cli && npm cache clean --force COPY LICENSE /licenses/LICENSE.txt COPY LICENSE /LICENSE diff --git a/server/src/config.ts b/server/src/config.ts index 4d1704c47f..5fbaa25e6d 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -240,7 +240,7 @@ export const defaults = Object.freeze({ [QueueName.SIDECAR]: { concurrency: 5 }, [QueueName.LIBRARY]: { concurrency: 5 }, [QueueName.MIGRATION]: { concurrency: 5 }, - [QueueName.THUMBNAIL_GENERATION]: { concurrency: 5 }, + [QueueName.THUMBNAIL_GENERATION]: { concurrency: 3 }, [QueueName.VIDEO_CONVERSION]: { concurrency: 1 }, [QueueName.NOTIFICATION]: { concurrency: 5 }, }, diff --git a/server/src/services/system-config.service.spec.ts b/server/src/services/system-config.service.spec.ts index 281090cb3f..ea287321b1 100644 --- a/server/src/services/system-config.service.spec.ts +++ b/server/src/services/system-config.service.spec.ts @@ -42,7 +42,7 @@ const updatedConfig = Object.freeze({ [QueueName.SIDECAR]: { concurrency: 5 }, [QueueName.LIBRARY]: { concurrency: 5 }, [QueueName.MIGRATION]: { concurrency: 5 }, - [QueueName.THUMBNAIL_GENERATION]: { concurrency: 5 }, + [QueueName.THUMBNAIL_GENERATION]: { concurrency: 3 }, [QueueName.VIDEO_CONVERSION]: { concurrency: 1 }, [QueueName.NOTIFICATION]: { concurrency: 5 }, }, diff --git a/server/start.sh b/server/start.sh index 9c9b4754a0..5aa7ee01b2 100755 --- a/server/start.sh +++ b/server/start.sh @@ -17,4 +17,10 @@ read_file_and_export "DB_USERNAME_FILE" "DB_USERNAME" read_file_and_export "DB_PASSWORD_FILE" "DB_PASSWORD" read_file_and_export "REDIS_PASSWORD_FILE" "REDIS_PASSWORD" +export CPU_CORES="${CPU_CORES:=$(./get-cpus.sh)}" +echo "Detected CPU Cores: $CPU_CORES" +if [ "$CPU_CORES" -gt 4 ]; then + export UV_THREADPOOL_SIZE=$CPU_CORES +fi + exec node /usr/src/app/dist/main "$@"