Slow solution to Thttphandler transmission data in thrift in C language

Source: Internet
Author: User

1. In C # write thrift service side, to the corresponding HTTP request, in the structure of the transmission, you will encounter a problem, that is (in the network) transmission of data is particularly slow,

This is due to the fact that the data is used in the tstreamtransport resulting in each data transmission, a connection is established.

2. Workaround:

The overrides in Thttphandler can be reduced to the following.

12345678910111213141516171819202122232425262728293031323334 public void ProcessRequest(Stream input, Stream output)      {          //TTransport transport = new TStreamTransport(input,output);          TTransport inTransport =new TStreamTransport(input, output);          //在out加入缓存机制          TBufferedTransport outTransport =new TBufferedTransport((TStreamTransport)inTransport);          //TTransport transport = new TStreamTransport(input, output);          TProtocol inputProtocol =null;          TProtocol outputProtocol =null;          try          {              inputProtocol = inputProtocolFactory.GetProtocol(inTransport);              outputProtocol = outputProtocolFactory.GetProtocol(outTransport);              while(processor.Process(inputProtocol, outputProtocol)) { }          }          catch(TTransportException)          {              // Client died, just move on          }          catch(TApplicationException tx)          {              Console.Error.Write(tx);          }          catch(Exception x)          {              Console.Error.Write(x);          }          inTransport.Close();          outTransport.Close();      }

Slow solution to Thttphandler transmission data in thrift in C language

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.