thrift

RPC框架之Thrift分析

ε祈祈猫儿з 提交于 2019-12-02 16:51:55
一、简介 1、Thrift是Facebook开发的跨语言的RPC服务框架。随后贡献给Apache开源组织。成为RPC服务的主流框架。 2、特点: 优点: 跨语言,支持java、c/c++、python等多种编程语言 IDL定义接口函数和数据类型 支持二进制传输,效率高 支持多种工作模型,单线程模型、线程池模型、非阻塞模型 缺点: 文档不多 各版本不兼容,升级不方便 二、分析 Thrift分为服务端(server)和客户端(Client)两个对应的部分。代码分层设计,分为Transport(传输层)、Protocol(协议层)、Processor(处理层)和Server(服务层)。 1、主要的处理流程: 各部分类图: 传输层 TTransport: 客户端传输层抽象基础类,主要方法:read、write、flush、open、close。read、write方法为核心 TSocket 与 TNonBlockingSocket: 分别是基于BIO和NIO客户端传输类。 TSocket 持有Socket,设置输入输出流使用1K的BufferedStream, TNonBlockingSocket 持有SocketChannel,read和write方法里的byte会每次被wrap成一个ByteBuffer。 TServerSocket 与 TNonBlockingServerSocket

Thrift入门示例

坚强是说给别人听的谎言 提交于 2019-12-02 16:05:50
RPC基本原理 RPC(Remote Procedure Call),远程过程调用,大部分的RPC框架都遵循如下三个开发步骤: 1. 定义一个接口说明文件:描述了对象(结构体)、对象成员、接口方法等一系列信息; 2. 通过RPC框架所提供的编译器,将接口说明文件编译成具体的语言文件; 3. 在客户端和服务器端分别引入RPC编译器所生成的文件,即可像调用本地方法一样调用服务端代码; RPC通信过程如下图所示 通信过程包括以下几个步骤: 1、客户过程以正常方式调用客户桩(client stub,一段代码); 2、客户桩生成一个消息,然后调用本地操作系统; 3、客户端操作系统将消息发送给远程操作系统; 4、远程操作系统将消息交给服务器桩(server stub,一段代码); 5、服务器桩将参数提取出来,然后调用服务器过程; 6、服务器执行要求的操作,操作完成后将结果返回给服务器桩; 7、服务器桩将结果打包成一个消息,然后调用本地操作系统; 8、服务器操作系统将含有结果的消息发送回客户端操作系统; 9、客户端操作系统将消息交给客户桩; 10、客户桩将结果从从消息中提取出来,返回给调用它的客户过程; 所有这些步骤的效果是,将客户过程对客户桩发出的本地调用转换成对服务器过程的本地调用,而客户端和服务器都不会意识到有中间步骤的存在。 这个时候,你可能会想,既然是调用另一台机器的服务,使用

Thrift RPC Golang、C++ Example

妖精的绣舞 提交于 2019-12-02 14:49:57
Thrift RPC Example 运行 请直接使用即可,无需拉取任何依赖包。 cd $GOPATH/src git clone https://github.com/hunterhug/thrift_example.git go build server.gp go build client.go ./server ./client $GOPATH 为环境变量,请替换为你的本地路径。 具体使用,详细介绍 gRPC是Google研究的RPC传输方案,thrift则是facebook, 大家都通过IDL(Interface Definition Language)接口定义语言来规范输入输出。 下载: https://thrift.apache.org/download Ubuntu 系统安装 sudo apt-get install automake bison flex git libboost-all-dev libevent-dev libssl-dev libtool make pkg-config build-essential g++ tar xvf thrift-0.12.0.tar.gz ./bootstrap.sh ./configure make sudo make install sudo ldconfig Windows系统请直接安装二进制。 建立

Haskell Thrift library 300x slower than C++ in performance test

余生颓废 提交于 2019-12-02 14:28:48
I'm building an application which contains two components - server written in Haskell, and client written in Qt (C++). I'm using thrift to communicate them, and I wonder why is it working so slow. I made a performance test and here is the result on my machine Results C++ server and C++ client: Sending 100 pings - 13.37 ms Transfering 1000000 size vector - 433.58 ms Recieved: 3906.25 kB Transfering 100000 items from server - 1090.19 ms Transfering 100000 items to server - 631.98 ms Haskell server and C++ client: Sending 100 pings 3959.97 ms Transfering 1000000 size vector - 12481.40 ms Recieved

Hue 入门

 ̄綄美尐妖づ 提交于 2019-12-02 10:31:41
