grpc / grpc/grpc-java

Use FastThreadLocalThread's in shared channel executor.

Ouverte
#1,555 6 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
performance
Langage dominant
Java
Étoiles
12.1k
Forks
4k
Merge moyen
2 j 17 h
PR mergées (30 j)
37

Description

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?

Guide de contribution

Ouvrir le guide de contribution

Piste de recherche

Commencez par l’exécuteur de canal partagé et son pool de threads mis en cache, puis suivez la manière dont les threads de l’exécuteur sont créés pour le transport Java. Implémentez le comportement demandé de création et de nettoyage de FastThreadLocalThread, tout en vérifiant si l’exécuteur partagé peut rester compatible avec Android ; le travail est terminé lorsque les caches thread-local de l’allocator sont libérés à l’arrêt des threads du pool.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
backend, performance
Type d'issue
Refactorisation
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.