Maximize Netty performances

Patrizio Munzi patrizio.munzi at eris4.com
Tue Mar 3 12:21:54 EST 2009


Hi everybody,

I've implemented a multi-thread TCP client/server application by using 
Netty 3.0.2.GA and now I'm looking for maximizing its performances.
At the moment I've used basic Netty configurations for both client and 
server sides but I'm wondering if your experience (I'm almost a newbie) 
could provide me with some tips I couldn't learned from available 
documentation.

Here are two snippets from my code:

------------ SERVER ------------------
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();
ChannelFactory channelFactory = new 
NioServerSocketChannelFactory(bossExecutor, workerExecutor);

ServerBootstrap serverBootstrap = new ServerBootstrap(channelFactory);
serverBootstrap.setOption("child.tcpNoDelay", true);
serverBootstrap.setOption("child.keepAlive", true);

serverBootstrap.setPipelineFactory(
    new ChannelPipelineFactory() {
        public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("decoder", new ServerDecoder());
        pipeline.addLast("encoder", new ServerEncoder());
        pipeline.addLast("handler", new ServerHandler());
        return pipeline;
    }
});

Channel channel = serverBootstrap.bind(new InetSocketAddress(port));
-------------------------------------------

------------ CLIENT ------------------
ExecutorService bossExecutor = Executors.newCachedThreadPool();
ExecutorService workerExecutor = Executors.newCachedThreadPool();

ChannelFactory channelFactory = new 
NioClientSocketChannelFactory(bossExecutor, workerExecutor);

ClientBootstrap clientBootstrap = new ClientBootstrap(channelFactory);
clientBootstrap.setOption("tcpNoDelay", true);
clientBootstrap.setOption("keepAlive", true);
clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
    public ChannelPipeline getPipeline() throws Exception {
        ChannelPipeline pipeline = Channels.pipeline();
        pipeline.addLast("decoder", new ClientDecoder());
        pipeline.addLast("encoder", new ClientEncoder());
        pipeline.addLast("handler", new 
DiameterClientHandler(exchangesMap));
        return pipeline;
    }
});

// Start the connection attempt.
ChannelFuture future = clientBootstrap.connect(new 
InetSocketAddress(host, port));

// Wait until the connection attempt succeeds or fails.
Channel channel = future.awaitUninterruptibly().getChannel();
-------------------------------------------

Thanks in advance,
    Patrizio

-- 

*Patrizio Munzi*
Product Specialist
Viale Bruno Buozzi, 19 - 00197 Roma (Italy)
tel: +39 06 4543 3540
fax: +39 06 4543 3587
mobile: +39 393 7195 164
mail: patrizio.munzi at eris4.com <mailto:patrizio.munzi at eris4.com>
web: http://www.eris4.com <http://www.eris4.com/>
skype: eris4_munzi <skype:eris4_munzi?add>




More information about the netty-users mailing list