I have been testing gRPC behaviour for larger message size on my machine. I
have got a single client to which I am streaming a video file of 603mb via
streaming gRPC. I ran into OOM while testing and found that in case of slow
clients, response messages were getting queued up and I was getting below
error msg:
io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216
byte(s) of direct memory (used: 1873805512, max: 1890582528)
Now this is fixable via flow control(using onReady() channel handler) but
out of curiosity I increased my direct memory to 4GB
via -XX:MaxDirectMemorySize=4g jvm flag to force queuing up of all
response messages and hence the client can consume on it's own pace. It got
completed successfully. But I observed that I ended up using 2.4GB of
direct memory. I checked it via usedDirectMemory() eposed by netty
for ByteBufAllocatorMetric.
*Isn't this too much for a 603mb file as it is 3 times more than the total
file size*. Below is the code snippet that I am using:
stream = new FileInputStream(file);
byte[] buffer = new byte[1024];
ByteBufAllocator byteBufAllocator = ByteBufAllocator.DEFAULT;
int length;
while ((length = stream.read(buffer)) > 0) {
response.onNext(VideoResponse.newBuilder().setVideoBytes(ByteString.
copyFrom(buffer)).build());
if (ByteBufAllocator.DEFAULT instanceof ByteBufAllocatorMetricProvider) {
ByteBufAllocatorMetric metric = ((ByteBufAllocatorMetricProvider)
byteBufAllocator).metric();
System.out.println(metric.usedDirectMemory()/(1024*1024));
}
}
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/ddd95e29-143b-4a0f-a6d7-b1dac7aa28b1%40googlegroups.com.