use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project flink by apache.
the class NettyConnectionManagerTest method testMatchingNumberOfArenasAndThreadsAsDefault.
/**
* Tests that the number of arenas and number of threads of the client and server are set to the
* same number, that is the number of configured task slots.
*/
@Test
public void testMatchingNumberOfArenasAndThreadsAsDefault() throws Exception {
// Expected number of arenas and threads
int numberOfSlots = 2;
NettyConnectionManager connectionManager;
try (NetUtils.Port port = NetUtils.getAvailablePort()) {
NettyConfig config = new NettyConfig(InetAddress.getLocalHost(), port.getPort(), 1024, numberOfSlots, new Configuration());
connectionManager = createNettyConnectionManager(config);
connectionManager.start();
}
assertNotNull("connectionManager is null due to fail to get a free port", connectionManager);
assertEquals(numberOfSlots, connectionManager.getBufferPool().getNumberOfArenas());
{
// Client event loop group
Bootstrap boostrap = connectionManager.getClient().getBootstrap();
EventLoopGroup group = boostrap.group();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfSlots, eventExecutors.length);
}
{
// Server event loop group
ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap();
EventLoopGroup group = bootstrap.group();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfSlots, eventExecutors.length);
}
{
// Server child event loop group
ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap();
EventLoopGroup group = bootstrap.childGroup();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfSlots, eventExecutors.length);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project flink by apache.
the class NettyConnectionManagerTest method testManualConfiguration.
/**
* Tests that the number of arenas and threads can be configured manually.
*/
@Test
public void testManualConfiguration() throws Exception {
// Expected numbers
int numberOfArenas = 1;
int numberOfClientThreads = 3;
int numberOfServerThreads = 4;
// Expected number of threads
Configuration flinkConfig = new Configuration();
flinkConfig.setInteger(NettyShuffleEnvironmentOptions.NUM_ARENAS, numberOfArenas);
flinkConfig.setInteger(NettyShuffleEnvironmentOptions.NUM_THREADS_CLIENT, 3);
flinkConfig.setInteger(NettyShuffleEnvironmentOptions.NUM_THREADS_SERVER, 4);
NettyConnectionManager connectionManager;
try (NetUtils.Port port = NetUtils.getAvailablePort()) {
NettyConfig config = new NettyConfig(InetAddress.getLocalHost(), port.getPort(), 1024, 1337, flinkConfig);
connectionManager = createNettyConnectionManager(config);
connectionManager.start();
assertEquals(numberOfArenas, connectionManager.getBufferPool().getNumberOfArenas());
}
assertNotNull("connectionManager is null due to fail to get a free port", connectionManager);
{
// Client event loop group
Bootstrap boostrap = connectionManager.getClient().getBootstrap();
EventLoopGroup group = boostrap.group();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfClientThreads, eventExecutors.length);
}
{
// Server event loop group
ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap();
EventLoopGroup group = bootstrap.group();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfServerThreads, eventExecutors.length);
}
{
// Server child event loop group
ServerBootstrap bootstrap = connectionManager.getServer().getBootstrap();
EventLoopGroup group = bootstrap.childGroup();
Field f = group.getClass().getSuperclass().getSuperclass().getDeclaredField("children");
f.setAccessible(true);
Object[] eventExecutors = (Object[]) f.get(group);
assertEquals(numberOfServerThreads, eventExecutors.length);
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project pinpoint by naver.
the class NettyIT method writeTest.
@Test
public void writeTest() throws Exception {
final CountDownLatch awaitLatch = new CountDownLatch(1);
EventLoopGroup workerGroup = new NioEventLoopGroup(2);
Bootstrap bootstrap = client(workerGroup);
final ChannelFuture connect = bootstrap.connect(webServer.getHostname(), webServer.getListeningPort());
connect.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) throws Exception {
if (future.isSuccess()) {
Channel channel = future.channel();
channel.pipeline().addLast(new SimpleChannelInboundHandler() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
awaitLatch.countDown();
}
});
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
future.channel().writeAndFlush(request);
}
}
});
boolean await = awaitLatch.await(3000, TimeUnit.MILLISECONDS);
Assert.assertTrue(await);
final Channel channel = connect.channel();
try {
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(event("NETTY", Bootstrap.class.getMethod("connect", SocketAddress.class), annotation("netty.address", webServer.getHostAndPort())));
verifier.verifyTrace(event("NETTY", "io.netty.channel.DefaultChannelPromise.addListener(io.netty.util.concurrent.GenericFutureListener)"));
verifier.verifyTrace(event("ASYNC", "Asynchronous Invocation"));
verifier.verifyTrace(event("NETTY_INTERNAL", "io.netty.util.concurrent.DefaultPromise.notifyListenersNow()"));
verifier.verifyTrace(event("NETTY_INTERNAL", "io.netty.util.concurrent.DefaultPromise.notifyListener0(io.netty.util.concurrent.Future, io.netty.util.concurrent.GenericFutureListener)"));
verifier.verifyTrace(event("NETTY", "io.netty.channel.DefaultChannelPipeline.writeAndFlush(java.lang.Object)"));
verifier.verifyTrace(event("NETTY_HTTP", "io.netty.handler.codec.http.HttpObjectEncoder.encode(io.netty.channel.ChannelHandlerContext, java.lang.Object, java.util.List)", annotation("http.url", "/")));
} finally {
channel.close().sync();
workerGroup.shutdown();
}
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project alluxio by Alluxio.
the class GrpcConnectionPool method applyGroupDefaults.
/**
* It updates and returns the given {@link NettyChannelBuilder} based on network group settings.
*/
private NettyChannelBuilder applyGroupDefaults(GrpcChannelKey key, NettyChannelBuilder channelBuilder, AlluxioConfiguration conf) {
long keepAliveTimeMs = conf.getMs(PropertyKey.Template.USER_NETWORK_KEEPALIVE_TIME_MS.format(key.getNetworkGroup().getPropertyCode()));
long keepAliveTimeoutMs = conf.getMs(PropertyKey.Template.USER_NETWORK_KEEPALIVE_TIMEOUT_MS.format(key.getNetworkGroup().getPropertyCode()));
long inboundMessageSizeBytes = conf.getBytes(PropertyKey.Template.USER_NETWORK_MAX_INBOUND_MESSAGE_SIZE.format(key.getNetworkGroup().getPropertyCode()));
long flowControlWindow = conf.getBytes(PropertyKey.Template.USER_NETWORK_FLOWCONTROL_WINDOW.format(key.getNetworkGroup().getPropertyCode()));
Class<? extends Channel> channelType = NettyUtils.getChannelClass(!(key.getServerAddress().getSocketAddress() instanceof InetSocketAddress), PropertyKey.Template.USER_NETWORK_NETTY_CHANNEL.format(key.getNetworkGroup().getPropertyCode()), conf);
EventLoopGroup eventLoopGroup = acquireNetworkEventLoop(key, conf);
// Update the builder.
channelBuilder.keepAliveTime(keepAliveTimeMs, TimeUnit.MILLISECONDS);
channelBuilder.keepAliveTimeout(keepAliveTimeoutMs, TimeUnit.MILLISECONDS);
channelBuilder.maxInboundMessageSize((int) inboundMessageSizeBytes);
channelBuilder.flowControlWindow((int) flowControlWindow);
channelBuilder.channelType(channelType);
channelBuilder.eventLoopGroup(eventLoopGroup);
// Use plaintext
channelBuilder.usePlaintext();
if (key.getNetworkGroup() == GrpcNetworkGroup.SECRET) {
// Use self-signed for SECRET network group.
channelBuilder.sslContext(getSslContextProvider(conf).getSelfSignedClientSslContext());
channelBuilder.useTransportSecurity();
} else if (conf.getBoolean(alluxio.conf.PropertyKey.NETWORK_TLS_ENABLED)) {
// Use shared TLS config for other network groups if enabled.
channelBuilder.sslContext(getSslContextProvider(conf).getClientSslContext());
channelBuilder.useTransportSecurity();
}
return channelBuilder;
}
use of org.apache.flink.shaded.netty4.io.netty.channel.EventLoopGroup in project netty by netty.
the class HttpNativeServer method main.
public static void main(String[] args) throws Exception {
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
// Control status.
boolean serverStartSucess = false;
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new HttpNativeServerInitializer());
Channel channel = b.bind(0).sync().channel();
System.err.println("Server started, will shutdown now.");
channel.close().sync();
serverStartSucess = true;
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
// return the right system exit code to signal success
System.exit(serverStartSucess ? 0 : 1);
}
Aggregations