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
Clientから見るFinagle
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
AGAWA Koji
April 01, 2016
Programming
2.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Clientから見るFinagle
AGAWA Koji
April 01, 2016
More Decks by AGAWA Koji
See All by AGAWA Koji
Software Architecture in an AI-Driven World
atty303
80
47k
PipeCDプラグインへの期待 / Anticipating PipeCD Plugins
atty303
0
130
EmscriptenでC/C++アプリをWASM化してブラウザで動かしてみた
atty303
0
680
良いソフトウェアとコードレビュー / Good software and code review
atty303
38
18k
Scala + Caliban で作るGraphQL バックエンド / Making GraphQL Backend with Scala + Caliban
atty303
0
600
Scala.jsとAndroidでドメイン層を共有しよう / Scala.js and Android
atty303
0
820
もう一つのビルドツール mill で作る Docker イメージ / Build docker image with mill the yet another build tool
atty303
2
2.6k
Case of Ad Delivery System is Implemented by Scala and DDD
atty303
4
3.7k
ログのメトリックを取ってみる話
atty303
0
1k
Other Decks in Programming
See All in Programming
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
9.3k
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
えっ!!コードを読まずに開発を!?
hananouchi
0
230
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
540
【やさしく解説 設計編・中級 #4】ルールの寿命と、システムの年輪
panda728
PRO
2
160
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
900
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
500
Foundation Models frameworkで画像分析
ryodeveloper
1
130
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
AIを活用したE2Eテスト実装効率化のあゆみ / ebisu-mobile-14-kotetu
kotetuco
0
180
광주소프트웨어마이스터고등학교 DevFest 특강 - 바이브 코딩 시대에서 주니어 개발자로 살아남는 방법
utilforever
1
150
Featured
See All Featured
How to Talk to Developers About Accessibility
jct
2
420
Into the Great Unknown - MozCon
thekraken
41
2.6k
Odyssey Design
rkendrick25
PRO
2
730
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
350
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
770
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
We Are The Robots
honzajavorek
0
280
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
420
Transcript
Client ͔ΒݟΔ Finagle
Finagle? 4 ϑΟωʔάϧ 4 Twitter 4 ϓϩτίϧதཱͳ RPC ϑϨʔϜϫʔΫ
ϓϩτίϧதཱ 4 Finagle ʮRPC ࣮ʯͦͷͰ Ͱͳ͍ 4 Apache Thrift 4
Apache Avro 4 Google Protocol Buffer
Bulitin protocols Server and Client 4 HTTP 4 Thrift Client
only 4 MySQL 4 Redis 4 Memcached
Microservice built with Fiangle
Your Server as a Function 1 type Service[Req, Rep] =
Req => Future[Rep] 4 αʔό͜ͷؔΛ࣮͢Δ 4 ΫϥΠΞϯτ͜ͷؔΛར༻͢Δ 1 https://monkey.org/~marius/funsrv.pdf
؆୯ͳ HTTP αʔό val service = new Service[http.Request, http.Response] {
def apply(req: http.Request): Future[http.Response] = { req.path match { case "/hello" => Future.value(http.Response(Status.OK, "world")) case _ => Future.value(http.Response(Status.NotFound)) } } } Await.ready(Http.server.serve(":80", service)) 4 αʔό Service Λ࣮͢Δ 4 τϥϯεϙʔτΛҙࣝ͢Δͷ serve ͢Δͱ͖͚ͩ
HTTP ΫϥΠΞϯτ val client: Service[http.Request, http.Response] = Http.client.newService("example.com:80") val f:
Future[http.Response] = client(http.Request("/hello")) 4 ΫϥΠΞϯτ Service Λੜͯ͠ apply ͢Δ 4 τϥϯεϙʔτΛҙࣝ͢Δͷ Service Λੜ͢Δͱ͖ͩ ͚
Your Server as a Function
Thrift ͷ߹ service LoggerService { string log(1: string message, 2:
i32 logLevel); i32 getLogSize(); } 4 RPC ͷΠϯλʔϑΣΠεΛ IDL Ͱఆٛ 4 Scrooge (ίʔυδΣωϨʔλ)͕ίʔυੜ
Thrift Server val iface = new LoggerService[Future] { def log(message:
String, loglevel: Int): Future[String] = ??? def getLogSize(): Future[Int] = ??? } Await.ready(Thrift.server.serveIface(":4000", iface)) 4 αʔό IDL ͷؔΛ࣮͢Δ
Thrift Client val iface = Thrift.client.newIface[LoggerService[Future]]("example.com:4000") val r: Future[String] =
iface.log("hello", 1) 4 ΫϥΠΞϯτ IDL ͷؔΛར༻Ͱ͖Δ
Your Server as a Function
͔͜͜Β Client ͷ 4 ͜Ε·Ͱʹ 1 ߦͰੜ͍ͯͨ͠ Client ͷߏ 4
෦࣮ͷͰͳ͍ 4 ͲΜͳ͜ͱΛͬͯ͘ΕΔͷ͔?
Finagle client stack
ελοΫͷߏ 1. client stack 4 ໊લղܾͱ load balancing 2. endpoint
stack 4 circuit breaker ͱ connection pooling 3. connection stack 4 connection ϥΠϑαΠΫϧཧ 4 wire protocol ͷ࣮
ελοΫ 4 client stack module ΛੵΈ্͛ͨͷ 4 client ͷ࡞࣌ʹΧελϚΠζͰ͖Δ
4 module ͷύϥϝʔλมߋ 4 stack ͷߏมߋ(module Λൈ͘ͳͲ)
[Client] Observe 4 StatsReceiver - ౷ܭσʔλͷड৴ 4 σϑΥϧτͳ͠ 4 Monitor
- ະॲཧྫ֎ͷϋϯυϦϯά 4 σϑΥϧτ printStackTrace 4 Trace - ϦΫΤετ 4 Zipkin
[Client] Retries 4 ϦΫΤετͷࣦഊΛϦτϥΠ 4 σϑΥϧτͰύέοτΛૹΔલͷࣦഊΛϦτϥΠ 4 ϦτϥΠ͕͠ͳ͍Α͏ʹ RetryBudget ͱ
Backoff Ͱίϯτϩʔ ϧ 4 RetryBudget - ϦτϥΠʹׂΓͯΔϦΫΤετྔ 4 Stream[Duration] - Backoff (ϦτϥΠִؒ) 4 σϑΥϧτͰ࠷ 10 retry/sec ɺ࠷େͰશϦΫΤετͷ 20% Λଈ࣌ (Backoff ͳ͠)ͰϦτϥΠׂΓͯ
[Client] Session Timeouts 4 Session Timeout 4 Service/Session ͕ར༻ՄೳʹͳΔ·Ͱͭ࣌ؒ 4
ྫ) connection pool ͕ۭ͖Λͭ࣌ؒ 4 Request Timeout 4 request Λૹ৴͔ͯ͠Β server ͷԠΛͭ࣌ؒ
[Client] Request Draining 4 Client ͷ close ࣌ʹ࣮ߦதͷ Request ͕ྃ͢ΔͷΛ
ͭ
[Client] Load Balancer 4 ෳͷ endpoint ͷͲΕ͔Λબ͢Δ 4 ޭͷ࠷େԽͱϨΠςϯγ࠷খԽͷͨΊʹ࠷దԽ͢Δ 4
load balancer 4 load metric -- endpoint ͕ෛՙσʔλΛఏڙ͢Δ 4 distributor -- ෛՙσʔλΛͱʹࢄ͢Δ 4 σϑΥϧτ P2C ΞϧΰϦζϜͰͬͱෛՙͷ͍ endpoint Λબ͢Δ
Finagle client stack - Endpoint
[Endpoint] Resolver 4 Endpoint ͷϦετ Resolver ͕ܾఆ͢Δ 4 ϦετΛಈతʹมߋ͢Δ͜ͱͰ͖Δ 4
୯ʹෳࢦఆ 4 "1.example.com:80,2.example.com:80" 4 DNS ͷෳ A Ϩίʔυ 4 roundrobin.example.com:80 4 ZooKeeper 4 zk!zk.local:2181/path/to/serverset
[Endpoint] Failure Accrual 4 Request ϕʔεͷ circuit breaker Ͱ open
͢Δͱ Load balancing ͷର֎ʹͳΔ 4 ࣌ؒΟϯυͰͷϦΫΤετޭ͕ᮢΛԼճΔͱ open 4 ࿈ଓͯ͠ n ճϦΫΤετ͕ࣦഊ͢Δͱ open
[Endpoint] Pool 4 ͍ΘΏΔ connection pool 4 ͍͔ͭ͘ͷ࣮͕͋Δ 4 SingletonPool
- 1ଓ͚ͩ(Mux) 4 BufferingPool 4 WatermarkPool 4 CachingPool
[Endpoint] Fail Fast 4 Connection ϕʔεͷ circuit breaker 4 ଓ͕Εͨͱ͖
open ͢Δ 4 ཪͰଓΛϦτϥΠͯ͠ܨΕ close
[Connection] Expiration 4 ଓͷ༗ޮظؒΛ੍ݶ 4 maxLifeTime -- connection ͷ࠷େੜଘ࣌ؒ 4
maxIdleTime -- connection ͷ࠷େΞΠυϧ࣌ؒ
·ͱΊ 4 Load Balancer ͱ Endpoint Resolver ͷΈ߹Θ͕ͤڧྗ 4 Service
Discovery ͱΈ߹ΘͤΕઐ༻ LB ͕ෆཁʹͳΔ 4 ϦΫΤετͷৄࡉΛ͍ͬͯΔͷͰޮతͳ Balancing ͕ Ͱ͖Δ 4 ଞʹݎ࿚ͳ client Λ࡞ΔͨΊʹඞཁͳͷ͕٧·͍ͬͯΔ 4 server Λ࣮͢ΔϑϨʔϜϫʔΫͨ͘͞Μ͋Δ͕ Finagle client ·Ͱ໘ΛݟΔ
Next ? 4 High-performance RPC with Finagle/ThriftMux