digplanet beta 1: Athena
Share digplanet:

Agriculture

Applied sciences

Arts

Belief

Business

Chronology

Culture

Education

Environment

Geography

Health

History

Humanities

Language

Law

Life

Mathematics

Nature

People

Politics

Science

Society

Technology

Apache Thrift
Developer(s) Apache Software Foundation
Stable release 0.9.0 / 15 October 2012; 7 months ago (2012-10-15)
Type Remote procedure call framework
License Apache License 2.0
Website thrift.apache.org

Thrift is an interface definition language that is used to define and create services for numerous languages.[1] It is used as a remote procedure call (RPC) framework and was developed at Facebook for "scalable cross-language services development". It combines a software stack with a code generation engine to build services that work efficiently to a varying degree and seamlessly between C#, C++ (on POSIX-compliant systems[2]), Cappuccino,[3] Cocoa, Erlang, Go, Haskell, Java, OCaml, Perl, PHP, Python, Ruby, Node.js and Smalltalk.[4] Although developed at Facebook, it is now an open source project in the Apache Software Foundation. The implementation was described in an April 2007 technical paper released by Facebook, now hosted on Apache.[5] To put it simply, Apache Thrift is a binary communication protocol.[6]

Contents

Architecture[edit]

The Apache Thrift API client/server architecture

Thrift includes a complete stack for creating clients and servers.[7] The top part is generated code from the Thrift definition. The services generate from this file client and processor code. In contrast to built-in types, created data structures are sent as result in generated code. The protocol and transport layer are part of the runtime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure to tie protocols and transports together, like blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is differently implemented for different languages.

Thrift supports a number of protocols:[7]

  • TBinaryProtocol – A straightforward binary format, simple, but not optimized for space efficiency. Faster to process than the text protocol but more difficult to debug.
  • TCompactProtocol – More compact binary format; typically more efficient to process as well
  • TDebugProtocol – A human-readable text format to aid in debugging.
  • TDenseProtocol – Similar to TCompactProtocol, stripping off the meta information from what is transmitted.
  • TJSONProtocol – Uses JSON for encoding of data.
  • TSimpleJSONProtocol – A write-only protocol using JSON. Suitable for parsing by scripting languages.

The supported transports are:

  • TFileTransport – This transport writes to a file.
  • TFramedTransport – This transport is required when using a non-blocking server. It sends data in frames, where each frame is preceded by length information.
  • TMemoryTransport – Uses memory for I/O. The Java implementation uses a simple ByteArrayOutputStream internally.
  • TSocket – Uses blocking socket I/O for transport.
  • TZlibTransport – Performs compression using zlib. Used in conjunction with another transport. Not available in the Java implementation.

Thrift also provides a number of servers, which are

  • TNonblockingServer – A multi-threaded server using non-blocking I/O (Java implementation uses NIO channels). TFramedTransport must be used with this server.
  • TSimpleServer – A single-threaded server using standard blocking I/O. Useful for testing.
  • TThreadPoolServer – A multi-threaded server using standard blocking I/O.

Benefits[edit]

Some stated benefits of Thrift include:[citation needed]

  • Cross-language serialization with lower overhead than alternatives such as SOAP due to use of binary format
  • A lean and clean library. No framework to code. No XML configuration files.
  • The language bindings feel natural. For example Java uses ArrayList<String>. C++ uses std::vector<std::string>.
  • The application-level wire format and the serialization-level wire format are cleanly separated. They can be modified independently.
  • The predefined serialization styles include: binary, HTTP-friendly and compact binary.
  • Doubles as cross-language file serialization.
  • Soft versioning of the protocol. Thrift does not require a centralized and explicit mechanism like major-version/minor-version. Loosely coupled teams can freely evolve RPC calls.
  • No build dependencies or non-standard software. No mix of incompatible software licenses.

Creating a Thrift service[edit]

Thrift is written in C++, but can create code for a number of languages. To create a Thrift service, one has to write Thrift files that describe it, generate the code in the destination language, and write some code to start the server and call it from the client. Here is a code example of such a description file:

enum PhoneType {
 HOME,
 WORK,
 MOBILE,
 OTHER
}
 
struct Phone {
 1: i32 id,
 2: string number,
 3: PhoneType type
}

Thrift will generate the code out of this descriptive information. For instance, in Java, the PhoneType will be a simple enum inside the POJO for Phone class.

See also[edit]

