Elffuss BraidHub

kikocis/java-driver public

JAVA-1275: Use Netty's default thread factory (#734)

This makes all of our threads instances of Netty's
FastThreadLocalThread, which allows an optimization of ThreadLocal
variables.
Changeset8ed9f031ec202d9b3493d86d4ebbd3e0d4e4abbe633d225d3e9ead3b7e018b38
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2016-09-12 13:57 -07:00
CommitterGitHub <noreply@github.com> · 2016-09-12 13:57 -07:00
Parents06afebc26b36

Browse the files at this changeset

3 files changed

modified changelog/README.md +1 −0
@@ -7,6 +7,7 @@
77 - [bug] JAVA-1258: Regression: Mapper cannot map a materialized view after JAVA-1126.
88 - [bug] JAVA-1101: Batch and BatchStatement should consider inner statements to determine query idempotence
99 - [improvement] JAVA-1262: Use ParseUtils for quoting & unquoting.
10+- [improvement] JAVA-1275: Use Netty's default thread factory
1011
1112
1213 ### 3.0.3
modified driver-core/src/main/java/com/datastax/driver/core/Cluster.java +9 −1
@@ -25,6 +25,7 @@
2525 import com.google.common.base.Throwables;
2626 import com.google.common.collect.*;
2727 import com.google.common.util.concurrent.*;
28+import io.netty.util.concurrent.DefaultThreadFactory;
2829 import org.slf4j.Logger;
2930 import org.slf4j.LoggerFactory;
3031
@@ -1515,7 +1516,14 @@
15151516 }
15161517
15171518 ThreadFactory threadFactory(String name) {
1518- return new ThreadFactoryBuilder().setNameFormat(clusterName + "-" + name + "-%d").build();
1519+ return new ThreadFactoryBuilder()
1520+ .setNameFormat(clusterName + "-" + name + "-%d")
1521+ // Back with Netty's thread factory in order to create FastThreadLocalThread instances. This allows
1522+ // an optimization around ThreadLocals (we could use DefaultThreadFactory directly but it creates
1523+ // slightly different thread names, so keep we keep a ThreadFactoryBuilder wrapper for backward
1524+ // compatibility).
1525+ .setThreadFactory(new DefaultThreadFactory("ignored name"))
1526+ .build();
15191527 }
15201528
15211529 private ListeningExecutorService makeExecutor(int threads, String name, LinkedBlockingQueue<Runnable> workQueue) {
modified driver-core/src/main/java/com/datastax/driver/core/NettyOptions.java +8 −2
@@ -89,7 +89,10 @@
8989 *
9090 * @param threadFactory The {@link ThreadFactory} to use when creating a new {@code EventLoopGroup} instance;
9191 * The driver will provide its own internal thread factory here.
92- * It is safe to ignore it and use another thread factory.
92+ * It is safe to ignore it and use another thread factory. Note however that for optimal
93+ * performance it is recommended to use a factory that returns
94+ * {@link io.netty.util.concurrent.FastThreadLocalThread} instances (such as Netty's
95+ * {@link java.util.concurrent.Executors.DefaultThreadFactory}).
9396 * @return the {@code EventLoopGroup} instance to use.
9497 */
9598 public EventLoopGroup eventLoopGroup(ThreadFactory threadFactory) {
@@ -205,7 +208,10 @@
205208 *
206209 * @param threadFactory The {@link ThreadFactory} to use when creating a new {@link HashedWheelTimer} instance;
207210 * The driver will provide its own internal thread factory here.
208- * It is safe to ignore it and use another thread factory.
211+ * It is safe to ignore it and use another thread factory. Note however that for optimal
212+ * performance it is recommended to use a factory that returns
213+ * {@link io.netty.util.concurrent.FastThreadLocalThread} instances (such as Netty's
214+ * {@link java.util.concurrent.Executors.DefaultThreadFactory}).
209215 * @return the {@link Timer} instance to use.
210216 */
211217 public Timer timer(ThreadFactory threadFactory) {