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
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
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
1
150
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
AIが無かった頃の素敵な出会いの話
codmoninc
1
190
1年で人数1.5倍、PR数5.5倍増。 品質とアウトカムはどうなったか、 何が効いたか
ike002jp
0
140
Android CLI
fornewid
0
100
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.9k
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
8
5.2k
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
540
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.7k
鹿野さんに聞く!『TypeScriptコードレシピ集』で磨く実践力
tonkotsuboy_com
4
1.1k
音楽のための関数型プログラミング言語mimiumにおける多段階計算の活用
tomoyanonymous
1
350
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
410
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.4k
The Pragmatic Product Professional
lauravandoore
37
7.4k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
For a Future-Friendly Web
brad_frost
183
10k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.6k
A Soul's Torment
seathinner
6
3.1k
Designing Powerful Visuals for Engaging Learning
tmiket
1
450
4 Signs Your Business is Dying
shpigford
187
22k
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