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
79
47k
PipeCDプラグインへの期待 / Anticipating PipeCD Plugins
atty303
0
120
EmscriptenでC/C++アプリをWASM化してブラウザで動かしてみた
atty303
0
660
良いソフトウェアとコードレビュー / 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
810
もう一つのビルドツール 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
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
200
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
CSC307 Lecture 17
javiergs
PRO
0
320
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.1k
RTSPクライアントを自作してみた話
simotin13
0
610
Observability in Practice:Grafana 與 Edge Device SRE 的那些事
blueswen
0
160
New "Type" system on PicoRuby
pocke
1
930
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
5k
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
180
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
510
Agentic UI
manfredsteyer
PRO
0
160
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Featured
See All Featured
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
430
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
300
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Mobile First: as difficult as doing things right
swwweet
225
10k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
Tell your own story through comics
letsgokoyo
1
950
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Invisible Side of Design
smashingmag
302
52k
A Tale of Four Properties
chriscoyier
163
24k
How to train your dragon (web standard)
notwaldorf
97
6.7k
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