提交 7c668a06 编写于 作者: N Nikita

KQueue support added. #1215

上级 1beed1dd
......@@ -31,12 +31,19 @@
</profiles>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-kqueue</artifactId>
<version>4.1.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>4.1.19.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
......
......@@ -78,7 +78,7 @@ public class Config {
*/
private boolean referenceEnabled = true;
private boolean useLinuxNativeEpoll;
private TransportMode transportMode = TransportMode.NIO;
private EventLoopGroup eventLoopGroup;
......@@ -106,6 +106,8 @@ public class Config {
setReferenceCodecProvider(oldConf.getReferenceCodecProvider());
setReferenceEnabled(oldConf.isReferenceEnabled());
setEventLoopGroup(oldConf.getEventLoopGroup());
setTransportMode(oldConf.getTransportMode());
if (oldConf.getSingleServerConfig() != null) {
setSingleServerConfig(new SingleServerConfig(oldConf.getSingleServerConfig()));
}
......@@ -455,23 +457,36 @@ public class Config {
throw new IllegalStateException("Replication servers config already used!");
}
}
/**
* Activates an unix socket if servers binded to loopback interface.
* Also used for epoll transport activation.
* <b>netty-transport-native-epoll</b> library should be in classpath
* Transport mode
* <p>
* Default is {@link TransportMode#NIO}
*
* @param useLinuxNativeEpoll flag
* @param transportMode param
* @return config
*/
public Config setTransportMode(TransportMode transportMode) {
this.transportMode = transportMode;
return this;
}
public TransportMode getTransportMode() {
return transportMode;
}
/**
* Use {@link #setTransportMode(TransportMode)}
*/
@Deprecated
public Config setUseLinuxNativeEpoll(boolean useLinuxNativeEpoll) {
this.useLinuxNativeEpoll = useLinuxNativeEpoll;
if (useLinuxNativeEpoll) {
setTransportMode(TransportMode.EPOLL);
}
return this;
}
public boolean isUseLinuxNativeEpoll() {
return useLinuxNativeEpoll;
return getTransportMode() == TransportMode.EPOLL;
}
/**
......@@ -515,12 +530,13 @@ public class Config {
/**
* Use external EventLoopGroup. EventLoopGroup processes all
* Netty connection tied with Redis servers. Each EventLoopGroup creates
* Netty connection tied to Redis servers. Each EventLoopGroup creates
* own threads and each Redisson client creates own EventLoopGroup by default.
* So if there are multiple Redisson instances in same JVM
* it would be useful to share one EventLoopGroup among them.
* <p>
* Only {@link io.netty.channel.epoll.EpollEventLoopGroup} or
* Only {@link io.netty.channel.epoll.EpollEventLoopGroup},
* {@link io.netty.channel.kqueue.KQueueEventLoopGroup}
* {@link io.netty.channel.nio.NioEventLoopGroup} can be used.
* <p>
* The caller is responsible for closing the EventLoopGroup.
......
/**
* Copyright 2016 Nikita Koksharov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.redisson.config;
/**
*
* @author Nikita Koksharov
*
*/
public enum TransportMode {
/**
* Use NIO transport.
*/
NIO,
/**
* Use EPOLL transport. Activates an unix socket if servers binded to loopback interface.
* Requires <b>netty-transport-native-epoll</b> lib in classpath.
*/
EPOLL,
/**
* Use KQUEUE transport. Requires <b>netty-transport-native-kqueue</b> lib in classpath.
*/
KQUEUE,
}
......@@ -50,6 +50,7 @@ import org.redisson.command.CommandSyncService;
import org.redisson.config.BaseMasterSlaveServersConfig;
import org.redisson.config.Config;
import org.redisson.config.MasterSlaveServersConfig;
import org.redisson.config.TransportMode;
import org.redisson.misc.InfinitySemaphoreLatch;
import org.redisson.misc.RPromise;
import org.redisson.misc.RedissonPromise;
......@@ -63,6 +64,9 @@ import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollDatagramChannel;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollSocketChannel;
import io.netty.channel.kqueue.KQueueDatagramChannel;
import io.netty.channel.kqueue.KQueueEventLoopGroup;
import io.netty.channel.kqueue.KQueueSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioDatagramChannel;
......@@ -175,7 +179,7 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
public MasterSlaveConnectionManager(Config cfg) {
Version.logVersion();
if (cfg.isUseLinuxNativeEpoll()) {
if (cfg.getTransportMode() == TransportMode.EPOLL) {
if (cfg.getEventLoopGroup() == null) {
this.group = new EpollEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
} else {
......@@ -184,6 +188,15 @@ public class MasterSlaveConnectionManager implements ConnectionManager {
this.socketChannelClass = EpollSocketChannel.class;
this.resolverGroup = new DnsAddressResolverGroup(EpollDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
} else if (cfg.getTransportMode() == TransportMode.KQUEUE) {
if (cfg.getEventLoopGroup() == null) {
this.group = new KQueueEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
} else {
this.group = cfg.getEventLoopGroup();
}
this.socketChannelClass = KQueueSocketChannel.class;
this.resolverGroup = new DnsAddressResolverGroup(KQueueDatagramChannel.class, DnsServerAddressStreamProviders.platformDefault());
} else {
if (cfg.getEventLoopGroup() == null) {
this.group = new NioEventLoopGroup(cfg.getNettyThreads(), new DefaultThreadFactory("redisson-netty"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册