grpc&thrift對比

grpc thrift 都是經常使用的rpc 框架,這裏對grpc 和 thrift 從幾個方面對二者進行對比php

一,語言支持度不一樣

grpc 和thrift 對不一樣語言支持度不同,相比而言 thrift 比grpc 支持度更廣,到底如何選擇rpc 框架須要結合公司技術棧來,好比php 不支持grpc 的server,全部有些公司只能用thrift 做爲公司的rpc 框架。java

其中grpc 支持11種語言,其中php 只支持client。node

  • C++: follow the instructions under the src/cpp directory
  • C#: NuGet package Grpc
  • Dart: pub package grpc
  • Go: go get google.golang.org/grpc
  • Java: Use JARs from Maven Central Repository
  • Node: npm install grpc
  • Objective-C: Add gRPC-ProtoRPC dependency to podspec
  • PHP: pecl install grpc
  • Python: pip install grpcio
  • Ruby: gem install grpc
  • WebJS: follow the grpc-web instructions

thrift 支持 23 Language,python

Language Since Build Systems Lang/Lib Levels (Tested) Low-Level Transports Transport Wrappers Protocols Servers Open Issues
autoconf cmake Min Max Domain File Memory Pipe Socket TLS Framed Header http zlib Binary Compact JSON Multiplex Forking Nonblocking Simple Threaded ThreadPool
ActionScript 0.3.0 Yes Yes FLEX SDK 4.6 img img img img Yes img img img Yes img Yes img img img img img img img img [ActionScript](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("AS3 - Compiler"%2C "AS3 - Library") and status not in (fixed%2C resolved%2C closed))
C (glib) 0.6.0 Yes Yes 2.48.2 2.56.4 Yes Yes Yes img Yes Yes Yes img img img Yes Yes img Yes img img Yes img img [C (glib)](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("C glib - Compiler"%2C "C glib - Library") and status not in (fixed%2C resolved%2C closed))
C++ 0.2.0 Yes Yes C++11 Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes img Yes Yes Yes Yes [C++](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("C%2B%2B - Compiler"%2C "C%2B%2B - Library") and status not in (fixed%2C resolved%2C closed))
C# 0.2.0 Deprecated use netstd Yes img .NET 3.5 / mono 3.2.8.0 .NET 4.6.1 / mono 4.6.2.7 img img Yes Yes Yes Yes Yes img Yes img Yes Yes Yes Yes img img Yes Yes Yes [C# (.NET)](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("C%23 - Compiler"%2C "C%23 - Library") and status not in (fixed%2C resolved%2C closed))
Common LISP 0.12.0 Yes img SBCL 1.4.x SBCL 1.5.3 img Yes img img Yes img Yes img img img Yes Yes img Yes img Yes img img img [Common LISP](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Common LISP - Compiler"%2C "Common LISP - Library") and status not in (fixed%2C resolved%2C closed))
Dlang 0.9.0 Yes img 2.075.1 2.087.0 img Yes Yes Yes Yes Yes Yes img Yes Yes Yes Yes Yes img img Yes Yes Yes Yes [D](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("D - Compiler"%2C "D - Library") and status not in (fixed%2C resolved%2C closed))
Dart 0.10.0 Yes img 2.0.0 2.4.0 img img img img Yes img Yes img Yes img Yes Yes Yes Yes img img img img img [Dart](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Dart - Compiler"%2C "Dart - Library") and status not in (fixed%2C resolved%2C closed))
Delphi 0.8.0 img img 2010 unknown img img img img Yes img Yes img Yes img Yes Yes Yes Yes img img Yes img img [Delphi](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Delphi - Compiler"%2C "Delphi - Library") and status not in (fixed%2C resolved%2C closed))
.NET Core 0.11.0 Deprecated use netstd Yes img 2.1.4 2.2.101 img img Yes Yes Yes Yes Yes img Yes img Yes Yes Yes Yes img Yes img img img [.NET Core](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("netcore - Compiler"%2C "netcore - Library") and status not in (fixed%2C resolved%2C closed))
.NET Standard 0.13.0 Yes img .NET 4.5+, .NET Standard 2.x img img Yes Yes Yes Yes Yes img Yes img Yes Yes Yes Yes img Yes img img img [.NET Standard](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("netstd - Compiler"%2C "netstd - Library") and status not in (fixed%2C resolved%2C closed))
Erlang 0.3.0 Yes img 18.3 22.0 img Yes Yes img Yes Yes Yes img Yes img Yes Yes Yes Yes img img Yes img img [Erlang](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Erlang - Compiler"%2C "Erlang - Library") and status not in (fixed%2C resolved%2C closed))
Go 0.7.0 Yes img 1.10.8 1.12.6 img img Yes img Yes Yes Yes img Yes Yes Yes Yes Yes Yes img img Yes img img [Go](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Go - Compiler"%2C "Go - Library") and status not in (fixed%2C resolved%2C closed))
Haskell 0.5.0 Yes Yes 7.10.3 8.0.2 img Yes Yes img Yes Yes Yes img Yes img Yes Yes Yes img img img Yes Yes img [Haskell](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Haskell - Compiler"%2C "Haskell - Library") and status not in (fixed%2C resolved%2C closed))
Haxe 0.9.3 Yes img 3.2.1 3.4.4 img Yes img img Yes img Yes img Yes img Yes Yes Yes Yes img img Yes img img [Haxe](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Haxe - Compiler"%2C "Haxe - Library") and status not in (fixed%2C resolved%2C closed))
Java (SE) 0.2.0 Yes Yes 1.8.0_151 11.0.3 img Yes Yes img Yes Yes Yes img Yes Yes Yes Yes Yes Yes img Yes Yes Yes Yes [Java SE](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Java - Compiler"%2C "Java - Library") and status not in (fixed%2C resolved%2C closed))
Java (ME) 0.5.0 img img unknown img img Yes img Yes Yes img img Yes img Yes img Yes img img img img img img [Java ME](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("JavaME - Compiler"%2C "JavaME - Library") and status not in (fixed%2C resolved%2C closed))
Javascript 0.3.0 Yes img ES5 ES6 img img img img Yes Yes img img Yes img img img Yes Yes img img img img img [Javascript](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Javascript - Compiler"%2C "Javascript - Library") and status not in (fixed%2C resolved%2C closed))
Lua 0.9.2 Yes img 5.1.5 5.2.4 img img Yes img Yes img Yes img Yes img Yes Yes Yes img img img Yes img img [Lua](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Lua - Compiler"%2C "Lua - Library") and status not in (fixed%2C resolved%2C closed))
node.js 0.6.0 Yes img 6.x 10.x Yes img img img Yes Yes Yes Yes Yes img Yes Yes Yes Yes img img Yes img img [node.js](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Node.js - Compiler"%2C "Node.js - Library") and status not in (fixed%2C resolved%2C closed))
node.ts 0.12.0 Yes img 3.1.6 img img img img Yes Yes img img img img Yes img img img img img Yes img img [node.ts](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("TypeScript - Library") and status not in (fixed%2C resolved%2C closed))
OCaml 0.2.0 img img 4.04.0 img img img img Yes img Yes img img img Yes img img img img img Yes Yes img [OCaml](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("OCaml - Compiler"%2C "OCaml - Library") and status not in (fixed%2C resolved%2C closed))
Perl 0.2.0 Yes img 5.22.1 5.26.1 Yes img Yes img Yes Yes Yes img Yes img Yes img Yes Yes Yes img Yes img img [Perl](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Perl - Compiler"%2C "Perl - Library") and status not in (fixed%2C resolved%2C closed))
PHP 0.2.0 Yes img 7.0.22 7.2.19 img img Yes img Yes Yes Yes img Yes img Yes Yes Yes Yes Yes img Yes img img [PHP](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("PHP - Compiler"%2C "PHP - Library") and status not in (fixed%2C resolved%2C closed))
Python 0.2.0 Yes Yes 2.7.12, 3.5.2 2.7.15, 3.6.8 img img img img Yes Yes img Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes img img [Python](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Python - Compiler"%2C "Python - Library") and status not in (fixed%2C resolved%2C closed))
Ruby 0.2.0 Yes img 2.3.1p112 2.5.1p57 Yes img Yes img Yes Yes Yes img Yes img Yes Yes Yes Yes img Yes Yes Yes Yes [Ruby](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Ruby - Compiler"%2C "Ruby - Library") and status not in (fixed%2C resolved%2C closed))
Rust 0.11.0 Yes img 1.35.0 1.35.0 img img Yes img Yes img Yes img img img Yes Yes img Yes img img img Yes img [Rust](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Rust - Compiler"%2C "Rust - Library") and status not in (fixed%2C resolved%2C closed))
Smalltalk 0.2.0 img img unknown img img img img Yes img img img img img Yes img img img img img img img img [Smalltalk](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Smalltalk - Compiler"%2C "Smalltalk - Library") and status not in (fixed%2C resolved%2C closed))
Swift 0.12.0 Yes img 4.2.1 img Yes Yes img Yes Yes Yes img Yes img Yes Yes img Yes img img img img Yes [Swift](https://issues.apache.org/jira/issues/?jql=project %3D THRIFT AND component in ("Swift - Compiler"%2C "Swift - Library") and status not in (fixed%2C resolved%2C closed))
Language Since autoconf cmake Min Max Domain File Memory Pipe Socket TLS Framed Header http zlib Binary Compact JSON Multiplex Forking Nonblocking Simple Threaded ThreadPool Open Issues

二,編解碼協議不一樣

對比xml,json ,thrift 和pb 相差比較大。git

  • 編碼方式不一樣github

    xml,json 採用文本方式編碼,thrift 和pb能夠支持二進制編碼golang

  • idlweb

    經過idl ,能夠方便客戶端和服務端維護數據結構,統一輩子成,項目很大後,維護成本下降objective-c

  • 效率apache

    由於編碼方式和實現不一樣,大體可認爲TCompactProtocol和pb 性能至關,優於json 和xml,但具體數據類型會影響性能之間的差距,好比double 類型數據json 編解碼特別差。有篇文章能夠參考:https://www.infoq.cn/article/json-is-5-times-faster-than-protobuf

三,傳輸協議不一樣

傳輸層,grpc 使用http2, thrift 支持Tsocket, TFramedTransport, TFileTransport, TZlibTransport 等多種自定義tcp層傳輸方式。

四,如何選擇?

  • 技術棧是很是重要的因素,多語言特別有php,可能選擇thrift 比較合適。
  • 若是要支持http2,grpc 是比較合適。
  • grpc 有更完善的示例。
  • thrift 相比grpc 更文檔。
相關文章
相關標籤/搜索