grpc / grpc/grpc-java

Use FastThreadLocalThread's in shared channel executor.

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

Descrizione

While working on https://github.com/netty/netty/commit/b88a980482d2aef1163a9abe759f68e685550052 I noticed that when using the blocking stub and the netty transport, we allocate in Netty's allocator from within the shared executor threads. Netty's allocator employs thread local caches that perform the majority of allocations. These caches are accessed via Netty's own threadlocal implementation `FastThreadLocal`, which is only "fast" when used in the context of a `FastThreadLocalThread`.

We should provide our own thread factory to the cached thread pool in order to create `FastThreadLocalThreads`. Additionally, we should override the Thread's `run()` method to do

```
public void run() {
try {
super.run();
} finally {
FastThreadLocal.removeAll();
}
}
```

This will release all memory from a thread's cache when it is shutdown. That should happen quite frequently, with the pool sizing threads dynamically.

However, I don't know how to best implement this. The shared channel executor should be shared by all transport, client, server combinations running in a JVM. Also, I assume we can't rely on the Netty dependency to be there on Android?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.