From 5e7c6906b3886a2e56e090d50ec9b61ae949f0eb Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Fri, 12 Jan 2024 13:47:01 +0100 Subject: [PATCH] fix: cpuset limits was determined in a way that apps only used 1 CPU max, ehh, sorry. --- app/Actions/Database/StartMariadb.php | 4 +- app/Actions/Database/StartMongodb.php | 4 +- app/Actions/Database/StartMysql.php | 4 +- app/Actions/Database/StartPostgresql.php | 4 +- app/Actions/Database/StartRedis.php | 4 +- app/Jobs/ApplicationDeploymentJob.php | 4 +- .../Project/Shared/ResourceLimits.php | 3 - app/Models/Application.php | 6 +- bootstrap/helpers/applications.php | 4 +- config/sentry.php | 2 +- config/version.php | 2 +- ...2024_01_12_123422_update_cpuset_limits.php | 76 +++++++++++++++++++ .../project/shared/resource-limits.blade.php | 12 ++- versions.json | 2 +- 14 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 database/migrations/2024_01_12_123422_update_cpuset_limits.php diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index 2788f2bf3..bb8cd9993 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -57,7 +57,6 @@ class StartMariadb 'mem_swappiness' => $this->database->limits_memory_swappiness, 'mem_reservation' => $this->database->limits_memory_reservation, 'cpus' => (float) $this->database->limits_cpus, - 'cpuset' => $this->database->limits_cpuset, 'cpu_shares' => $this->database->limits_cpu_shares, ] ], @@ -69,6 +68,9 @@ class StartMariadb ] ] ]; + if ($this->database->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); + } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', diff --git a/app/Actions/Database/StartMongodb.php b/app/Actions/Database/StartMongodb.php index c15f3f370..e20973b71 100644 --- a/app/Actions/Database/StartMongodb.php +++ b/app/Actions/Database/StartMongodb.php @@ -64,7 +64,6 @@ class StartMongodb 'mem_swappiness' => $this->database->limits_memory_swappiness, 'mem_reservation' => $this->database->limits_memory_reservation, 'cpus' => (float) $this->database->limits_cpus, - 'cpuset' => $this->database->limits_cpuset, 'cpu_shares' => $this->database->limits_cpu_shares, ] ], @@ -76,6 +75,9 @@ class StartMongodb ] ] ]; + if ($this->database->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); + } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index 1298555db..f566cff55 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -57,7 +57,6 @@ class StartMysql 'mem_swappiness' => $this->database->limits_memory_swappiness, 'mem_reservation' => $this->database->limits_memory_reservation, 'cpus' => (float) $this->database->limits_cpus, - 'cpuset' => $this->database->limits_cpuset, 'cpu_shares' => $this->database->limits_cpu_shares, ] ], @@ -69,6 +68,9 @@ class StartMysql ] ] ]; + if ($this->database->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); + } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index 0f579719b..2a1f854bb 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -67,7 +67,6 @@ class StartPostgresql 'mem_swappiness' => $this->database->limits_memory_swappiness, 'mem_reservation' => $this->database->limits_memory_reservation, 'cpus' => (float) $this->database->limits_cpus, - 'cpuset' => $this->database->limits_cpuset, 'cpu_shares' => $this->database->limits_cpu_shares, ] ], @@ -79,6 +78,9 @@ class StartPostgresql ] ] ]; + if ($this->database->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); + } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { ray('Log Drain Enabled'); $docker_compose['services'][$container_name]['logging'] = [ diff --git a/app/Actions/Database/StartRedis.php b/app/Actions/Database/StartRedis.php index a186fbbc9..88f9576c9 100644 --- a/app/Actions/Database/StartRedis.php +++ b/app/Actions/Database/StartRedis.php @@ -66,7 +66,6 @@ class StartRedis 'mem_swappiness' => $this->database->limits_memory_swappiness, 'mem_reservation' => $this->database->limits_memory_reservation, 'cpus' => (float) $this->database->limits_cpus, - 'cpuset' => $this->database->limits_cpuset, 'cpu_shares' => $this->database->limits_cpu_shares, ] ], @@ -78,6 +77,9 @@ class StartRedis ] ] ]; + if ($this->database->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->database->limits_cpuset); + } if ($this->database->destination->server->isLogDrainEnabled() && $this->database->isLogDrainEnabled()) { $docker_compose['services'][$container_name]['logging'] = [ 'driver' => 'fluentd', diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index e846f9f61..3672591ae 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1016,7 +1016,6 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted 'mem_swappiness' => $this->application->limits_memory_swappiness, 'mem_reservation' => $this->application->limits_memory_reservation, 'cpus' => (float) $this->application->limits_cpus, - 'cpuset' => $this->application->limits_cpuset, 'cpu_shares' => $this->application->limits_cpu_shares, ] ], @@ -1028,6 +1027,9 @@ class ApplicationDeploymentJob implements ShouldQueue, ShouldBeEncrypted ] ] ]; + if ($this->application->limits_cpuset !== 0) { + data_set($docker_compose, 'services.' . $this->container_name . '.cpuset', $this->application->limits_cpuset); + } if ($this->server->isSwarm()) { data_forget($docker_compose, 'services.' . $this->container_name . '.container_name'); data_forget($docker_compose, 'services.' . $this->container_name . '.expose'); diff --git a/app/Livewire/Project/Shared/ResourceLimits.php b/app/Livewire/Project/Shared/ResourceLimits.php index 692c5f741..747478f07 100644 --- a/app/Livewire/Project/Shared/ResourceLimits.php +++ b/app/Livewire/Project/Shared/ResourceLimits.php @@ -44,9 +44,6 @@ class ResourceLimits extends Component if (!$this->resource->limits_cpus) { $this->resource->limits_cpus = "0"; } - if (!$this->resource->limits_cpuset) { - $this->resource->limits_cpuset = "0"; - } if (!$this->resource->limits_cpu_shares) { $this->resource->limits_cpu_shares = 1024; } diff --git a/app/Models/Application.php b/app/Models/Application.php index c16adc7e6..97b7f1736 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -429,7 +429,7 @@ class Application extends BaseModel } public function isConfigurationChanged($save = false) { - $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->port_exposes . $this->port_mappings . $this->base_directory . $this->publish_directory . $this->health_check_path . $this->health_check_port . $this->health_check_host . $this->health_check_method . $this->health_check_return_code . $this->health_check_scheme . $this->health_check_response_text . $this->health_check_interval . $this->health_check_timeout . $this->health_check_retries . $this->health_check_start_period . $this->health_check_enabled . $this->limits_memory . $this->limits_swap . $this->limits_swappiness . $this->limits_reservation . $this->limits_cpus . $this->limits_cpuset . $this->limits_cpu_shares . $this->dockerfile . $this->dockerfile_location . $this->custom_labels; + $newConfigHash = $this->fqdn . $this->git_repository . $this->git_branch . $this->git_commit_sha . $this->build_pack . $this->static_image . $this->install_command . $this->build_command . $this->start_command . $this->port_exposes . $this->port_mappings . $this->base_directory . $this->publish_directory . $this->dockerfile . $this->dockerfile_location . $this->custom_labels; if ($this->pull_request_id === 0 || $this->pull_request_id === null) { $newConfigHash .= json_encode($this->environment_variables->all()); } else { @@ -642,7 +642,6 @@ class Application extends BaseModel 'mem_swappiness' => $this->limits_memory_swappiness, 'mem_reservation' => $this->limits_memory_reservation, 'cpus' => (float) $this->limits_cpus, - 'cpuset' => $this->limits_cpuset, 'cpu_shares' => $this->limits_cpu_shares, ] ], @@ -654,6 +653,9 @@ class Application extends BaseModel ] ] ]; + if ($this->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$container_name}.cpuset", $this->limits_cpuset); + } if ($server->isSwarm()) { data_forget($docker_compose, 'services.' . $container_name . '.container_name'); data_forget($docker_compose, 'services.' . $container_name . '.expose'); diff --git a/bootstrap/helpers/applications.php b/bootstrap/helpers/applications.php index d3e28d524..0779c872f 100644 --- a/bootstrap/helpers/applications.php +++ b/bootstrap/helpers/applications.php @@ -167,7 +167,6 @@ function generateComposeFile(string $deploymentUuid, Server $server, string $net 'mem_swappiness' => $application->limits_memory_swappiness, 'mem_reservation' => $application->limits_memory_reservation, 'cpus' => (int) $application->limits_cpus, - 'cpuset' => $application->limits_cpuset, 'cpu_shares' => $application->limits_cpu_shares, ] ], @@ -179,6 +178,9 @@ function generateComposeFile(string $deploymentUuid, Server $server, string $net ] ] ]; + if ($application->limits_cpuset !== 0) { + data_set($docker_compose, "services.{$containerName}.cpuset", $application->limits_cpuset); + } if ($server->isLogDrainEnabled() && $application->isLogDrainEnabled()) { $docker_compose['services'][$containerName]['logging'] = [ 'driver' => 'fluentd', diff --git a/config/sentry.php b/config/sentry.php index 2d526fb85..9426b3076 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ return [ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.189', + 'release' => '4.0.0-beta.190', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index dec4e2c54..0e5343e99 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ string('limits_cpuset')->nullable()->default(null)->change(); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default(null)->change(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default(null)->change(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default(null)->change(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default(null)->change(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default(null)->change(); + }); + Application::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + StandalonePostgresql::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + StandaloneRedis::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + StandaloneMariadb::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + StandaloneMysql::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + StandaloneMongodb::where('limits_cpuset', '0')->update(['limits_cpuset' => null]); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('applications', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Schema::table('standalone_postgresqls', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Schema::table('standalone_redis', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Schema::table('standalone_mariadbs', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Schema::table('standalone_mysqls', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Schema::table('standalone_mongodbs', function (Blueprint $table) { + $table->string('limits_cpuset')->nullable()->default("0")->change(); + }); + Application::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + StandalonePostgresql::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + StandaloneRedis::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + StandaloneMariadb::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + StandaloneMysql::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + StandaloneMongodb::where('limits_cpuset', null)->update(['limits_cpuset' => '0']); + } +}; diff --git a/resources/views/livewire/project/shared/resource-limits.blade.php b/resources/views/livewire/project/shared/resource-limits.blade.php index 025160459..0b03d1cdd 100644 --- a/resources/views/livewire/project/shared/resource-limits.blade.php +++ b/resources/views/livewire/project/shared/resource-limits.blade.php @@ -7,9 +7,15 @@
Limit your container resources by CPU & memory.

Limit CPUs

- - - + + +

Limit Memory

diff --git a/versions.json b/versions.json index a8d4bd649..04da3a38c 100644 --- a/versions.json +++ b/versions.json @@ -4,7 +4,7 @@ "version": "3.12.36" }, "v4": { - "version": "4.0.0-beta.189" + "version": "4.0.0-beta.190" } } }