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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
680
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
270
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
770
New "Type" system on PicoRuby
pocke
1
930
肥大化するレガシーコードに立ち向かうためのインターフェース分離と依存の逆転 / JJUG CCC 2026 Spring
hirokunimaeta
0
560
Even G2とAWSで推しのエージェントを召喚しよう!
har1101
1
120
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
260
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
240
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.6k
Webフレームワークの ベンチマークについて
yusukebe
0
170
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3.4k
Raft: Consensus for Rubyists
vanstee
141
7.5k
Become a Pro
speakerdeck
PRO
31
6k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
65
55k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.1k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
Claude Code のすすめ
schroneko
67
230k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
150
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
590
A designer walks into a library…
pauljervisheath
211
24k
The SEO identity crisis: Don't let AI make you average
varn
0
490
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