Skip to content

Commit

Permalink
[SPARK-17314][CORE] Use Netty's DefaultThreadFactory to enable its fa…
Browse files Browse the repository at this point in the history
…st ThreadLocal impl

## What changes were proposed in this pull request?

When a thread is a Netty's FastThreadLocalThread, Netty will use its fast ThreadLocal implementation. It has a better performance than JDK's (See the benchmark results in netty/netty#4417, note: it's not a fix to Netty's FastThreadLocal. It just fixed an issue in Netty's benchmark codes)

This PR just changed the ThreadFactory to Netty's DefaultThreadFactory which will use FastThreadLocalThread. There is also a minor change to the thread names. See https://github.com/netty/netty/blob/netty-4.0.22.Final/common/src/main/java/io/netty/util/concurrent/DefaultThreadFactory.java#L94

## How was this patch tested?

Author: Shixiong Zhu <shixiong@databricks.com>

Closes #14879 from zsxwing/netty-thread.
  • Loading branch information
zsxwing committed Aug 30, 2016
1 parent fb20084 commit 02ac379
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.lang.reflect.Field;
import java.util.concurrent.ThreadFactory;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
Expand All @@ -31,6 +30,7 @@
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.util.concurrent.DefaultThreadFactory;
import io.netty.util.internal.PlatformDependent;

/**
Expand All @@ -39,10 +39,7 @@
public class NettyUtils {
/** Creates a new ThreadFactory which prefixes each thread with the given name. */
public static ThreadFactory createThreadFactory(String threadPoolPrefix) {
return new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat(threadPoolPrefix + "-%d")
.build();
return new DefaultThreadFactory(threadPoolPrefix, true);
}

/** Creates a Netty EventLoopGroup based on the IOMode. */
Expand Down

0 comments on commit 02ac379

Please sign in to comment.