Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
658 views
in Technique[技术] by (71.8m points)

tcp - How to write a high performance Netty Client

I want an extremely efficient TCP client to send google protocol buffer messages. I have been using the Netty library to develop a server/client.

In tests the server seems to be able to handle up to 500k transactions per second, without to many problems, but the client tends to peak around 180k transactions per second.

I have based my client on the examples provided in the Netty documentation, but the difference is I just want to send the message and forget, I don't want a response (which most of the examples get). Is there anyway to optimize my client, so that I can achieve a higher TPS ?

Should my client maintain multiple channels, or should I be able to achieve a higher throughput than this with a single channel?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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);


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...