Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GRPCの実践と現状での利点欠点 / Go Conference 2016 Spring
Search
kazegusuri
April 22, 2016
Technology
44
32k
GRPCの実践と現状での利点欠点 / Go Conference 2016 Spring
kazegusuri
April 22, 2016
Tweet
Share
More Decks by kazegusuri
See All by kazegusuri
go-sqlite3を使ってCloud Spannerエミュレーターを作ってみた / Cloud Spanner emulator with go-sqlite3
kazegusuri
5
6.4k
handy-spanner GCPUG
kazegusuri
4
1.7k
Open SKT: メルペイ開発の裏側 / builderscon tokyo 2019 Open SKT
kazegusuri
22
26k
Keep watching and extending features of gRPC
kazegusuri
3
2.4k
Testing with microservices in merpay
kazegusuri
10
10k
Real World Mercari API Architecture
kazegusuri
1
6k
gRPC and REST with gRPC in practice
kazegusuri
19
7.6k
Fluentdで始めるPrometheus / Prometheus Tokyo Meetup #1
kazegusuri
1
1.7k
OutputとBufferedOutputの間の何か
kazegusuri
2
3.1k
Other Decks in Technology
See All in Technology
20241120_JAWS_東京_ランチタイムLT#17_AWS認定全冠の先へ
tsumita
2
300
Engineer Career Talk
lycorp_recruit_jp
0
190
iOSチームとAndroidチームでブランチ運用が違ったので整理してます
sansantech
PRO
0
150
AIチャットボット開発への生成AI活用
ryomrt
0
170
心が動くエンジニアリング ── 私が夢中になる理由
16bitidol
0
100
OS 標準のデザインシステムを超えて - より柔軟な Flutter テーマ管理 | FlutterKaigi 2024
ronnnnn
0
190
Zennのパフォーマンスモニタリングでやっていること
ryosukeigarashi
0
140
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
【Startup CTO of the Year 2024 / Audience Award】アセンド取締役CTO 丹羽健
niwatakeru
0
1.3k
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
Platform Engineering for Software Developers and Architects
syntasso
1
520
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
229
18k
It's Worth the Effort
3n
183
27k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
What's in a price? How to price your products and services
michaelherold
243
12k
Done Done
chrislema
181
16k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Rails Girls Zürich Keynote
gr2m
94
13k
Transcript
GRPCͷ࣮ફͱ ݱঢ়Ͱͷརɾܽ @kazegusuri / Masahiro Sano Go Conference 2016 Spring
ࣗݾհ w ࠤਖ਼ߒ !LB[FHVTVSJ w 43&!.FSDBSJ *OD w #BDLFOE4ZTUFNXJUI(P
w 044ͷ׆ಈ w --7.ؔ࿈ w ,VCFSOFUFT w HSQDHBUFXBZ
Mercari Your Friendly Mobile Marketplace
ΞδΣϯμ w (31$ͱ w (13$ͷ͍ํ w ຊ൪ಋೖ·Ͱʹߦͬͨ͜ͱ w (31$ͷརͱܽ
GRPC w )551Λͬͨ൚༻తͳ31$ϑϨʔϜϫʔΫ w ݄ʹ(PPHMF͕ެ։ w 1SPUPDPM#V⒎FSͰΠϯλϑΣΠεΛఆٛ
GRPCͷ։ൃಈػ w 4UVCCZͱ͍͏31$Λ͍ͬͯͨ w ࣾγεςϜʹີ݁߹ w ಉҎ্ͷػೳ͕ඪ४ن֨Ͱग़͖ͯͨ w ϞόΠϧ*P5ɺΫϥυʹద༻ http://www.grpc.io/posts/principles
OSSͰͷ࠾༻ࣄྫ w 5FOTPS'MPX (PPHMF w DPOUBJOFSE %PDLFS w
FUDE $PSF04 w HJUIVCDPNHPLJULJU w ࠃاۀͰ࠾༻ྫଟ͍
GRPCͷ͍ํ w εςοϓ QSPUPఆٛΛॻ͘ QSPUP͔ΒHPΛੜ͢Δ ΠϯλϑΣΠεΛ࣮͢Δ
(31$αʔόΛىಈ͢Δ
protoఆٛΛॻ͘ w TFSWJDFʹNFUIPEΛ࣋ͨͤΔ w ೖग़ྗͷNFTTBHFΛࢦఆ syntax = “proto3"; package echo;
message EchoMessage { string msg = 1; } service EchoService { rpc Echo(EchoMessage) returns (EchoMessage) {} }
proto͔ΒgoΛੜ͢Δ w QSPUPDHP@PVUQMVHJOTHSQDFDIPQSPUP w NFTTBHFTUSVDUʹɺTFSWJDFJOUFSGBDFʹ type EchoMessage struct { Msg
string `protobuf:"bytes,1,opt,name=msg" json:"msg,omitempty"` } type EchoServiceServer interface { Echo(context.Context, *EchoMessage) (*EchoMessage, error) }
ΠϯλϑΣΠεΛ࣮͢Δ w &DIPؔΛ࣋ͭTUSVDUΛ࣮ w Τϥʔઐ༻ͷεςʔλεΛฦ͢ type EchoServer struct{} func (s
*EchoServer) Echo(ctx context.Context, in *pb.EchoMessage) (*pb.EchoMessage, error) { if in.Msg == "" { return nil, grpc.Errorf(codes.InvalidArgument, "message is empty") } return &pb.EchoMessage{ Msg: in.Msg, }, nil }
GRPCαʔόΛىಈ͢Δ w HSQD4FSWFSʹTFSWJDFΛొ w OFU-JTUFOFSΛͯ͠4FSWF func main() { echoServer :=
&server.EchoServer{} s := grpc.NewServer() pb.RegisterEchoServiceServer(s, echoServer) lis, _ := net.Listen("tcp", ":8080") s.Serve(lis) }
ຊ൪ಋೖ·Ͱʹߦͬͨ͜ͱ • ॲཧͷڞ௨Խ • Τϥʔॲཧ • ੑೳݕূ • ϦΫΤετࢄ •
grpc-gateway
ϦΫΤετॲཧͷϨΠϠԽ w શͯͷNFUIPEͰڞ௨ͷॲཧΛߦ͍͍ͨ w MPHHJOHೝূͳͲ w TFSWJDFͷΠϯλϑΣΠεΛ࣋ͭϋϯυϥΛ࡞ w IUUQͰͷ4FSWF)551Λఏڙ͢Δϋϯυϥ
ϦΫΤετϋϯυϥ w -PHHJOH)BOEMFS w *OTUSVNFOUBUJPO)BOEMFS w $SBTI)BOEMFS w "VUIFOUJDBUJPO)BOEMFS w
4FSWJDF)BOEMFS
Logging: ΞΫηεϩά w ֤छΛϩάʹอଘ w TFSWJDF໊NFUIPE໊ w ϦΫΤετ࣌ؒ w εςʔλείʔυͱΤϥʔϝοηʔδ
w ϦϞʔτΞυϨε w MPHHFSࣗલͰ࣮
Logging: ΞϓϦέʔγϣϯϩά w ΞϓϦέʔγϣϯϩάʹίϯςΩετΛՃ w TFSWJDFNFUIPE໊ɺ6TFS*%ͳͲ w HJUIVCDPNHPLJULJUMPH w HPMBOHPSHYOFUDPOUFYUʹMPHHFSΛηοτ
Instrumentation Handler w QSPNFUIFVT w JOTUSVNFOUBUJPOϥΠϒϥϦͱͯ͠ར༻ w ϦΫΤετճɾ࣌ؒΤϥʔճ w औಘͨ͠ϝτϦΫε)551Ͱఏڙ
Crash Handler w ϦΫΤετॲཧதͷQBOJDΛSFDPWFS w *OUFSOBMΤϥʔͱͯ͠ฦ͢ w ΞϓϦέʔγϣϯϩάʹελοΫτϨʔε w *OUFSOBMΤϥʔϩάࢹͰϞχλϦϯά
Authentication Handler w NFUBEBUBΛͬͨೝূ w ϢʔβใΛDPOUFYUʹηοτ w DSFEFOUJBMTͷػೳ͍ͬͯͳ͍
Τϥʔͷฦ͠ํ • Τϥʔ࣌message͕ฦͤͳ͍ • εςʔλείʔυͱΤϥʔϝοηʔδͷΈ return nil, grpc.Errorf(codes.InvalidArgument, "message is
empty") εςʔλείʔυ Τϥʔϝοηʔδ ແࢹ͞ΕΔ
Metadata w )FBEFSͱ5SBJMFS w ϦΫΤετ࣌)FBEFSͷΈ w Ϩεϙϯε࣌)FBEFSͱ5SBJMFS͕ར༻Մೳ w ৄࡉͳΤϥʔใ5SBJMFSΛར༻ md
:= metadata.Pairs( “error”, "ValidationError", “message", "message is empty") grpc.SetTrailer(md)
ύϑΥʔϚϯε w FDIPαʔόͰ,SFRT w MPHHJOHJOTUSVNFOUBUJPOؚΉ w ೝূ ॺ໊ݕূ Λ͍Εͯ,SFRT w
NT͔͔Βͳ͍ w %#ΞΫηεΛؚΉ࣮ࡍͷॲཧͰ,SFRT
ϩʔυόϥϯε w ෳαʔόʹϦΫΤετΛࢄ w )551ͷ··(31$αʔόʹ௨৴ w ϦΫΤετݩͷ*1ΞυϨεΛ͍ͨ͠
nginx TCP Load Balancing w OHJOY͔ΒTUSFBNNPEVMFΛαϙʔτ w VQTUSFBNʹ*1ΞυϨεΛ͢ͷ͕՝ w 9'PXBSEFE'PS
w 51SPYZ 5SBOTQBSFOU1SPYZ w 1309:QSPUPDPM
PROXY protocol w 5$1ϨϕϧͰ*1ΞυϨεͱϙʔτΛνΣΠϯ w ΫϥΠΞϯτଆͷରԠ͕ඞཁ w HPͰHJUIVCDPNBSNPOHPQSPYZQSPUP w OFU-JTUFOFSͷϥούʔͳͷͰ؆୯
list, err := net.Listen("tcp", "...") proxyList := &proxyproto.Listener{list} conn, err := proxyList.Accept()
grpc-gateway w +40/͔Β(31$ม͢ΔϦόʔεϓϩΩγ w QSPUP͔Βࣗಈੜ w 3&45"1*Λఏڙ͍ͨ͠߹ʹศར w ಛʹσόοάʹศར
grpc-gatewayͷఆٛํ๏ message SimpleMessage { string id = 1; } service
EchoService { rpc Echo(SimpleMessage) returns (SimpleMessage) { option (google.api.http) = { post: "/v1/example/echo/{id}" }; } rpc EchoBody(SimpleMessage) returns (SimpleMessage) { option (google.api.http) = { post: "/v1/example/echo_body" body: "*" }; } }
grpc-gateway w Կߟ͑ͳ͍ઃఆ͕͓͢͢Ί w 63-TFSWJDF໊NFUIPE໊ w NFTTBHFશ෦1045Ͱ͢ w ਏ͍ͱ͜Ζ͋Δ w
ϔομʔͱNFUBEBUBͷѻ͍ w QSPUPͰఆٛ͞ΕΔKTPO͕શͯPNJUFNQUZ
GRPCͷܽ w ϛυϧΣΞ͕ͳ͍ɺͦͦ࡞ΓͮΒ͍ w ΞΫηεϩάͳͲ w DVSM͕͑ͳ͍ w υΩϡϝϯτ͕গͳ͍ w
ιʔεΛಡΉͱ࣮͜Μͳػೳ͕ʜ w ݴޠຖͷػೳ͕ҧ͏
GRPCͷར w ࣮ʹूதͰ͖Δ w ϧʔςΟϯάɺFODEFD͕ࣗಈ w ΫϥΠΞϯτ͕࡞Γ͍͢ w ςετଟݴޠͷରԠ w
ܽͷ෦ͳΜͱ͔ͳΔ
GRPC݁ہ͓͢͢Ίͳͷ͔ʁ w ͔ͳΓ͓͢͢Ί w JOUFSDFQUPS͕ೖΕ΄΅՝ͳ͘ͳΔ w ϚΠΫϩαʔϏεͷ͓ڙʹ w ͏ී௨ͷ3&45"1*ʹΓͨ͘ͳ͍ w
+40/ʹରԠ͢ΔܕΛॻ͘ख͕ؒݮΔ w (31$͍͍ͧ
GoΤϯδχΞืूʂ Backend System Engineer https://www.mercari.com/jp/jobs/backend/