netty优化学习积累+++++++

一、

c/s-Handler在需要发送消息时,不一定必须调用writeandFlush(),如果对于一些零碎的消息都writeAndFlush(),那么多次频繁的调用对应多次的syscall系统调用,如何减少系统调用提高效率?

write()函数,对于多次要发送的零碎的消息都采用write()函数,这样只会把消息gather汇聚起来,放到缓冲区中,

最后一个flush()函数,会将缓冲区中汇聚的多方消息全部整合发送,减少了系统调用syscall.

https://stackoverflow.com/questions/27498428/implementing-group-flush-in-server-side-netty-handler

二、

1) If the client is only interested in sending, not in receiving, you can always disable reading from channel like below

channel.setReadable(false);

2) You can increase the throughput very easily by having multiple client channels per client, and also it can scale too.

3) and you can do following tweaks to improve the performance in general (for read/ write)

  • Its better to have a SEDA like pipline by adding a EXecutionHandler with OrderdMemoryAwareThreadPoolExecutor, (with min, max channel memory with optimal value)

    bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline( executionHandler1,//sharable new MessageDecoderHandler(), new MessageEncoderHandler(), executionHandler2,//sharable new BusinessLogicHandler1(), new BusinessLogicHandler2()); } });
  • Setting the writeBufferHighWaterMark of the channel to optimal value (Make sure that setting a big value will not create congestion)

    bootstrap.setOption("writeBufferHighWaterMark", 10 * 64 * 1024);

  • Setting the SO_READ, SO_WRITE buffer size

    bootstrap.setOption("sendBufferSize", 1048576); bootstrap.setOption("receiveBufferSize", 1048576);

  • Enabling the TCP No delay

    bootstrap.setOption("tcpNoDelay", true);

  •       

  •  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值