Do work in RPC call for getting file in its own thread
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.filedistribution;
+import com.yahoo.concurrent.DaemonThreadFactory;
import com.yahoo.config.FileReference;
import com.yahoo.jrt.DoubleArray;
import com.yahoo.jrt.Int32Value;
@@ -15,6 +16,8 @@ import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -30,6 +33,8 @@ public class FileDistributionRpcServer {
private final Supervisor supervisor;
private final FileDownloader downloader;
+ private final ExecutorService rpcDownloadExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(),
+ new DaemonThreadFactory("Rpc executor"));
public FileDistributionRpcServer(Supervisor supervisor, FileDownloader downloader) {
this.supervisor = supervisor;
@@ -74,6 +79,7 @@ public class FileDistributionRpcServer {
@SuppressWarnings({"UnusedDeclaration"})
public final void getFile(Request req) {
req.detach();
+ rpcDownloadExecutor.execute(() -> {
FileReference fileReference = new FileReference(req.parameters().get(0).asString());
log.log(LogLevel.DEBUG, "getFile() called for file reference '" + fileReference.value() + "'");
Optional<File> pathToFile = downloader.getFile(fileReference);
@@ -90,6 +96,7 @@ public class FileDistributionRpcServer {
req.setError(fileReferenceInternalError, "File reference '" + fileReference.value() + "' removed");
}
req.returnRequest();
+ });
}
@SuppressWarnings({"UnusedDeclaration"})
