Skip to content
This repository was archived by the owner on May 14, 2020. It is now read-only.

Commit 35b0dad

Browse files
committed
Determines CPU count automatically.
1 parent 6219b27 commit 35b0dad

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Server created for javascript SPA apps like: Vue, React, Angular, etc.
2323
## Docker usage
2424

2525
```Dockerfile
26-
FROM microparts/static-server-php:1.1.1
26+
FROM microparts/static-server-php:1.1.2
2727

2828
COPY dist/ /app
2929
# frontend yaml configuration

example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ ARG STAGE
1313
RUN npm ci --silent \
1414
&& npm run build
1515

16-
FROM microparts/static-server-php:1.1.1
16+
FROM microparts/static-server-php:1.1.2
1717

1818
COPY --from=0 /usr/app/dist /app
1919
COPY --from=0 /usr/app/configuration /app/configuration

src/HttpApplication.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ final class HttpApplication
6161
*/
6262
private $sha1;
6363

64+
/**
65+
* @var float|int
66+
*/
67+
private $cpuNum;
68+
6469
/**
6570
* HttpApplication constructor.
6671
*
@@ -74,6 +79,7 @@ public function __construct(ConfigurationInterface $conf, string $stage = '', st
7479
$this->conf = $conf;
7580
$this->stage = $stage;
7681
$this->sha1 = $sha1;
82+
$this->cpuNum = swoole_cpu_num() * 2;
7783

7884
$this->header = new Header($conf);
7985

@@ -177,7 +183,7 @@ private function createServer(ConfigurationInterface $conf): Server
177183
];
178184

179185
$server->set(array_merge(
180-
['worker_num' => 4], // should be possible to override worker_num parameter from server config.
186+
['worker_num' => $this->cpuNum], // should be possible to override worker_num parameter from server config.
181187
array_merge($conf->get('server.swoole'), $compress)
182188
));
183189

@@ -191,7 +197,7 @@ private function createServer(ConfigurationInterface $conf): Server
191197
private function registerOnStartListener(): void
192198
{
193199
$this->server->on('start', function ($server) {
194-
$this->logger->info(sprintf('Application state is: STAGE=%s SHA1=%s', $this->stage, $this->sha1));
200+
$this->logger->info(sprintf('Application state is: STAGE=%s SHA1=%s CPU=%s', $this->stage, $this->sha1, $this->cpuNum));
195201
$this->logger->info(sprintf('HTTP static server started at %s:%s', $server->host, $server->port));
196202
});
197203
}

0 commit comments

Comments
 (0)