Skip to content

Commit

Permalink
KQueue support added. #1215
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita committed Jan 5, 2018
1 parent 1beed1d commit 7c668a0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 11 deletions.
7 changes: 7 additions & 0 deletions redisson/pom.xml
Expand Up @@ -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>
Expand Down
36 changes: 26 additions & 10 deletions redisson/src/main/java/org/redisson/config/Config.java
Expand Up @@ -78,7 +78,7 @@ public class Config {
*/
private boolean referenceEnabled = true;

private boolean useLinuxNativeEpoll;
private TransportMode transportMode = TransportMode.NIO;

private EventLoopGroup eventLoopGroup;

Expand Down Expand Up @@ -106,6 +106,8 @@ public Config(Config oldConf) {
setReferenceCodecProvider(oldConf.getReferenceCodecProvider());
setReferenceEnabled(oldConf.isReferenceEnabled());
setEventLoopGroup(oldConf.getEventLoopGroup());
setTransportMode(oldConf.getTransportMode());

if (oldConf.getSingleServerConfig() != null) {
setSingleServerConfig(new SingleServerConfig(oldConf.getSingleServerConfig()));
}
Expand Down Expand Up @@ -455,23 +457,36 @@ private void checkReplicatedServersConfig() {
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;
}

/**
Expand Down Expand Up @@ -515,12 +530,13 @@ public ExecutorService getExecutor() {

/**
* 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.
Expand Down
41 changes: 41 additions & 0 deletions redisson/src/main/java/org/redisson/config/TransportMode.java
@@ -0,0 +1,41 @@
/**
* 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,

}
Expand Up @@ -50,6 +50,7 @@
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;
Expand All @@ -63,6 +64,9 @@
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;
Expand Down Expand Up @@ -175,7 +179,7 @@ public MasterSlaveConnectionManager(MasterSlaveServersConfig cfg, Config config)
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 {
Expand All @@ -184,6 +188,15 @@ public MasterSlaveConnectionManager(Config cfg) {

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"));
Expand Down

0 comments on commit 7c668a0

Please sign in to comment.