fix: cpuset limits was determined in a way that apps only used 1 CPU max, ehh, sorry.

This commit is contained in:
Andras Bacsai 2024-01-12 13:47:01 +01:00
parent f1298d1db4
commit 5e7c6906b3
14 changed files with 113 additions and 18 deletions

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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'] = [

View File

@ -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',

View File

@ -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');

View File

@ -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;
}

View File

@ -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');

View File

@ -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',

View File

@ -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'),

View File

@ -1,3 +1,3 @@
<?php
return '4.0.0-beta.189';
return '4.0.0-beta.190';

View File

@ -0,0 +1,76 @@
<?php
use App\Models\Application;
use App\Models\StandaloneMariadb;
use App\Models\StandaloneMongodb;
use App\Models\StandaloneMysql;
use App\Models\StandalonePostgresql;
use App\Models\StandaloneRedis;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('applications', function (Blueprint $table) {
$table->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']);
}
};

View File

@ -7,9 +7,15 @@
<div class="">Limit your container resources by CPU & memory.</div>
<h3 class="pt-4">Limit CPUs</h3>
<div class="flex gap-2">
<x-forms.input placeholder="1.5" label="Number of CPUs" id="resource.limits_cpus" />
<x-forms.input placeholder="0-2" label="CPU sets to use" id="resource.limits_cpuset" />
<x-forms.input placeholder="1024" label="CPU Weight" id="resource.limits_cpu_shares" />
<x-forms.input placeholder="1.5"
helper="0 means use all CPUs. Floating point number, like 0.002 or 1.5. More info <a target='_blank' href='https://docs.docker.com/engine/reference/run/#cpu-share-constraint'>here</a>."
label="Number of CPUs" id="resource.limits_cpus" />
<x-forms.input placeholder="0-2"
helper="Empty means, use all CPU sets. 0-2 will use CPU 0, CPU 1 and CPU 2. More info <a target='_blank' href='https://docs.docker.com/engine/reference/run/#cpu-share-constraint'>here</a>."
label="CPU sets to use" id="resource.limits_cpuset" />
<x-forms.input placeholder="1024"
helper="More info <a target='_blank' href='https://docs.docker.com/engine/reference/run/#cpu-share-constraint'>here</a>."
label="CPU Weight" id="resource.limits_cpu_shares" />
</div>
<h3 class="pt-4">Limit Memory</h3>
<div class="flex gap-2">

View File

@ -4,7 +4,7 @@
"version": "3.12.36"
},
"v4": {
"version": "4.0.0-beta.189"
"version": "4.0.0-beta.190"
}
}
}