grpc thrift 都是經常使用的rpc 框架,這裏對grpc 和 thrift 從幾個方面對二者進行對比php
grpc 和thrift 對不一樣語言支持度不同,相比而言 thrift 比grpc 支持度更廣,到底如何選擇rpc 框架須要結合公司技術棧來,好比php 不支持grpc 的server,全部有些公司只能用thrift 做爲公司的rpc 框架。java
其中grpc 支持11種語言,其中php 只支持client。node
src/cpp
directoryGrpc
grpc
go get google.golang.org/grpc
npm install grpc
gRPC-ProtoRPC
dependency to podspecpecl install grpc
pip install grpcio
gem install grpc
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 | FLEX SDK 4.6 | [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 | 2.48.2 | 2.56.4 | [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 | C++11 | [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 | .NET 3.5 / mono 3.2.8.0 | .NET 4.6.1 / mono 4.6.2.7 | [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 | SBCL 1.4.x | SBCL 1.5.3 | [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 | 2.075.1 | 2.087.0 | [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 | 2.0.0 | 2.4.0 | [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 | 2010 | unknown | [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 | 2.1.4 | 2.2.101 | [.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 | .NET 4.5+, .NET Standard 2.x | [.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 | 18.3 | 22.0 | [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 | 1.10.8 | 1.12.6 | [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 | 7.10.3 | 8.0.2 | [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 | 3.2.1 | 3.4.4 | [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 | 1.8.0_151 | 11.0.3 | [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 | unknown | [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 | ES5 | ES6 | [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 | 5.1.5 | 5.2.4 | [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 | 6.x | 10.x | [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 | 3.1.6 | [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 | 4.04.0 | [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 | 5.22.1 | 5.26.1 | [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 | 7.0.22 | 7.2.19 | [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 | 2.7.12, 3.5.2 | 2.7.15, 3.6.8 | [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 | 2.3.1p112 | 2.5.1p57 | [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 | 1.35.0 | 1.35.0 | [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 | unknown | [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 | 4.2.1 | [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層傳輸方式。