diff --git a/app/http.php b/app/http.php index 1a03ff63..5daf32b0 100644 --- a/app/http.php +++ b/app/http.php @@ -538,6 +538,8 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st 'INERNAL_EXECUTOR_HOSTNAME' => System::getHostname() ]); + $coldStartTime = 0; + // Prepare runtime if (!$activeRuntimes->exists($activeRuntimeId)) { if (empty($image) || empty($source) || empty($entrypoint)) { @@ -602,6 +604,10 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st $body = \json_decode($error, true); throw new Exception('An internal curl error has occurred while starting runtime! Error Msg: ' . ($body['message'] ?? $error), 500); } + + $body = \json_decode($executorResponse, true); + + $coldStartTime = \floatval($body['duration']); break; } @@ -745,7 +751,7 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st 'response' => \mb_strcut($res, 0, 1000000), // Limit to 1MB 'stdout' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB 'stderr' => \mb_strcut($stderr, 0, 1000000), // Limit to 1MB - 'duration' => $executionTime, + 'duration' => $executionTime + $coldStartTime, ]; // Update swoole table diff --git a/tests/ExecutorTest.php b/tests/ExecutorTest.php index c4077ed1..851c5562 100644 --- a/tests/ExecutorTest.php +++ b/tests/ExecutorTest.php @@ -147,7 +147,6 @@ public function testExecute(array $data): void { // TODO: @Meldiron test timeout execution. Timeout build too? - /** Execute on running runtime */ $params = [ 'runtimeId' => 'test-exec', 'source' => $data['path'], @@ -171,7 +170,7 @@ public function testExecute(array $data): void $this->assertLessThan(0.5, $response['body']['duration']); $this->assertEquals('{"payload":"","variable":"","unicode":"Unicode magic: êä"}', $response['body']['response']); - /** Execute witn data and variables */ + /** Execute on cold-started runtime */ $response = $this->client->call(Client::METHOD_POST, '/runtimes/test-exec/execution', [], [ 'payload' => 'test payload', 'variables' => [ @@ -194,6 +193,8 @@ public function testExecute(array $data): void ]); $this->assertEquals(200, $response['headers']['status-code']); + $this->assertLessThan(10, $response['body']['duration']); + $this->assertGreaterThan(0.5, $response['body']['duration']); /** Delete runtime */ $response = $this->client->call(Client::METHOD_DELETE, '/runtimes/test-exec-coldstart', [], []);