#31


Nasz system rozmawia po Thrifcie

(Our system speaks Thrift)

Tomasz Ducin
16th December 2013, Warsaw

Tomek Ducin

Python, JavaScript
lead frontend developer @ Gemius
TDD, CI, Agile enthusiast
Open Source enthusiast
mentor @ gitkata

agenda

  • origins & aims
  • fundamentals
  • code generation / basic example
  • benefits & limitations
  • competitors comparison: twisted, protobuf
  • advanced example outline

origins



big users

(most important) supported languages

C (GLib), C++, C#,
Cocoa, D, Delphi,
Erlang, Haskell, Java,
OCaml, JavaScript,
Perl, PHP, Python,
Ruby, Smalltalk

communication


  • traditional client-server request-response model... but the server can handle requests from different language clients out of the box
  • several built-in transports, protocols and server types

components & data types

  • services
  • structs
  • basics
    • bool
    • signed integers: byte, i16, i32, i64
    • double
    • string (UTF-8 encoded)
  • containers
    • map<t1,t2>
    • list<t1>
    • set<t1>
  • others
    • enumerations
    • constants
    • exceptions

code generator (thrift compiler)

install thrift:
  • from sources (current version 0.9.1)
  • dependencies (boost, bison and more...)
  • choose supported languages (py, rb, java, etc.)
thrift --gen <language> <thrift filename>
# examples
thrift -r --gen java -out src/main/java src/main/thrift/game.thrift
thrift -r --gen py -out src/main/python src/main/thrift/game.thrift

basic example - hello world

basic example - tic tac toe

benefits of using thrift

  • avoiding boilerplate code (built-in protocols, transports and servers)
  • binary serialization
  • cross-language communication
  • natural language bindings
  • separation of concerns (application, transport)
  • thrift definitions become precise documentation which has to be up-to-date all the time
  • soft versioning

development limitations

  • no cyclic structs
  • no struct inheritance
  • hence no polymorphism
  • no overloading
  • no heterogeneous containers


community limitations

  • basic documentation, few examples
  • no professional literature
    (currently only work-in-progress)

python support

2.x ✔

3.x ✘

found on apache jira task:
There has been no timeline set for this, the biggest thing we are trying to avoid is having a py2 and a py3 library to support

thrift vs twisted

can be used for similar tasks

twisted

  • python only
  • asynchronous only
  • no code generation
  • focused on handling connections

thrift

  • focused on logical models and services
  • request-response communication

thrift vs protocol buffers

both very similar

thrift

  • supports more features
    such as containers, constants, exceptions
             
  • more languages out of the box

protobuf

  • comes from Google ;)
  • more aggressive data compression, slightly faster
  • documentation supposed to be better (more examples)

advanced example


Resources

Thanks!

thrift

By Tomasz Ducin

thrift

Presentation during Warsaw Python Meetings, http://pywaw.org/31/

  • 4,730