use of com.firenio.concurrent.ThreadEventLoopGroup in project baseio by generallycloud.
the class TestLoadClient1 method prepare.
@Override
public void prepare() throws Exception {
IoEventHandle eventHandleAdaptor = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame frame) {
addCount(80000);
if (debug) {
count.decrementAndGet();
}
}
};
NioEventLoopGroup group = new NioEventLoopGroup();
group.setMemoryCapacity(5120000 * 256 * CLIENT_CORE_SIZE);
group.setMemoryUnit(256);
group.setWriteBuffers(TestLoadServer.WRITE_BUFFERS);
group.setEnableMemoryPool(TestLoadServer.ENABLE_POOL);
context = new ChannelConnector(group, "127.0.0.1", 8300);
context.setIoEventHandle(eventHandleAdaptor);
if (TestLoadServer.ENABLE_SSL) {
context.setSslContext(SslContextBuilder.forClient(true).build());
}
context.setPrintConfig(false);
context.addProtocolCodec(new LengthValueCodec());
if (TestLoadServer.ENABLE_WORK_EVENT_LOOP) {
context.setExecutorGroup(new ThreadEventLoopGroup("ep", 1024 * 256));
}
context.connect(6000);
}
use of com.firenio.concurrent.ThreadEventLoopGroup in project baseio by generallycloud.
the class TestLoadServer method main.
public static void main(String[] args) throws Exception {
Options.setBufAutoExpansion(AUTO_EXPANSION);
Options.setEnableEpoll(ENABLE_EPOLL);
Options.setEnableUnsafeBuf(ENABLE_UNSAFE_BUF);
IoEventHandle eventHandle = new IoEventHandle() {
@Override
public void accept(Channel ch, Frame f) throws Exception {
String text = f.getStringContent();
if (BUFFERED_WRITE) {
ByteBuf buf = ch.getAttribute(WRITE_BUF);
if (buf == null) {
buf = ch.allocate();
ByteBuf temp = buf;
ch.setAttribute(WRITE_BUF, buf);
ch.getEventLoop().submit(() -> {
ch.writeAndFlush(temp);
ch.setAttribute(WRITE_BUF, null);
});
}
byte[] data = text.getBytes(ch.getCharset());
buf.writeInt(data.length);
buf.writeBytes(data);
} else {
f.setString(text, ch);
ch.writeAndFlush(f);
}
}
};
NioEventLoopGroup group = new NioEventLoopGroup(SERVER_CORE_SIZE);
group.setMemoryCapacity(1024 * 512 * MEM_UNIT * SERVER_CORE_SIZE);
group.setWriteBuffers(WRITE_BUFFERS);
group.setMemoryUnit(MEM_UNIT);
group.setEnableMemoryPool(ENABLE_POOL);
ChannelAcceptor context = new ChannelAcceptor(group, 8300);
context.addProtocolCodec(new LengthValueCodec());
context.setIoEventHandle(eventHandle);
if (ENABLE_SSL) {
// context.setSslPem("localhost.key;localhost.crt");
}
context.addChannelEventListener(new LoggerChannelOpenListener());
if (ENABLE_WORK_EVENT_LOOP) {
context.setExecutorGroup(new ThreadEventLoopGroup("ep", 1024 * 256 * CLIENT_CORE_SIZE));
}
context.bind();
}
use of com.firenio.concurrent.ThreadEventLoopGroup in project baseio by generallycloud.
the class TestHttpBootstrapEngine method bootstrap.
@Override
public void bootstrap(String rootPath, boolean prodMode) throws Exception {
ClassLoader cl = this.getClass().getClassLoader();
boolean debug = Util.isTrueValue(System.getProperty("http.debug"));
if (debug) {
for (; debug; ) {
Util.sleep(100);
}
}
DevelopConfig.NATIVE_DEBUG = true;
DevelopConfig.BUF_DEBUG = true;
DevelopConfig.BUF_PATH_DEBUG = true;
DevelopConfig.SSL_DEBUG = true;
DevelopConfig.CHANNEL_DEBUG = true;
DevelopConfig.DEBUG_ERROR = true;
Options.setEnableEpoll(true);
Options.setEnableUnsafe(true);
Options.setEnableOpenssl(true);
Options.setBufThreadYield(true);
// Options.setEnableUnsafeBuf(true);
HttpDateUtil.start();
final SpringHttpFrameHandle handle = new SpringHttpFrameHandle();
Properties properties = FileUtil.readPropertiesByCls("server.properties", cl);
NioEventLoopGroup group = new NioEventLoopGroup(true);
ChannelAcceptor context = new ChannelAcceptor(group);
ConfigurationParser.parseConfiguration("server.", context, properties);
ConfigurationParser.parseConfiguration("server.", group, properties);
context.setIoEventHandle(handle);
context.addChannelIdleEventListener(new ChannelAliveListener());
context.addChannelEventListener(new WebSocketChannelListener());
context.addChannelEventListener(new LoggerChannelOpenListener());
context.addChannelEventListener(new CountChannelListener());
context.setExecutorGroup(new ThreadEventLoopGroup());
context.addLifeCycleListener(new LifeCycleListener() {
@Override
public void lifeCycleStarting(LifeCycle lifeCycle) {
try {
handle.initialize(context, rootPath, prodMode);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
@Override
public void lifeCycleStopped(LifeCycle lifeCycle) {
handle.destroy(context);
}
});
String[] applicationProtocols = null;
if (properties.getBooleanProperty("app.enableHttp2")) {
context.addProtocolCodec(new Http2Codec());
applicationProtocols = new String[] { "h2", "http/1.1" };
} else {
context.addProtocolCodec(new HttpCodec(4));
context.addProtocolCodec(new WebSocketCodec());
}
int defaultPort = 80;
String pem = properties.getProperty("server.sslPem");
if (!Util.isNullOrBlank(pem)) {
defaultPort = 443;
SslContext sslContext = loadSslContextFromPem(pem, applicationProtocols, cl);
context.setSslContext(sslContext);
}
int port = properties.getIntegerProperty("server.port", defaultPort);
context.setPort(port);
try {
context.bind();
} catch (Exception e) {
HttpDateUtil.stop();
group.stop();
throw e;
}
this.group = group;
this.context = context;
if (properties.getBooleanProperty("app.proxy")) {
NetDataTransferServer.get().startup(group, 18088);
}
}
Aggregations