-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Support multiplex workers in ResourceProcessorBusyBox #14428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Bencodes
wants to merge
1
commit into
bazelbuild:master
from
Bencodes:support-multiplex-workers-in-resourceprocessorbusybox
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ | |
|
|
||
| import com.google.devtools.build.android.aapt2.Aapt2Exception; | ||
| import com.google.devtools.build.android.resources.JavaIdentifierValidator.InvalidJavaIdentifier; | ||
| import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest; | ||
| import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse; | ||
| import com.google.devtools.build.lib.worker.ProtoWorkerMessageProcessor; | ||
| import com.google.devtools.build.lib.worker.WorkRequestHandler; | ||
| import com.google.devtools.common.options.EnumConverter; | ||
| import com.google.devtools.common.options.Option; | ||
| import com.google.devtools.common.options.OptionDocumentationCategory; | ||
|
|
@@ -26,11 +26,14 @@ | |
| import com.google.devtools.common.options.OptionsParser; | ||
| import com.google.devtools.common.options.OptionsParsingException; | ||
| import com.google.devtools.common.options.ShellQuotedParamsFilePreProcessor; | ||
|
|
||
| import java.io.ByteArrayOutputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.PrintStream; | ||
| import java.io.PrintWriter; | ||
| import java.nio.file.FileSystems; | ||
| import java.time.Duration; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Properties; | ||
|
|
@@ -183,43 +186,56 @@ private static int runPersistentWorker() throws Exception { | |
| PrintStream ps = new PrintStream(buf, true); | ||
| PrintStream realStdOut = System.out; | ||
| PrintStream realStdErr = System.err; | ||
| try { | ||
| // Redirect all stdout and stderr output for logging. | ||
| System.setOut(ps); | ||
| System.setErr(ps); | ||
|
|
||
| while (true) { | ||
| try { | ||
| WorkRequest request = WorkRequest.parseDelimitedFrom(System.in); | ||
| if (request == null) { | ||
| break; | ||
| } | ||
|
|
||
| int exitCode = processRequest(request.getArgumentsList()); | ||
| ps.flush(); | ||
|
|
||
| WorkResponse.newBuilder() | ||
| .setExitCode(exitCode) | ||
| .setRequestId(request.getRequestId()) | ||
| .setOutput(buf.toString()) | ||
| .build() | ||
| .writeDelimitedTo(realStdOut); | ||
|
|
||
| realStdOut.flush(); | ||
| buf.reset(); | ||
| } catch (IOException e) { | ||
| logger.severe(e.getMessage()); | ||
| e.printStackTrace(realStdErr); | ||
| return 1; | ||
| } | ||
| } | ||
| // Redirect all stdout and stderr output for logging. | ||
| System.setOut(ps); | ||
| System.setErr(ps); | ||
| try { | ||
| WorkRequestHandler workerHandler = | ||
| new WorkRequestHandler.WorkRequestHandlerBuilder( | ||
| new WorkRequestHandler.WorkRequestCallback( | ||
| (request, pw) -> processRequest(request.getArgumentsList(), pw, buf)), | ||
| realStdErr, | ||
| new ProtoWorkerMessageProcessor(System.in, realStdOut)) | ||
| .setCpuUsageBeforeGc(Duration.ofSeconds(10)) | ||
| .build(); | ||
| workerHandler.processRequests(); | ||
| } catch (IOException e) { | ||
| logger.severe(e.getMessage()); | ||
| e.printStackTrace(realStdErr); | ||
| return 1; | ||
| } finally { | ||
| System.setOut(realStdOut); | ||
| System.setErr(realStdErr); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * Processes the request for the given args and writes the captured byte array buffer to the | ||
| * WorkRequestHandler print writer. | ||
| */ | ||
| private static int processRequest(List<String> args, PrintWriter pw, ByteArrayOutputStream buf) { | ||
| int exitCode; | ||
| try { | ||
| // Process the actual request and grab the exit code | ||
| exitCode = processRequest(args); | ||
larsrc-google marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } catch (Exception e) { | ||
| e.printStackTrace(pw); | ||
| exitCode = 1; | ||
| } finally { | ||
| // Write the captured buffer to the work response. We synchronize to avoid race conditions | ||
| // while reading from and calling reset on the shared ByteArrayOutputStream. | ||
| synchronized (buf) { | ||
| String captured = buf.toString().trim(); | ||
| buf.reset(); | ||
| pw.print(captured); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This preserves the previous logging behavior seen here https://github.com/bazelbuild/bazel/pull/14428/files#diff-6bbb0aaf4cf2d425734021815617e2b6203223abe7dc76ca8030a90e9f043873L204 |
||
| } | ||
| } | ||
|
|
||
| return exitCode; | ||
| } | ||
|
|
||
| private static int processRequest(List<String> args) throws Exception { | ||
| OptionsParser optionsParser = | ||
| OptionsParser.builder() | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this flag would override
--noexperimental_worker_multiplex?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing
--noexperimental_worker_multiplexwould disable multiplex workers entirely whileisPersistentMultiplexBusyboxToolsjust instructsBusyBoxActionBuilderto register it's actions with withsupports-multiplex-workerspecified as part of it's execution info.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'uh. You're right.