Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
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
6.1k
gRPC and REST with gRPC in practice
kazegusuri
19
7.7k
Fluentdで始めるPrometheus / Prometheus Tokyo Meetup #1
kazegusuri
1
1.7k
OutputとBufferedOutputの間の何か
kazegusuri
2
3.2k
Other Decks in Technology
See All in Technology
WED Company Deck for Engineer
wed
2
3.7k
データパイプラインをなんとかした話 / Improving the Data Pipeline in IVRy
mirakui
0
110
セキュリティ系アップデート全体像と AWS Organizations 新ポリシー「宣言型ポリシー」を紹介 / reGrowth 2024 Security
masahirokawahara
0
170
Password-less Journey - パスキーへの移行を見据えたユーザーの準備 @ AXIES 2024
ritou
2
840
MySQL 8.0 から PostgreSQL 16 への移行と RLS 導入までの道のりと学び
baseballyama
0
1k
TimeTreeが経た3つの転換点 ー プロダクト成長過程でその時、その瞬間、何を考えてたか
ysmtysts
1
3.7k
Autonomous Database サービス・アップデート (FY25)
oracle4engineer
PRO
0
270
Kaggleふりかえり会〜LLM 20 Questions & ISIC 2024
recruitengineers
PRO
2
190
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
52k
大規模サーバ移行を成功に導くための事前調査フェーズの工夫事例
fukuchiiinu
2
110
スパイクアクセス対策としての pitchfork 導入
riseshia
0
190
突き破って学ぶコンテナセキュリティ/container-breakout-cncj-lt
mochizuki875
6
1.1k
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
73
9.1k
Scaling GitHub
holman
458
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Side Projects
sachag
452
42k
Optimizing for Happiness
mojombo
376
70k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Writing Fast Ruby
sferik
627
61k
A Philosophy of Restraint
colly
203
16k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
160
Facilitating Awesome Meetings
lara
50
6.1k
GraphQLとの向き合い方2022年版
quramy
44
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/