1 简介 Hue 是什么? Hue=Hadoop User Experience(Hadoop 用户体验),直白来说就一个开源的 Apache Hadoop UI 系统,它是基于Python Web 框架 Django 实现的,通过使用 Hue 我们可以在浏览器端的 Web 控制台上与 Hadoop 集群进行交互来分析处理数据。 2 安装部署 2.1、帮助文档 http://archive.cloudera.com/cdh5/cdh/5/hue-3.7.0-cdh5.3.0/manual.html 2.2、Hue 安装 1.安装前准备 必备的软件环境: Centos 7.6+Python 2.7.5+JDK8+Maven-3.3.9+Ant-1.8.1+Hue-3.7.0 必备的集群环境: Hadoop+HBase+Hive+ZK+MySQL+Oozie 配置环境变量 #JAVA_HOME export JAVA_HOME = /opt/module/jdk1.8.0_144 export PATH = $PATH : $JAVA_HOME /bin #MAVEN_HOME export MAVEN_HOME = /opt/module/maven-3.3.9 export PATH = $PATH : $MAVEN_HOME /bin #HADOOP_HOME export

C++ linker error in Apache Thrift tutorial - undefined symbols

非 Y 不嫁゛ 提交于 2019-12-02 03:45:17
I am running through Apache's Thrift tutorial: http://wiki.apache.org/thrift/ThriftUsageC%2B%2B My Thrift is version 0.9.1, and I'm on OS X. I've performed a search for similar problems with this tutorial, and while other people have also had issues they don't appear to be similar to the one I'm having. The server both compiles and links properly, and the client compiles correctly as well. The problem is linking the client at the very last step of the tutorial, where I get this: Undefined symbols for architecture x86_64: "apache::thrift::transport::TSocket::TSocket(std::string, int)",

Start HiveThriftServer programmatically in Python

社会主义新天地 提交于 2019-12-02 03:41:33
问题 In the spark-shell (scala), we import, org.apache.spark.sql.hive.thriftserver._ for starting Hive Thrift server programatically for a particular hive context as HiveThriftServer2.startWithContext(hiveContext) to expose a registered temp table for that particular session. How can we do the same using python? Is there a package / api on python for importing HiveThriftServer? Any other thoughts / recommendations appreciated. We have used pyspark for creating a dataframe Thanks Ravi Narayanan 回答1

How to connect to hive using python pyhs2?

青春壹個敷衍的年華 提交于 2019-12-02 00:59:08
I am trying to access hive using pyhs2 . I tried the following code: example.py import pyhs2 conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default') with conn.cursor() as cur: cur.execute("select * from table") for i in cur.fetch(): print i I am getting the following error: Traceback (most recent call last): File "example.py", line 2, in <module> conn = pyhs2.connect(host='localhost', port=10000,authMechanism=None, user=None, password=None,database='default') File "build/bdist.linux-x86_64/egg/pyhs2/__init__.py", line 7, in connect

File Transport between Server/Client

99封情书 提交于 2019-12-01 23:00:36
问题 What kind of Service should I define for ".thrift"-file to use it later for my Program? This File Transport should be between the Client and the Server and it should be "partly". StreamFileService.thrift: struct FileChunk { 1: binary data 2: i64 remaining } service StreamFileService { FileChunk getBytes(1:string fileName, 2: i64 offset, 3: i32 size); } StreamFileClient.java: public class StreamFileClient { private int fileChunkSize = 16; private String filePath; public String getFilePath() {

Golang通过Thrift框架完美实现跨语言调用

*爱你&永不变心* 提交于 2019-12-01 21:52:20
  每种语言都有自己最擅长的领域,Golang 最适合的领域就是服务器端程序。   做为服务器端程序,需要考虑性能同时也要考虑与各种语言之间方便的通讯。采用 http 协议简单,但性能不高。采用 TCP 通讯,则需要考虑封包、解包、粘包等等很多因素,而且想写个高效的 TCP 服务,也很难。   其实,对于此类需求,采用 RPC ( Remote Procedure Call Protocol ) 编程最靠谱。使用 RPC 编程 被认为是在分布式环境中运行的客户机和服务器应用程序之间进行可靠通信的最强大、最高效的方法之一。   Golang 内置了对 RPC 支持,但只能适用于 go 语言程序之间调用,且貌似序列化、反序列化性能不高。如果 go 语言能使用 Thrift 开发,那么就如虎添翼了。可惜, thrift 虽然很早就包含了 golang 的代码,但一直都存在各种问题无法正确执行,以至于GitHub上有许多大牛小牛自行实现的Thrift代码,但依然各种问题……直到 0.9.1 版本的发布!   是的,最近, Apache Thrift 0.9.1 正式发布了。新版的 Thrift 终于对 Golang 提供了完美的支持。经过实验,服务器端、客户端已经完美支持跨语言调用,且性能、尤其是内存占用上,编译型语言的特点展现出来,比 java 版的实现强了很多。   下面,我们采用