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

Commit

Permalink
Limit the maximum number of hh_client processes to run in parallel (#400
Browse files Browse the repository at this point in the history
)

* Rename ParseQueue to ProcessExecutionQueue, supporting processes other than `hh_parse`
* Limit the number of `hh_client` processes
  • Loading branch information
Atry authored Nov 23, 2021
1 parent 449ff79 commit 16ed31b
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 46 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
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

0 comments on commit 16ed31b

Please sign in to comment.