Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions hbase-common/src/main/java/org/apache/hadoop/hbase/util/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ public class JVM {

private static final boolean ibmvendor =
System.getProperty("java.vendor") != null && System.getProperty("java.vendor").contains("IBM");
private static final boolean windows =
System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Windows");
private static final boolean linux =
System.getProperty("os.name") != null && System.getProperty("os.name").startsWith("Linux");
// At least on my systems os.name reports as "linux", not "Linux". Prefer case insensitive tests.
private static final boolean windows = System.getProperty("os.name") != null
&& System.getProperty("os.name").toLowerCase().contains("windows");
private static final boolean linux = System.getProperty("os.name") != null
&& System.getProperty("os.name").toLowerCase().contains("linux");
private static final boolean amd64 =
System.getProperty("os.arch") != null && System.getProperty("os.arch").contains("amd64");
private static final boolean aarch64 =
System.getProperty("os.arch") != null && System.getProperty("os.arch").contains("aarch64");

private static final String JVMVersion = System.getProperty("java.version");

Expand Down Expand Up @@ -99,6 +102,14 @@ public static boolean isAmd64() {
return amd64;
}

/**
* Check if the arch is aarch64;
* @return whether this is aarch64 or not.
*/
public static boolean isAarch64() {
return aarch64;
}

/**
* Check if the finish() method of GZIPOutputStream is broken
* @return whether GZIPOutputStream.finish() is broken.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
import org.apache.hadoop.hbase.HBaseServerBase;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.regionserver.HRegionServer;
import org.apache.hadoop.hbase.security.HBasePolicyProvider;
import org.apache.hadoop.hbase.util.NettyEventLoopGroupConfig;
import org.apache.hadoop.hbase.util.ReflectionUtils;
Expand All @@ -47,10 +46,7 @@
import org.apache.hbase.thirdparty.io.netty.channel.ServerChannel;
import org.apache.hbase.thirdparty.io.netty.channel.group.ChannelGroup;
import org.apache.hbase.thirdparty.io.netty.channel.group.DefaultChannelGroup;
import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioServerSocketChannel;
import org.apache.hbase.thirdparty.io.netty.handler.codec.FixedLengthFrameDecoder;
import org.apache.hbase.thirdparty.io.netty.util.concurrent.DefaultThreadFactory;
import org.apache.hbase.thirdparty.io.netty.util.concurrent.GlobalEventExecutor;

/**
Expand All @@ -61,14 +57,6 @@
public class NettyRpcServer extends RpcServer {
public static final Logger LOG = LoggerFactory.getLogger(NettyRpcServer.class);

/**
* Name of property to change netty rpc server eventloop thread count. Default is 0. Tests may set
* this down from unlimited.
*/
public static final String HBASE_NETTY_EVENTLOOP_RPCSERVER_THREADCOUNT_KEY =
"hbase.netty.eventloop.rpcserver.thread.count";
private static final int EVENTLOOP_THREADCOUNT_DEFAULT = 0;

/**
* Name of property to change the byte buf allocator for the netty channels. Default is no value,
* which causes us to use PooledByteBufAllocator. Valid settings here are "pooled", "unpooled",
Expand Down Expand Up @@ -97,21 +85,16 @@ public NettyRpcServer(Server server, String name, List<BlockingServiceAndInterfa
super(server, name, services, bindAddress, conf, scheduler, reservoirEnabled);
this.bindAddress = bindAddress;
this.channelAllocator = getChannelAllocator(conf);
EventLoopGroup eventLoopGroup;
Class<? extends ServerChannel> channelClass;
if (server instanceof HRegionServer) {
NettyEventLoopGroupConfig config = ((HBaseServerBase) server).getEventLoopGroupConfig();
eventLoopGroup = config.group();
channelClass = config.serverChannelClass();
} else {
int threadCount = server == null
? EVENTLOOP_THREADCOUNT_DEFAULT
: server.getConfiguration().getInt(HBASE_NETTY_EVENTLOOP_RPCSERVER_THREADCOUNT_KEY,
EVENTLOOP_THREADCOUNT_DEFAULT);
eventLoopGroup = new NioEventLoopGroup(threadCount,
new DefaultThreadFactory("NettyRpcServer", true, Thread.MAX_PRIORITY));
channelClass = NioServerSocketChannel.class;
// Get the event loop group configuration from the server class if available.
NettyEventLoopGroupConfig config = null;
if (server instanceof HBaseServerBase) {
config = ((HBaseServerBase) server).getEventLoopGroupConfig();
}
if (config == null) {
config = new NettyEventLoopGroupConfig(conf, "NettyRpcServer");
}
EventLoopGroup eventLoopGroup = config.group();
Class<? extends ServerChannel> channelClass = config.serverChannelClass();
ServerBootstrap bootstrap = new ServerBootstrap().group(eventLoopGroup).channel(channelClass)
.childOption(ChannelOption.TCP_NODELAY, tcpNoDelay)
.childOption(ChannelOption.SO_KEEPALIVE, tcpKeepAlive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@
*/
@InterfaceAudience.Private
public class NettyEventLoopGroupConfig {

public static final String NETTY_WORKER_COUNT_KEY = "hbase.netty.worker.count";
public static final int DEFAULT_NETTY_WORKER_COUNT = 0;

public static final String NETTY_NATIVETRANSPORT_KEY = "hbase.netty.nativetransport";
public static final boolean DEFAULT_NETTY_NATIVETRANSPORT = true;

private final EventLoopGroup group;

private final Class<? extends ServerChannel> serverChannelClass;
Expand All @@ -47,14 +54,21 @@ public class NettyEventLoopGroupConfig {

private static boolean useEpoll(Configuration conf) {
// Config to enable native transport.
boolean epollEnabled = conf.getBoolean("hbase.netty.nativetransport", true);
// Use the faster native epoll transport mechanism on linux if enabled
return epollEnabled && JVM.isLinux() && JVM.isAmd64();
final boolean epollEnabled =
conf.getBoolean(NETTY_NATIVETRANSPORT_KEY, DEFAULT_NETTY_NATIVETRANSPORT);
// Use the faster native epoll transport mechanism on linux if enabled and the
// hardware architecture is either amd64 or aarch64. Netty is known to have native
// epoll support for these combinations.
return epollEnabled && JVM.isLinux() && (JVM.isAmd64() || JVM.isAarch64());
}

public NettyEventLoopGroupConfig(Configuration conf, String threadPoolName) {
boolean useEpoll = useEpoll(conf);
int workerCount = conf.getInt("hbase.netty.worker.count", 0);
final boolean useEpoll = useEpoll(conf);
final int workerCount = conf.getInt(NETTY_WORKER_COUNT_KEY,
// For backwards compatibility we also need to consider
// "hbase.netty.eventloop.rpcserver.thread.count"
// if it is defined in site configuration instead.
conf.getInt("hbase.netty.eventloop.rpcserver.thread.count", DEFAULT_NETTY_WORKER_COUNT));
ThreadFactory eventLoopThreadFactory =
new DefaultThreadFactory(threadPoolName, true, Thread.MAX_PRIORITY);
if (useEpoll) {
Expand Down
5 changes: 0 additions & 5 deletions hbase-server/src/test/resources/hbase-site.xml
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,4 @@
<value>3</value>
<description>Default is unbounded</description>
</property>
<property>
<name>hbase.netty.eventloop.rpcserver.thread.count</name>
<value>3</value>
<description>Default is unbounded</description>
</property>
</configuration>