All Projects → pinterest → Elixir Thrift

pinterest / Elixir Thrift

Licence: apache-2.0
A Pure Elixir Thrift Implementation

Programming Languages

elixir
2628 projects

Labels

Projects that are alternatives of or similar to Elixir Thrift

Thriftpy2
Pure python approach of Apache Thrift.
Stars: ✭ 402 (+120.88%)
Mutual labels:  rpc, thrift
Armeria
Your go-to microservice framework for any situation, from the creator of Netty et al. You can build any type of microservice leveraging your favorite technologies, including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot and Dropwizard.
Stars: ✭ 3,392 (+1763.74%)
Mutual labels:  rpc, thrift
thrift-typescript
Generate TypeScript from Thrift IDL files
Stars: ✭ 129 (-29.12%)
Mutual labels:  thrift, rpc
Thriftpy
Thriftpy has been deprecated, please migrate to https://github.com/Thriftpy/thriftpy2
Stars: ✭ 1,156 (+535.16%)
Mutual labels:  rpc, thrift
Finagle
A fault tolerant, protocol-agnostic RPC system
Stars: ✭ 8,126 (+4364.84%)
Mutual labels:  rpc, thrift
Javaspringbootsamples
SpringBoot、Dubbo、SpringCloud的各种集成例子:Atomikos、gRPC、Thrift、Seata、ShardingSphere、Dubbo、Hmily、Nacos、Consul、Ribbon、Jedis、Lettuce、Redisson等框架
Stars: ✭ 399 (+119.23%)
Mutual labels:  rpc, thrift
Yarpc Go
A message passing platform for Go
Stars: ✭ 285 (+56.59%)
Mutual labels:  rpc, thrift
Srpc
RPC based on C++ Workflow
Stars: ✭ 521 (+186.26%)
Mutual labels:  rpc, thrift
Nettythrift
Thrift on Netty, support TCP/HTTP/WebSocket at same port. support multiple Protocols at same time. multil Simple Clients with Connection Pool.
Stars: ✭ 60 (-67.03%)
Mutual labels:  rpc, thrift
Dapeng Soa
A lightweight, high performance micro-service framework
Stars: ✭ 101 (-44.51%)
Mutual labels:  rpc, thrift
Ginrpc
gin auto binding,grpc, and annotated route,gin 注解路由, grpc,自动参数绑定工具
Stars: ✭ 157 (-13.74%)
Mutual labels:  rpc
Gayrpc
Full Duplex C++ RPC Library,Use Protobuf, Support HTTP API .
Stars: ✭ 157 (-13.74%)
Mutual labels:  rpc
Discordrpcmaker
Cross-platform Discord Rich Presence Maker, WITH BUTTONS!
Stars: ✭ 165 (-9.34%)
Mutual labels:  rpc
Ipcinvoker
A IPC Invoker for Android Development.
Stars: ✭ 176 (-3.3%)
Mutual labels:  rpc
Pulsar
Event driven concurrent framework for Python
Stars: ✭ 1,867 (+925.82%)
Mutual labels:  rpc
Asylum tutorials
Code for tutorials posted on my blog.
Stars: ✭ 165 (-9.34%)
Mutual labels:  rpc
Dotnettyrpc
A RPC Framework Based On DotNetty
Stars: ✭ 153 (-15.93%)
Mutual labels:  rpc
Mango
A high-performance, open-source java RPC framework.
Stars: ✭ 150 (-17.58%)
Mutual labels:  rpc
Spring Thrift Starter
Set of cool annotations that helps you building Thrift applications with Spring Boot
Stars: ✭ 151 (-17.03%)
Mutual labels:  thrift
Finatra
Fast, testable, Scala services built on TwitterServer and Finagle
Stars: ✭ 2,126 (+1068.13%)
Mutual labels:  thrift

Elixir Thrift

Hex Version Hex Docs Build Status Coverage Status

This package contains an implementation of Thrift for Elixir. It includes a Thrift IDL parser, an Elixir code generator, and binary framed client and server implementations.

The generated serialization code is highly optimized and has been measured at 10 and 25 times fasterwhy? than the code generated by the Apache Thrift Erlang implementation.

Project Status

Version 2.0 is under actively development and should be released soon. It is a complete rewrite that drops the Apache Thrift dependency and implements everything in pure Elixir.

Getting Started

Until version 2.0 is released, you'll need to track the master branch directly:

{:thrift, github: "pinterest/elixir-thrift"}

This package includes a Mix compiler task that automates Thrift code generation. Prepend :thrift to your project's :compilers list and add a new top-level :thrift configuration key. The only necessary compiler option is :files, which defines the list of Thrift files that should be compiled.

# mix.exs
defmodule MyProject.Mixfile do
  # ...
  def project do
    [
      # ...
      compilers: [:thrift | Mix.compilers],
      thrift: [
        files: Path.wildcard("thrift/**/*.thrift")
      ]
    ]
  end
end

RPC Service Support

