Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
Limit the number of hh_client processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Atry committed Nov 23, 2021
1 parent b7ee063 commit 4897d51
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
15 changes: 8 additions & 7 deletions src/Linters/HHClientLinter.hack
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,14 @@ final class HHClientLinter implements Linter {

public async function getLintErrorsAsync(
): Awaitable<vec<HHClientLintError>> {
$lines = await __Private\execute_async(
'hh_client',
'--lint',
$this->getFile()->getPath(),
'--json',
'--from',
'hhast',
$lines = await __Private\ProcessExecutionQueues::HH_CLIENT->waitForAsync(
vec[
'--lint',
$this->getFile()->getPath(),
'--json',
'--from',
'hhast',
],
);
$hh_client_lint_result = TypeAssert\matches<this::TJSONResult>(
\json_decode(
Expand Down
30 changes: 11 additions & 19 deletions src/__Private/ProcessExecutionQueue.hack
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,25 @@ namespace Facebook\HHAST\__Private;
use namespace HH\Lib\Async;

final class ProcessExecutionQueue {
private Async\Semaphore<vec<string>, vec<string>> $impl;
protected function __construct(int $limit, string $process_name) {
$this->impl = new Async\Semaphore(
$limit,
async (vec<string> $args) ==> await execute_async($process_name, ...$args),
);
}

// Random number; it might seem high, but it's likely that `hh_parse` will
// execute quick enough that most of the processes are waiting to be cleaned
// up
const int HH_PARSE_LIMIT = 32;
const int HH_CLIENT_LIMIT = 32;

<<__Memoize>>
public static function getHHParserQueue(): this {
return new self(self::HH_PARSE_LIMIT, 'hh_parse');
private function impl(): Async\Semaphore<vec<string>, vec<string>> {
return new Async\Semaphore(
$this->limit,
async (vec<string> $args) ==>
await execute_async($this->process_name, ...$args),
);
}

<<__Memoize>>
public static function getHHClientQueue(): this {
return new self(self::HH_CLIENT_LIMIT, 'hh_client');
public function __construct(
private int $limit,
private string $process_name,
)[] {
}

public async function waitForAsync(
vec<string> $args,
): Awaitable<vec<string>> {
return await $this->impl->waitForAsync($args);
return await $this->impl()->waitForAsync($args);
}
}
23 changes: 23 additions & 0 deletions src/__Private/ProcessExecutionQueues.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

namespace Facebook\HHAST\__Private;

use namespace HH\Lib\Async;

enum class ProcessExecutionQueues: ProcessExecutionQueue {

// Random number; it might seem high, but it's likely that `hh_parse` will
// execute quick enough that most of the processes are waiting to be cleaned
// up
ProcessExecutionQueue HH_CLIENT =
new ProcessExecutionQueue(32, 'hh_client');
ProcessExecutionQueue HH_PARSE = new ProcessExecutionQueue(32, 'hh_parse');

}
2 changes: 1 addition & 1 deletion src/entrypoints.hack
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function from_file_async(
);

try {
$results = await __Private\ProcessExecutionQueue::getHHParserQueue()
$results = await __Private\ProcessExecutionQueues::HH_PARSE
->waitForAsync($args);
} catch (__Private\SubprocessException $e) {
throw new HHParseError(
Expand Down

0 comments on commit 4897d51

Please sign in to comment.