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
AWS Media Services 最新サービスアップデート 2024
eijikominami
0
190
VideoMamba: State Space Model for Efficient Video Understanding
chou500
0
190
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
180
B2B SaaS × AI機能開発 〜テナント分離のパターン解説〜 / B2B SaaS x AI function development - Explanation of tenant separation pattern
oztick139
2
220
AIチャットボット開発への生成AI活用
ryomrt
0
170
OCI Network Firewall 概要
oracle4engineer
PRO
0
4.1k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
300
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
5
470
隣接領域をBeyondするFinatextのエンジニア組織設計 / beyond-engineering-areas
stajima
1
270
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
510
Featured
See All Featured
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
24k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Building Your Own Lightsaber
phodgson
103
6.1k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Facilitating Awesome Meetings
lara
50
6.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Rails Girls Zürich Keynote
gr2m
94
13k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Automating Front-end Workflow
addyosmani
1366
200k
Faster Mobile Websites
deanohume
305
30k
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/