aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/server
diff options
context:
space:
mode:
authorGravatar Michajlo Matijkiw <michajlo@google.com>2016-11-02 17:45:31 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2016-11-03 07:17:00 +0000
commitf7a5769187a11d4d15ed685abf55338eaeafdc12 (patch)
tree41f8322e880091dd6f2619fa7a42f8b6d96b374d /src/main/java/com/google/devtools/build/lib/server
parentd0761e6a641a33ca9e4ec8bf3f5c92f74a4c3c86 (diff)
Store and use commandId and cookie as ByteStrings
We wind up doing String -> UTF8 bytes conversion for every message serialized (this happens in protocol buffer land). Do the conversion once and reuse the immutable value instead of doing it for every chunk of output written. Keep this optimization local to RpcOutputStream where we see a lot of repitition - using ByteStrings in place of Strings can get confusing when it comes to logging, so only apply this optimization where it could count. -- MOS_MIGRATED_REVID=137964305
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/server')
-rw-r--r--src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java
index 03af9d78a6..0c8791990e 100644
--- a/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java
+++ b/src/main/java/com/google/devtools/build/lib/server/GrpcServerImpl.java
@@ -384,14 +384,17 @@ public class GrpcServerImpl implements RPCServer {
static class RpcOutputStream extends OutputStream {
private static final int CHUNK_SIZE = 8192;
- private final String commandId;
- private final String responseCookie;
+ // Store commandId and responseCookie as ByteStrings to avoid String -> UTF8 bytes conversion
+ // for each serialized chunk of output.
+ private final ByteString commandIdBytes;
+ private final ByteString responseCookieBytes;
+
private final StreamType type;
private final GrpcSink sink;
RpcOutputStream(String commandId, String responseCookie, StreamType type, GrpcSink sink) {
- this.commandId = commandId;
- this.responseCookie = responseCookie;
+ this.commandIdBytes = ByteString.copyFromUtf8(commandId);
+ this.responseCookieBytes = ByteString.copyFromUtf8(responseCookie);
this.type = type;
this.sink = sink;
}
@@ -402,8 +405,8 @@ public class GrpcServerImpl implements RPCServer {
ByteString input = ByteString.copyFrom(b, off + i, Math.min(CHUNK_SIZE, inlen - i));
RunResponse.Builder response = RunResponse
.newBuilder()
- .setCookie(responseCookie)
- .setCommandId(commandId);
+ .setCookieBytes(responseCookieBytes)
+ .setCommandIdBytes(commandIdBytes);
switch (type) {
case STDOUT: response.setStandardOutput(input); break;
@@ -421,7 +424,7 @@ public class GrpcServerImpl implements RPCServer {
log.info(
String.format(
"Client disconnected received for command %s on thread %s",
- commandId, Thread.currentThread().getName()));
+ commandIdBytes.toStringUtf8(), Thread.currentThread().getName()));
throw new IOException("Client disconnected");
}
}