Skip to content

Commit 06b6dbf

Browse files
committed
Configurable decoder buffer size
1 parent e5cc038 commit 06b6dbf

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

conf/config.neon

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ parameters:
4646
processTimeout: 60.0
4747
maximumNumberOfProcesses: 32
4848
minimumNumberOfJobsPerProcess: 2
49+
buffer: 134217728 # 128 MB
4950
polluteScopeWithLoopInitialAssignments: true
5051
polluteScopeWithAlwaysIterableForeach: true
5152
polluteCatchScopeWithTryAssignments: false
@@ -169,7 +170,8 @@ parametersSchema:
169170
jobSize: int(),
170171
processTimeout: float(),
171172
maximumNumberOfProcesses: int(),
172-
minimumNumberOfJobsPerProcess: int()
173+
minimumNumberOfJobsPerProcess: int(),
174+
buffer: int()
173175
])
174176
polluteScopeWithLoopInitialAssignments: bool()
175177
polluteScopeWithAlwaysIterableForeach: bool()
@@ -416,6 +418,7 @@ services:
416418
arguments:
417419
internalErrorsCountLimit: %internalErrorsCountLimit%
418420
processTimeout: %parallel.processTimeout%
421+
decoderBufferSize: %parallel.buffer%
419422

420423
-
421424
class: PHPStan\Parallel\Scheduler

src/Command/WorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
115115
$tcpConector = new TcpConnector($loop);
116116
$tcpConector->connect(sprintf('127.0.0.1:%d', $port))->then(function (ConnectionInterface $connection) use ($container, $identifier, $analysedFiles): void {
117117
$out = new Encoder($connection);
118-
$in = new Decoder($connection, true, 512, 0, 4 * 1024 * 1024);
118+
$in = new Decoder($connection, true, 512, 0, $container->getParameter('parallel')['buffer']);
119119
$out->write(['action' => 'hello', 'identifier' => $identifier]);
120120
$this->runWorker($container, $out, $in, $analysedFiles);
121121
});

src/Parallel/ParallelAnalyser.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,20 @@ class ParallelAnalyser
3030
/** @var ProcessPool */
3131
private $processPool;
3232

33+
/** @var int */
34+
private $decoderBufferSize;
35+
3336
public function __construct(
3437
IgnoredErrorHelper $ignoredErrorHelper,
3538
int $internalErrorsCountLimit,
36-
float $processTimeout
39+
float $processTimeout,
40+
int $decoderBufferSize
3741
)
3842
{
3943
$this->ignoredErrorHelper = $ignoredErrorHelper;
4044
$this->internalErrorsCountLimit = $internalErrorsCountLimit;
4145
$this->processTimeout = $processTimeout;
46+
$this->decoderBufferSize = $decoderBufferSize;
4247
}
4348

4449
/**
@@ -78,7 +83,7 @@ public function analyse(
7883
$server = new \React\Socket\TcpServer('127.0.0.1:0', $loop);
7984
$this->processPool = new ProcessPool($server);
8085
$server->on('connection', function (ConnectionInterface $connection) use (&$jobs): void {
81-
$decoder = new Decoder($connection, true, 512, 0, 4 * 1024 * 1024);
86+
$decoder = new Decoder($connection, true, 512, 0, $this->decoderBufferSize);
8287
$encoder = new Encoder($connection);
8388
$decoder->on('data', function (array $data) use (&$jobs, $decoder, $encoder): void {
8489
if ($data['action'] !== 'hello') {

0 commit comments

Comments
 (0)