References[edit]

  1. ^ Andrew Prunicki. "Apache Thrift: Introduction". http://www.ociweb.com/: Object Computing Inc. – An Open Solutions Company. Retrieved 2011-04-11. "Through a simple and straightforward Interface Definition Language (IDL), Thrift allows you to define and create services that are both consumable by and serviceable by numerous languages. Using code generation, Thrift creates a set of files that can then be used to create clients and/or servers. In addition to interoperability, Thrift can be very efficient through a unique serialization mechanism that is efficient in both time and space." 
  2. ^ Thrift Requirements, see this issue for Windows support
  3. ^ Fred Potter, Using Thrift with Cappuccino, parallel48's posterously luscious blog, 10 June 2010.
  4. ^ Andrew Prunicki. "Apache Thrift: Code Generation". http://www.ociweb.com/: Object Computing Inc. – An Open Solutions Company. Retrieved 2011-04-12. "Thrift supports many languages too varying degrees. The complete list is below. Be careful before assuming that just because your language has some support that it supports all of the features of Thrift. Python for instance, only supports TBinaryProtocol. Cocoa, C++, C#, Erlang, Haskell, Java, OCaml, Perl, PHP, Python, Ruby, and Smalltalk" 
  5. ^ Mark Slee, Aditya Agarwal, Marc Kwiatkowski, Thrift: Scalable Cross-Language Services Implementation
  6. ^ "Installing and using Apache Cassandra With Java Part 4 (Thrift Client)". http://www.sodeso.nl/: Sodeso – Software Development Solutions. Retrieved 2011-03-30. "Thrift is a separate Apache project which is, to put it simply, a binary communication protocol." 
  7. ^ a b Andrew Prunicki. "Apache Thrift: Introduction". http://www.ociweb.com/: Object Computing Inc. – An Open Solutions Company. Retrieved 2011-04-11. "The top portion of the stack is generated code from your Thrift definition file. Thrift services result in generated client and processor code. These are represented by the brown boxes in the diagram. The data structures that are sent (other than built-in types) also result in generated code. These result in the red boxes. The protocol and transport are part of the Thrift runtime library. Therefore with Thrift, you can define a service, and are free to change the protocol and transport without re-generating your code. Thrift also includes a server infrastructure to tie the protocols and transports together. There are blocking, non-blocking, single and multi-threaded servers available. The "Underlying I/O" portion of the stack differs based on the language in question. For Java and Python network I/O, the built-in libraries are leveraged by the Thrift library, while the C++ implementation uses its own custom implementation." 

External links[edit]


Original courtesy of Wikipedia: http://en.wikipedia.org/wiki/Apache_Thrift — Please support Wikipedia.
A portion of the proceeds from advertising on Digplanet goes to supporting Wikipedia.
4028 videos foundNext > 

Apache Thrift

Do you find yourself struggling with incompatible protocols when making RPC calls between different languages and operating systems? Perhaps Apache Thrift ho...

Apache Thrift Tutorial/ Demo

In this video I provide a brief introduction to Apache Thrift and a demo to install it, generate code and create a client/ server service that uses this code...

Thrift vs Protocol Buffers vs Avro - Biased Comparison by Igor Anishchenko

Let's take a step back and compare data serialization formats, of which there are plenty. What are the key differences between Apache Thrift, Google Protocol...

Apache Cassandra - Part 1

This is the first of a new series to show how to install, configure, and test Apache Cassandra, a very powerful open-source NoSQL database. Part 1 is mainly ...

ZooKeeper

Scott Leberknight presents on Apache ZooKeeper. Code samples: https://github.com/sleberknight/zookeeper-samples Apache ZooKeeper is an open-source server whi...

SB's July Thrift Haul

hey guys sorry for being MIA all the time but im making it up for u. For my new viewers feel free to comment & keep update with me. Makeup Tutorial: http://w...

History of Rap 4 (Jimmy Fallon & Justin Timberlake)

Justin Timberlake and Jimmy Fallon team up again to perform a medley of hip hop's greatest hits. Buy Justin's new album here: http://bit.ly/162L9XI Subscribe...

Apache Cassandra and Python

Description Using Apache Cassandra from Python is easy to do. This talk will cover setting up and using a local development instance of Cassandra from Python...

rmr2, Python, Jar & Pig MapReduce Wordcounts in RStudio

Wordcount with 4 different languages. Jar is fastest. ..what a surprise ;) Hadoop is running on a VirtualBox Image with Zentyal Server 3.01 (x86_64 GNU/Linux...

Wordcount MapReduce in R

Example Script for a simple MapReduce Job with the RevolutionAnalytics rmr2-Package. Example and package source: github.com/RevolutionAnalytics/rmr2 Hadoop i...

4028 videos foundNext > 

1 news items

 
GameDev.net
Tue, 21 May 2013 17:48:09 -0700

If, on the other hand, this is a standalone client in any language I suggest using a service oriented solution (though not directly REST style, you want a maintained session per client), the concept there is fairly simple, go take a look at Apache ...
Loading

Oops, we seem to be having trouble contacting Twitter

Talk About Apache Thrift

You can talk about Apache Thrift with people all over the world in our discussions.

Support Wikipedia

A portion of the proceeds from advertising on Digplanet goes to supporting Wikipedia. Please add your support for Wikipedia!