Skip to content

Commit

Permalink
enable turning on service response compression via config
Browse files Browse the repository at this point in the history
  • Loading branch information
mdavis95 committed May 25, 2023
1 parent a550c8b commit 06a635a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
3 changes: 3 additions & 0 deletions zulia-server/src/dist/config/zulia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions zulia-server/src/main/java/io/zulia/server/config/ZuliaConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class ZuliaConfig {
private int servicePort = 32191;
private int restPort = 32192;

private boolean responseCompression;

public ZuliaConfig() {
}

Expand Down Expand Up @@ -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 + '}';
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,14 +19,29 @@
*/
public class ZuliaServiceServer {

public static class ResponseCompressionIntercept implements ServerInterceptor {

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
call.setCompression("gzip");
return next.startCall(call, headers);
}
}

private Server server;

public ZuliaServiceServer(ZuliaConfig zuliaConfig, ZuliaIndexManager indexManager) {

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand Down

0 comments on commit 06a635a

Please sign in to comment.