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

Limit the maximum number of hh_client processes to run in parallel #400

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
38 changes: 0 additions & 38 deletions src/__Private/ParserQueue.hack

This file was deleted.

36 changes: 36 additions & 0 deletions src/__Private/ProcessExecutionQueue.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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;

final class ProcessExecutionQueue {

<<__Memoize>>
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),
);
}

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);
}
}
21 changes: 21 additions & 0 deletions src/__Private/ProcessExecutionQueues.hack
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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;

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');

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

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