-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #141: configs for main loop and socket polling intervals
- Loading branch information
Showing
5 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
|
||
namespace Buggregator\Trap; | ||
|
||
use Buggregator\Trap\Config\Server\App; | ||
use Buggregator\Trap\Config\Server\Files\SPX as SPXFileConfig; | ||
use Buggregator\Trap\Config\Server\Files\XDebug as XDebugFileConfig; | ||
use Buggregator\Trap\Config\Server\Files\XHProf as XHProfFileConfig; | ||
use Buggregator\Trap\Config\Server\Frontend as FrontendConfig; | ||
use Buggregator\Trap\Config\Server\SocketServer; | ||
use Buggregator\Trap\Config\Server\TcpPorts; | ||
use Buggregator\Trap\Handler\Http\Handler\Websocket; | ||
use Buggregator\Trap\Handler\Http\Middleware; | ||
use Buggregator\Trap\Proto\Buffer; | ||
|
@@ -113,8 +115,11 @@ public function __construct( | |
/** | ||
* @param positive-int $sleep Sleep time in microseconds | ||
*/ | ||
public function run(int $sleep = 50): void | ||
public function run(): void | ||
Check failure on line 118 in src/Application.php GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)
|
||
{ | ||
/** @var App $config */ | ||
$config = $this->container->get(App::class); | ||
$sleep = \max(50, $config->mainLoopInterval); | ||
foreach ($this->senders as $sender) { | ||
\assert($sender instanceof Sender); | ||
if ($sender instanceof Processable) { | ||
|
@@ -191,7 +196,7 @@ function (): void { | |
* @param Inspector $inspector | ||
* @return \Fiber | ||
*/ | ||
public function prepareServerFiber(SocketServer $config, Inspector $inspector, Logger $logger): \Fiber | ||
private function prepareServerFiber(SocketServer $config, Inspector $inspector, Logger $logger): \Fiber | ||
{ | ||
return $this->fibers[] = new \Fiber(function () use ($config, $inspector, $logger): void { | ||
do { | ||
|
@@ -206,7 +211,7 @@ public function prepareServerFiber(SocketServer $config, Inspector $inspector, L | |
}); | ||
} | ||
|
||
public function configureFrontend(bool $separated): void | ||
private function configureFrontend(bool $separated): void | ||
{ | ||
$this->processors[] = $this->senders[] = $wsSender = Sender\FrontendSender::create($this->logger); | ||
$this->container->set($wsSender); | ||
|
@@ -226,8 +231,14 @@ public function configureFrontend(bool $separated): void | |
), | ||
]); | ||
$this->processors[] = $inspector; | ||
/** @var TcpPorts $tcpConfig */ | ||
$tcpConfig = $this->container->get(TcpPorts::class); | ||
$config = $this->container->get(FrontendConfig::class); | ||
$this->prepareServerFiber(new SocketServer(port: $config->port), $inspector, $this->logger); | ||
$this->prepareServerFiber( | ||
new SocketServer(port: $config->port, pollingInterval: $tcpConfig->pollingInterval), | ||
$inspector, | ||
$this->logger, | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -256,7 +267,7 @@ private function createServer(SocketServer $config, Inspector $inspector): Serve | |
return Server::init( | ||
$config->port, | ||
payloadSize: 524_288, | ||
acceptPeriod: .001, | ||
acceptPeriod: \max(50, $config->pollingInterval) / 1e6, | ||
clientInflector: $clientInflector, | ||
logger: $this->logger, | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Buggregator\Trap\Config\Server; | ||
|
||
use Buggregator\Trap\Service\Config\Env; | ||
|
||
/** | ||
* Common configuration for the application | ||
* | ||
* @internal | ||
* @psalm-internal Buggregator\Trap | ||
*/ | ||
final class App | ||
{ | ||
/** | ||
* Main loop interval in microseconds | ||
* @var int<50, max> | ||
*/ | ||
#[Env('TRAP_MAIN_LOOP_INTERVAL')] | ||
public int $mainLoopInterval = 100; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters