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
670
良いソフトウェアとコードレビュー / 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
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.8k
AI駆動開発を妨げる技術的負債の解消アプローチ / ai-refactoring-approach
minodriven
17
8.8k
SREの積み重ねがAI駆動開発のガードレールになった ― 7つの実践/SRE Guardrails The 7
tomoyakitaura
7
3.3k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
840
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
これからAgentCoreを触る方へトレンドはGatewayです
har1101
6
480
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
350
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
15
3.1k
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
580
どこまでゆるくて許されるのか
tk3fftk
0
450
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.4k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.7k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
610
Mozcon NYC 2025: Stop Losing SEO Traffic
samtorres
1
280
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Utilizing Notion as your number one productivity tool
mfonobong
4
350
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
How STYLIGHT went responsive
nonsquared
100
6.2k
Are puppies a ranking factor?
jonoalderson
1
3.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