grpc / grpc/grpc-java

channel warm up per thread

Aperta
#1,758 23 commenti 1 reazione 0 assegnatari Vedi su GitHub
performance
Lingua principale
Java
Stelle
12.1k
Fork
4k
Merge medio
2g 17h
PR unite (30g)
37

Descrizione

Hi, all. I'm doing an experiment with grpc and find out that the first usage of grpc in a thread costs much more time than the subsequent ones doing the same thing. I tested it on a 2-core laptop and 24-core machines, and the same phenomena occurred on all of them. So I'm wondering if I'm using grpc wrong or something in grpc-java could be improved to avoid such situation. Below is my code and part of the report.

```
import java.text.SimpleDateFormat;
import java.util.Date;

import me.gdbc.mocker.MockServer;
import me.proto.query.QueryProtocol.QueryRequest;
import me.proto.query.QueryProtocol.QueryResponse;

import me.proto.query.QueryServiceInterfaceGrpc.METHOD_QUERY;

import io.grpc.CallOptions;
import io.grpc.ManagedChannel;
import io.grpc.netty.NettyChannelBuilder;

public class WarmUp {

public static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

public static QueryRequest request = QueryRequest.newBuilder().setQueryString("").build();
public static class QueryThread extends Thread {

private String name;
private ManagedChannel client;

public QueryThread(String name, ManagedChannel client) {
this.name = name;
this.client = client;
}

public void run() {
for (int i = 0 ; i < 300; i++) {
long start = System.currentTimeMillis();
try {
//ClientCall call = client.newCall(METHOD_QUERY, CallOptions.DEFAULT);
QueryResponse ret = io.grpc.stub.ClientCalls.blockingUnaryCall(client, METHOD_QUERY, CallOptions.DEFAULT, request);
//QueryResponse ret = io.grpc.stub.ClientCalls.blockingUnaryCall(call, request);
long duration = System.currentTimeMillis() - start;
String show = "" + ret + "\n" + df.format(new Date()) + "\n" + "cost " + duration + "ms in thread " + name;
System.out.println(show);
} catch (Exception e) {
e.printStackTrace();
}
}

}
}

public static void main(String[] args) {
int port = 9012;
MockServer server = new MockServer(port);
try {
server.start();
ManagedChannel channel = NettyChannelBuilder.forAddress("127.0.0.1", port).usePlaintext(true).build();
io.grpc.stub.ClientCalls.blockingUnaryCall(channel, METHOD_QUERY, CallOptions.DEFAULT, request);
for (int i = 0; i < 4; i++) {
QueryThread th = new QueryThread(String.valueOf(i), channel);
th.start();

}

} catch (Exception e) {
e.printStackTrace();
}
}

}
```

```
May 01, 2016 2:28:09 PM me.gdbc.mocker.MockServer start
INFO: Server started, listenning on 9012
May 01, 2016 2:28:09 PM io.grpc.internal.ManagedChannelImpl
INFO: [ManagedChannelImpl@326de728] Created with target 127.0.0.1:9012
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 76ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 67ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 68ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 66ms in thread 2
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 8ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 8ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 10ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 10ms in thread 2
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 8ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 10ms in thread 2
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 4ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 6ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 7ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 6ms in thread 3
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 6ms in thread 1
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 6ms in thread 0
result {
props {
intVal: 1
}
}

2016-05-01 14:28:10
cost 6ms in thread 3
result {
props {
intVal: 1
}
}
```

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by running the supplied WarmUp example with NettyChannelBuilder, ManagedChannel, and ClientCalls.blockingUnaryCall, then inspect the channel and call paths involved in the first request on each thread. Done means the per-thread latency behavior is explained and any improvement is covered by a reproducible regression check.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
backend-api-design, networking, performance
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
32/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.