html tool

显示标签为“thrift”的博文。显示所有博文
显示标签为“thrift”的博文。显示所有博文

2017年2月5日星期日

thrift TFramed与TBuffered , TCompactProtocol 和 TBinaryProtocol 的区别

问题:使用模拟器测试,提示:
Thrift: Mon Feb 6 12:16:48 2017 TConnectedClient died: Frame size has negative value
client端提示错误为:
message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

修改使用
21 transport = TTransport.TFramedTransport(transport)
23 protocol = TCompactProtocol.TCompactProtocol(transport)
替代如下:测试通过
20 #transport = TTransport.TBufferedTransport(transport)
22 #protocol = TBinaryProtocol.TBinaryProtocol(transport)

解释: 
TFramed与TBuffered的区别
参考:http://grokbase.com/t/thrift/user/101gw5eh24/tframedtransport-and-tbufferedtransport
Generally, unless you're working directly from memory, you should always use
either framed or buffered transport. Otherwise, every little byte you need
to read out will go to the OS buffer, which will just crush your
performance.

Additionally, if you are connecting to a nonblocking server (like Java's
TNonblockingServer and THsHaServer), then you *must* use a framed transport,
since this is the only way they can tell when a whole message has been sent.

参考:http://halloffame.iteye.com/blog/2346959
1--transport_type本例中只列举使用了以下三种:
(1) buffered:使用经典的缓冲流Socket;
(2) framed:基于帧的方式的Socket,每个帧都是按照4字节的帧长加上帧的内容来组织,帧内容就是我们要收发的数据。读的时候按长度预先将整Frame数据读入Buffer,再从Buffer慢慢读取。写的时候,每次flush将Buffer中的所有数据写成一个Frame。framed这种方式有点类似于http协议的chunked编码;
(3) fastframed:和framed相比是内存利用率更高的一个内存读写缓存区,它使用自动增长的byte[](不够长度才new),而不是每次都new一个byte[],提高了内存的使用率。framed的ReadBuffer每次读入Frame时都会创建新的byte[],WriteBuffer每次flush时如果大于初始1K也会重新创建byte[]。


2--protocol_type本例中只列举使用了以下三种:
(1) binary:二进制编码格式进行数据传输;
(2) json:使用JSON的数据编码协议进行数据传输;
(3) compact:高效率的,密集的二进制编码格式进行数据传输
[popexizhi: 这个正好是
 TCompactProtocol 和  TBinaryProtocol 的区别]


2016年9月26日星期一

转载How to install Apache Thrift on Ubuntu 14.04

1. Introduction

Apache Thrift is just a software framework written in C++. It was initially developed in 2007 by Facebook but now it is an Open Source project in Apache Software Foundation (ASF). The RPC is Remote Procedure Call is a type of protocol, requesting a service from one server to another server in a network using programs. Tt does not need any kind of network details for the whole process. In this article, We are going to install Apache Thrift.
Install all the dependencies
# apt-get install libboost-dev libboost-test-dev libboost-program-options-dev libboost-system-dev libboost-filesystem-dev libevent-dev automake libtool flex bison pkg-config g++ libssl-dev ant

2. Install Java JDK

Check whether the Java JDK package is installed or not. You may use the below command to verify :
# java --version

If the Java JDK is not installed. Please the command to install Java JDK :
# apt-get install openjdk-7-jre 
# apt-get install openjdk-7-jdk
Thus we have completed installing the dependencies.

3. Installation

Download the latest version of Apache Thrift from there official site in to your local directory :
# http://www.us.apache.org/dist/thrift/0.9.3/thrift-0.9.3.tar.gz
Extract the tar file :
# tar -xvf thrift-0.9.3.tar.gz
Now install thirift folder :
# cd thrift-0.9.3/
# ./configure
thrift 0.9.3

Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : no
Building Python Library ...... : no
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no

C++ Library:
   Build TZlibTransport ...... : yes
   Build TNonblockingServer .. : yes
   Build TQTcpServer (Qt4) .... : no
   Build TQTcpServer (Qt5) .... : no

Java Library:
   Using javac ............... : javac
   Using java ................ : java
   Using ant ................. : /usr/bin/ant

# make 
# make install
Thus the installation process is completed. We can verify the installation using the command below :
# thrift -version
Thrift version 0.9.3

4. Conclusion

Thus we have completed the installation of Apache Thrift.