Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CPU's float #91

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ docker compose down
| `command` | `string` | Commands to run after container is created. Maximum of 100 commands are allowed, each 1024 characters long. | | ' ' |
| `timeout` | `integer` | Commands execution time in seconds | | 600 |
| `remove` | `boolean` | Remove a runtime after execution | | false |
| `cpus` | `integer` | Maximum CPU cores runtime can utilize | | 1 |
| `cpus` | `float` | Maximum CPU cores runtime can utilize | | 1 |
| `memory` | `integer` | Container RAM memory in MBs | | 512 |
| `version` | `string` | Runtime Open Runtime version (allowed values: 'v2', 'v3') | | 'v3' |

Expand All @@ -175,7 +175,7 @@ docker compose down
| `source` | `string` | Path to source files | | ' ' |
| `entrypoint` | `string` | Entrypoint of the code file | | ' ' |
| `variables` | `json` | Environment variables passed into runtime | | [ ] |
| `cpus` | `integer` | Maximum CPU cores runtime can utilize | | 1 |
| `cpus` | `float` | Maximum CPU cores runtime can utilize | | 1 |
| `memory` | `integer` | Container RAM memory in MBs | | 512 |
| `version` | `string` | Runtime Open Runtime version (allowed values: 'v2', 'v3') | | 'v3' |
| `runtimeEntrypoint` | `string` | Commands to run when creating a container. Maximum of 100 commands are allowed, each 1024 characters long. | | ' ' |
Expand Down
9 changes: 5 additions & 4 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use Utopia\Http\Route;
use Utopia\Http\Validator\Assoc;
use Utopia\Http\Validator\Boolean;
use Utopia\Http\Validator\FloatValidator;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename it to Float? It's already in namespace of Validator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its actually called FloatValidator in the http library
https://github.com/utopia-php/http/blob/master/src/Http/Validator/FloatValidator.php

We need to fix it there.

For now we can do use Utopia\Http\Validator\FloatValidator as Float;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do either (I wanted to do this previously 😅) Class names are case-insensitive in PHP, and classes named 'int', 'string', 'float', 'bool', 'true', 'false', or 'null' are forbidden

use Utopia\Http\Validator\Integer;
use Utopia\Http\Validator\Text;
use Utopia\Http\Validator\WhiteList;
Expand Down Expand Up @@ -384,14 +385,14 @@ function removeAllRuntimes(Table $activeRuntimes, Orchestration $orchestration):
->param('command', '', new Text(1024), 'Commands to run after container is created. Maximum of 100 commands are allowed, each 1024 characters long.', true)
->param('timeout', 600, new Integer(), 'Commands execution time in seconds.', true)
->param('remove', false, new Boolean(), 'Remove a runtime after execution.', true)
->param('cpus', 1, new Integer(), 'Container CPU.', true)
->param('cpus', 1.0, new FloatValidator(), 'Container CPU.', true)
->param('memory', 512, new Integer(), 'Comtainer RAM memory.', true)
->param('version', 'v3', new WhiteList(['v2', 'v3']), 'Runtime Open Runtime version.', true)
->inject('orchestration')
->inject('activeRuntimes')
->inject('response')
->inject('log')
->action(function (string $runtimeId, string $image, string $entrypoint, string $source, string $destination, array $variables, string $runtimeEntrypoint, string $command, int $timeout, bool $remove, int $cpus, int $memory, string $version, Orchestration $orchestration, Table $activeRuntimes, Response $response, Log $log) {
->action(function (string $runtimeId, string $image, string $entrypoint, string $source, string $destination, array $variables, string $runtimeEntrypoint, string $command, int $timeout, bool $remove, float $cpus, int $memory, string $version, Orchestration $orchestration, Table $activeRuntimes, Response $response, Log $log) {
$runtimeName = System::getHostname() . '-' . $runtimeId;

$runtimeHostname = \uniqid();
Expand Down Expand Up @@ -711,15 +712,15 @@ function removeAllRuntimes(Table $activeRuntimes, Orchestration $orchestration):
->param('source', '', new Text(0), 'Path to source files.', true)
->param('entrypoint', '', new Text(256), 'Entrypoint of the code file.', true)
->param('variables', [], new Assoc(), 'Environment variables passed into runtime.', true)
->param('cpus', 1, new Integer(), 'Container CPU.', true)
->param('cpus', 1.0, new FloatValidator(), 'Container CPU.', true)
->param('memory', 512, new Integer(), 'Container RAM memory.', true)
->param('version', 'v3', new WhiteList(['v2', 'v3']), 'Runtime Open Runtime version.', true)
->param('runtimeEntrypoint', '', new Text(1024, 0), 'Commands to run when creating a container. Maximum of 100 commands are allowed, each 1024 characters long.', true)
->inject('activeRuntimes')
->inject('response')
->inject('log')
->action(
function (string $runtimeId, ?string $payload, string $path, string $method, array $headers, int $timeout, string $image, string $source, string $entrypoint, array $variables, int $cpus, int $memory, string $version, string $runtimeEntrypoint, Table $activeRuntimes, Response $response, Log $log) {
function (string $runtimeId, ?string $payload, string $path, string $method, array $headers, int $timeout, string $image, string $source, string $entrypoint, array $variables, float $cpus, int $memory, string $version, string $runtimeEntrypoint, Table $activeRuntimes, Response $response, Log $log) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use $cpus in setCpu(). that is https://github.com/utopia-php/orchestration/blob/main/src/Orchestration/Orchestration.php#L217

Notice it accepts int. We need to change orchestration library to support float too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeap we updated it 👍 Release 0.10.1 of it

if (empty($payload)) {
$payload = '';
}
Expand Down
102 changes: 52 additions & 50 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading