Browse Source

Epoll support added. #145

master
Nikita 11 years ago
parent
commit
6db9b38d74
  1. 5
      pom.xml
  2. 9
      src/main/java/com/corundumstudio/socketio/Configuration.java
  3. 15
      src/main/java/com/corundumstudio/socketio/SocketIOServer.java

5
pom.xml

@ -125,6 +125,11 @@
<artifactId>netty-codec</artifactId> <artifactId>netty-codec</artifactId>
<version>4.0.23.Final</version> <version>4.0.23.Final</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-transport-native-epoll</artifactId>
<version>4.0.23.Final</version>
</dependency>
<dependency> <dependency>
<groupId>com.googlecode.jmockit</groupId> <groupId>com.googlecode.jmockit</groupId>

9
src/main/java/com/corundumstudio/socketio/Configuration.java

@ -37,6 +37,7 @@ public class Configuration {
private int bossThreads = 0; // 0 = current_processors_amount * 2 private int bossThreads = 0; // 0 = current_processors_amount * 2
private int workerThreads = 0; // 0 = current_processors_amount * 2 private int workerThreads = 0; // 0 = current_processors_amount * 2
private boolean useLinuxNativeEpoll;
private boolean allowCustomRequests = false; private boolean allowCustomRequests = false;
@ -86,6 +87,7 @@ public class Configuration {
Configuration(Configuration conf) { Configuration(Configuration conf) {
setBossThreads(conf.getBossThreads()); setBossThreads(conf.getBossThreads());
setWorkerThreads(conf.getWorkerThreads()); setWorkerThreads(conf.getWorkerThreads());
setUseLinuxNativeEpoll(conf.isUseLinuxNativeEpoll());
setPingInterval(conf.getPingInterval()); setPingInterval(conf.getPingInterval());
setPingTimeout(conf.getPingTimeout()); setPingTimeout(conf.getPingTimeout());
@ -472,4 +474,11 @@ public class Configuration {
return origin; return origin;
} }
public boolean isUseLinuxNativeEpoll() {
return useLinuxNativeEpoll;
}
public void setUseLinuxNativeEpoll(boolean useLinuxNativeEpoll) {
this.useLinuxNativeEpoll = useLinuxNativeEpoll;
}
} }

15
src/main/java/com/corundumstudio/socketio/SocketIOServer.java

@ -19,6 +19,8 @@ import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.FixedRecvByteBufAllocator; import io.netty.channel.FixedRecvByteBufAllocator;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Future;
@ -128,9 +130,15 @@ public class SocketIOServer implements ClientListeners {
initGroups(); initGroups();
pipelineFactory.start(configCopy, namespacesHub); pipelineFactory.start(configCopy, namespacesHub);
Class channelClass = NioServerSocketChannel.class;
if (configCopy.isUseLinuxNativeEpoll()) {
channelClass = EpollServerSocketChannel.class;
}
ServerBootstrap b = new ServerBootstrap(); ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup) b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.channel(channelClass)
.childHandler(pipelineFactory); .childHandler(pipelineFactory);
applyConnectionOptions(b); applyConnectionOptions(b);
@ -169,9 +177,14 @@ public class SocketIOServer implements ClientListeners {
} }
protected void initGroups() { protected void initGroups() {
if (configCopy.isUseLinuxNativeEpoll()) {
bossGroup = new EpollEventLoopGroup(configCopy.getBossThreads());
workerGroup = new EpollEventLoopGroup(configCopy.getWorkerThreads());
} else {
bossGroup = new NioEventLoopGroup(configCopy.getBossThreads()); bossGroup = new NioEventLoopGroup(configCopy.getBossThreads());
workerGroup = new NioEventLoopGroup(configCopy.getWorkerThreads()); workerGroup = new NioEventLoopGroup(configCopy.getWorkerThreads());
} }
}
/** /**
* Stop server * Stop server

Loading…
Cancel
Save