We provide full client and server support for Thrift RPC services. The examples below are based on this simplified service definition:

service Service {
  i64 add(1: i64 left, 2: i64 right)
}

You can also check out the full example project for a complete client and server implementation of the sample calculator application.

Clients

You interact with Thrift services using generated, service-specific interface modules. These modules handle type conversions and make calling the service's remote functions easier.

iex> alias Calculator.Generated.Service.Binary.Framed.Client
iex> {:ok, client} = Client.start_link("localhost", 9090, [])
iex> {:ok, result} = Client.add(client, 10, 20)
{:ok, 30}

We generate two versions of each function defined by the Thrift service's interface: one that returns a standard result tuple, and a ! variant that returns a single result value but raises an exception if an error occurs.

@spec add(pid(), integer(), integer(), Client.options()) :: {:ok, integer()} | {:error, any()}
def add(client, left, right, rpc_opts \\ [])

@spec add!(pid(), integer(), integer(), Client.options()) :: integer()
def add!(client, left, right, rpc_opts \\ [])

Servers

In order to start a Thrift server, you will need to provide a callback module that implements the functions described by its service interface. Fortunately, a behaviour module will be automatically generated for you, complete with success typing.

defmodule Calculator.ServiceHandler do
  @behaviour Calculator.Generated.Service.Handler

  @impl true
  def add(left, right) do
    left + right
  end
end

Then provide your handler module when starting the server process:

iex> alias Calculator.Generated.Service.Binary.Framed.Server
iex> {:ok, server} = Server.start_link(Calculator.ServiceHandler, 9090, [])

All RPC calls to the server will be delegated to the handler module. The server provides a supervisor which can be added to your application's supervision tree. It's important to add it to your supervision tree with type :supervisor and not :worker.

defmodule Calculator.Application
  alias Calculator.Generated.Service.Binary.Framed.Server

  def start(_type, _args) do
    children = [
      server_child_spec(9090)
    ]

    opts = [strategy: :one_for_one, name: Calculator.Supervisor]
    Supervisor.start_link(children, opts)
  end

  defp server_child_spec(port) do
    %{
      id: Server,
      start: {Server, :start_link, [Calculator.ServiceHandler, port]},
      type: :supervisor
    }
  end
end

Serialization

A BinaryProtocol module is generated for each Thrift struct, union, and exception type. You can use this interface to easily serialize and deserialize your own types.

iex> alias Calculator.Generated.Vector
iex> data = %Vector{x: 1, y: 2, z: 3}
|> Vector.BinaryProtocol.serialize
|> IO.iodata_to_binary
iex> Vector.BinaryProtocol.deserialize(data)
{%Calculator.Generated.Vector{x: 1.0, y: 2.0, z: 3.0}, ""}

Thrift IDL Parsing

The Thrift.Parser module parses Thrift IDL documents and produces an abstract syntax tree. You can use these features to support additional languages, protocols, and servers.

Thrift.Parser.parse("enum Colors { RED, GREEN, BLUE }")
%Thrift.AST.Schema{constants: %{},
 enums: %{Colors: %Thrift.AST.TEnum{name: :Colors,
    values: [RED: 1, GREEN: 2, BLUE: 3]}}, exceptions: %{}, includes: [],
 namespaces: %{}, services: %{}, structs: %{}, thrift_namespace: nil,
 typedefs: %{}, unions: %{}}

Debugging

In order to debug your Thrift RPC calls, we recommend you use thrift-tools. It is a set of tools to introspect Apache Thrift traffic.

Try something like:

$ pip install thrift-tools
$ sudo thrift-tool --iface eth0 --port 9090 dump --show-all --pretty

FAQ

Why is it faster than the Apache implementation?

The Apache Thrift implementation uses C++ to write Erlang modules that describe Thrift data structures and then uses these descriptions to turn your Thrift data into bytes. It consults these descriptions every time Thrift data is serialized/deserialized. This on-the-fly conversion costs CPU time.

Additionally, this separation of concerns in Apache Thrift prevent the Erlang VM from doing the best job that it can do during serialization.

Our implementation uses Elixir to write Elixir code that's specific to your Thrift structures. This serialization logic is then compiled, and that compiled code is what converts your data to and from serialized bytes. We've spent a lot of time making sure that the generated code takes advantage of several of the optimizations that the Erlang VM provides.

What tradeoffs have you made to get this performance?

Thrift has the following concepts:

  1. Protocols Define a conversion of data into bytes.
  2. Transports Define how bytes move; across a network or in and out of a file.
  3. Processors Encapsulate reading from streams and doing something with the data. Processors are generated by the Thrift compiler.

In Apache Thrift, Protocols and Transports can be mixed and matched. However, our implementation does the mixing and matching for you and generates a combination of (Protocol + Transport + Processor). This means that if you need to support a new Protocol or Transport, you will need to integrate it into this project.

Presently, we implement:

  • Binary Protocol, Framed Client
  • Binary Protocol, Framed Server

We are more than willing to accept contributions that add more!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].