diff --git a/zulia-server/src/dist/config/zulia.yaml b/zulia-server/src/dist/config/zulia.yaml index 8e917e2a..c613b5fd 100644 --- a/zulia-server/src/dist/config/zulia.yaml +++ b/zulia-server/src/dist/config/zulia.yaml @@ -25,6 +25,9 @@ mongoServers: - hostname: 127.0.0.1 port: 27017 +# compress the services response to the client (grpc service port, not rest) +responseCompression: false + #mongoConnection: # protocol: "mongodb+srv" # connectionURL: example.com diff --git a/zulia-server/src/main/java/io/zulia/server/config/ZuliaConfig.java b/zulia-server/src/main/java/io/zulia/server/config/ZuliaConfig.java index f0269d35..567347b0 100644 --- a/zulia-server/src/main/java/io/zulia/server/config/ZuliaConfig.java +++ b/zulia-server/src/main/java/io/zulia/server/config/ZuliaConfig.java @@ -25,6 +25,8 @@ public class ZuliaConfig { private int servicePort = 32191; private int restPort = 32192; + private boolean responseCompression; + public ZuliaConfig() { } @@ -116,10 +118,19 @@ public void setRestPort(int restPort) { this.restPort = restPort; } + public boolean isResponseCompression() { + return responseCompression; + } + + public void setResponseCompression(boolean responseCompression) { + this.responseCompression = responseCompression; + } + @Override public String toString() { return "ZuliaConfig{" + "dataPath='" + dataPath + '\'' + ", cluster=" + cluster + ", clusterName='" + clusterName + '\'' + ", clusterStorageEngine='" - + clusterStorageEngine + '\'' + ", s3=" + s3 + ", mongoServers=" + mongoServers + ", mongoAuth=" + mongoAuth + ", serverAddress='" - + serverAddress + '\'' + ", servicePort=" + servicePort + ", restPort=" + restPort + '}'; + + clusterStorageEngine + '\'' + ", s3=" + s3 + ", mongoServers=" + mongoServers + ", mongoConnection=" + mongoConnection + ", mongoAuth=" + + mongoAuth + ", serverAddress='" + serverAddress + '\'' + ", servicePort=" + servicePort + ", restPort=" + restPort + ", responseCompression=" + + responseCompression + '}'; } } diff --git a/zulia-server/src/main/java/io/zulia/server/connection/server/ZuliaServiceServer.java b/zulia-server/src/main/java/io/zulia/server/connection/server/ZuliaServiceServer.java index 233808c3..f21fab5e 100644 --- a/zulia-server/src/main/java/io/zulia/server/connection/server/ZuliaServiceServer.java +++ b/zulia-server/src/main/java/io/zulia/server/connection/server/ZuliaServiceServer.java @@ -1,6 +1,10 @@ package io.zulia.server.connection.server; +import io.grpc.Metadata; import io.grpc.Server; +import io.grpc.ServerCall; +import io.grpc.ServerCallHandler; +import io.grpc.ServerInterceptor; import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder; import io.zulia.server.config.ZuliaConfig; import io.zulia.server.index.ZuliaIndexManager; @@ -15,6 +19,15 @@ */ public class ZuliaServiceServer { + public static class ResponseCompressionIntercept implements ServerInterceptor { + + @Override + public ServerCall.Listener interceptCall(ServerCall call, Metadata headers, ServerCallHandler next) { + call.setCompression("gzip"); + return next.startCall(call, headers); + } + } + private Server server; public ZuliaServiceServer(ZuliaConfig zuliaConfig, ZuliaIndexManager indexManager) { @@ -22,7 +35,13 @@ public ZuliaServiceServer(ZuliaConfig zuliaConfig, ZuliaIndexManager indexManage int externalServicePort = zuliaConfig.getServicePort(); ZuliaServiceHandler zuliaServiceHandler = new ZuliaServiceHandler(indexManager); - server = NettyServerBuilder.forPort(externalServicePort).addService(zuliaServiceHandler).maxInboundMessageSize(128 * 1024 * 1024).build(); + NettyServerBuilder nettyServerBuilder = NettyServerBuilder.forPort(externalServicePort).addService(zuliaServiceHandler) + .maxInboundMessageSize(128 * 1024 * 1024); + + if (zuliaConfig.isResponseCompression()) { + nettyServerBuilder = nettyServerBuilder.intercept(new ResponseCompressionIntercept()); + } + server = nettyServerBuilder.build(); } public void start() throws IOException { diff --git a/zulia-server/src/test/java/io/zulia/server/test/node/shared/TestHelper.java b/zulia-server/src/test/java/io/zulia/server/test/node/shared/TestHelper.java index 3d6c7006..bbcc7992 100644 --- a/zulia-server/src/test/java/io/zulia/server/test/node/shared/TestHelper.java +++ b/zulia-server/src/test/java/io/zulia/server/test/node/shared/TestHelper.java @@ -122,6 +122,7 @@ public static void startNodes() throws Exception { zuliaConfig.setServerAddress("localhost"); zuliaConfig.setCluster(true); zuliaConfig.setClusterName(TEST_CLUSTER_NAME); + zuliaConfig.setResponseCompression(true); String mongoServerUrl = getMongoServer(); zuliaConfig.setMongoServers(Collections.singletonList(new MongoServer(mongoServerUrl, parseMongoPort(mongoServerUrl))));