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.8k
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
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
130
Google Cloud で始める Cloud Run 〜AWSとの比較と実例デモで解説〜
risatube
PRO
0
100
Opcodeを読んでいたら何故かphp-srcを読んでいた話
murashotaro
0
230
AI時代のデータセンターネットワーク
lycorptech_jp
PRO
1
280
大幅アップデートされたRagas v0.2をキャッチアップ
os1ma
2
530
UI State設計とテスト方針
rmakiyama
2
580
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
.NET 9 のパフォーマンス改善
nenonaninu
0
900
10個のフィルタをAXI4-Streamでつなげてみた
marsee101
0
170
新機能VPCリソースエンドポイント機能検証から得られた考察
duelist2020jp
0
220
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
110
私なりのAIのご紹介 [2024年版]
qt_luigi
1
120
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Six Lessons from altMBA
skipperchong
27
3.5k
For a Future-Friendly Web
brad_frost
175
9.4k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
How GitHub (no longer) Works
holman
311
140k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
520
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
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/