SlideShare a Scribd company logo
1 of 75
Download to read offline
Finagle: Twitter’s RPC Library 
24 Oct. 2014 
Steve Gury 
@stevegury
> whoami 
stevegury 
2005 2008 2011 2014 time 
Distributed Systems 
Massively Multiplayer Online Games 
Twitter 
Scala
Agenda 
1. Motivation 
2.Finagle TL;DR 
3.Three Key Abstractions 
4.Finagle Big Picture
Motivation & Context 
2006 2010 2014 
>2M Tweets / day 
(January 2009) 
>65M Tweets / day 
(July 2010) 
>500M Tweets / day 
(August 2013)
Agenda 
1. Motivation 
2.Finagle TL;DR 
3.Three Key Abstractions 
4.Finagle Big Picture
Finagle TL;DR 
Compose RPC like you 
compose functions
Composing Functions 
getUserId(name: String): Int getTweets(userId: Int): Tweets 
getTweets(name: String): Tweets 
= getUserId ◦ getTweets (name)
Agenda 
1. Motivation 
2.Finagle TL;DR 
3.Three Key Abstractions 
4.Finagle Big Picture
Futures 
Futures are containers for value 
Pending Successful Failed 
Present
Futures 
a 
val a: Future[Int]
Futures 
a 
b 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 }
Futures 
a 
b 
c 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x }
Futures 
a 
b 
c 
d 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c)
Futures 
a 
b 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 b 
a 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 b 
a 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
4 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
4 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
4 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
4 
(528, 
4) 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 
4 
(528, 
4) 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
16 
a 
528 
b 532 
4 
(528, 
4) 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
0 b 
a 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
0 
a 
512 
b 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
0 
a 
512 
b 
Ex 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
0 
a 
512 
b Ex 
Ex 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
0 
a 
512 
b Ex Ex 
Ex 
c 
d e 
val a: Future[Int] 
val b: Future[Int] = a map { x => x + 512 } 
val c = a map { x => 64 / x } 
val d = Future.join(b,c) 
val e = d map { case (x, y) => x + y }
Futures 
Lots of combinators: 
! 
map -> add an edge+node in the graph 
flatMap -> combine two graphs together 
handle -> deal with exceptions 
join -> merge multiple nodes of the graphs 
select -> select the first node with a value 
! 
…more
Programming with Futures == Building a Graph
Service 
Remember the key idea: treat RPC like functions
Service 
Service is a Function from Request to Response 
! 
trait Service[Request, Response] {! 
def apply(req: Request): Response! 
}! 
! 
Equivalent to Scala’s Function1: Request=>Response
Service 
But it has to be asynchronous, and treat exception as 
value 
! 
trait Service[Request, Response] {! 
def apply(req: Request): Future[Response]! 
}! 
!
Service 
It also has to be closable for proper management of 
resources. 
! 
trait Service[Request, Response] {! 
def apply(req: Request): Future[Response]! 
def close(): Future[Unit]! 
}!
ServiceFactory 
Factory of Service 
(Function that returns a Function)
ServiceFactory 
Function that asynchronously returns a Service 
! 
trait ServiceFactory[Req, Rep] {! 
def apply(): Future[Service[Req, Rep]]! 
def close(): Future[Unit]! 
}
Agenda 
1. Motivation 
2.Finagle TL;DR 
3.Three Key Abstractions 
4.Finagle Big Picture
Transport 
trait Transport[In, Out] { 
def write(req: In): Future[Unit] 
def read(): Future[Out] 
} 
Transport
Dispatcher 
class Dispatcher[A, B] extends Service[…] { 
def apply(req: A): Future[B] 
} 
Dispatcher Transport
Connection Pool 
class ConnPool[A,B] extends ServiceFactory[…]{ 
def apply(): Future[Service[A, B]] 
} 
Connection Dispatcher Transport 
Pool
Load Balancer 
class LoadBalancer[A,B] extends ServiceFactory[…]{ 
def apply(): Future[Service[A, B]] 
} 
Connection Dispatcher Transport 
Pool 
Load 
Balancer
Finagle in Action 
Connection Dispatcher Transport 
Pool 
Load 
Balancer 
val req: Request 
loadbalancer() // LB select an host 
// Pool select a connection
Finagle in Action 
val req: Request 
loadbalancer() flatMap { 
service => // LBService(PoolService(disp)) 
} 
Connection Dispatcher Transport 
Pool 
Load 
Balancer
Finagle in Action 
val req: Request 
loadbalancer() flatMap { 
service => // LBService(PoolService(disp)) 
service(req) // disp write req on Transp. 
} 
Connection Dispatcher Transport 
Pool 
Load 
Balancer
Finagle in Action 
val req: Request 
loadbalancer() flatMap { 
service => // LBService(PoolService(disp)) 
service(req) ensure { 
service.close() // close LBService 
// close PoolService 
} 
} 
Connection Dispatcher Transport 
Pool 
Load 
Balancer
FactoryToService 
class FactoryToService[A, B](factory: ServiceFactory[A, B]) 
extends Service[A, B] 
{ 
def apply(request: A): Future[B] = 
factory() flatMap { service => 
service(request) ensure { 
service.close() 
} 
} 
} 
Connection Dispatcher Transport 
Pool 
Load 
Balancer 
FactoryTo 
Service
Connection Dispatcher Transport 
Pool 
Load 
Balancer 
Finagle is “just” a composition of independent 
functions on top of a Transport 
FactoryTo 
Service
The “Simplified” Full Picture 
Stats 
Timeout 
Draining 
Load Balancer 
Monitor 
Stats 
Failure accrual 
Timeout 
Conn. Pool 
Expiration Dispatcher 
ServiceFactory 
Service
The Stack is configured for you 
You rarely have to configured the stack, we have a series 
of predefined stack for you. 
! 
scala> val client: ServiceFactory[Req, Res] = Http.client! 
.newClient(“localhost:8080")! 
!
The Stack is configured for you 
You rarely have to configured the stack, we have a series 
of predefined stack for you. 
! 
scala> val client: Service[Req, Res] = Http.client! 
.newClient(“localhost:8080")! 
.toService! 
scala> client(req)!
The Stack is configured for you 
You rarely have to configured the stack, we have a series 
of predefined stack for you. 
! 
scala> val client: Service[Req, Res] = Http.client! 
.configured(DefaultPool.Param(5, 10, 0, 1.minute, 100))! 
.newClient(“localhost:8080")! 
.toService! 
scala> client(req)! 
! 
You can configure any layer of the Stack
Finagle is doing more… 
• Load balancing 
• Connection pooling and request buffering 
• Dynamic membership (Zookeeper) 
• Failure detection and mitigation (fail-fast & failure 
accrual) 
• Statistics for visibility 
• Distributed tracing (Zipkin) 
• Cancellation propagation 
• Automatic retrying 
• Graceful shutdown and request draining 
• GC avoidance - traffic shaping 
• Backup requests
Load balancing
Load balancing 
1 
0 
0 
10
Load balancing 
1 
10 
0
Load balancing 
24 
25 
22 
0
A Better Load Balancer 
Key idea: Use history of recorded latencies to estimate 
the “cost” of sending a request to a server
Experimental Latencies
A better Load Balancer 
First idea: calculate an average of the latencies
Experimental Latencies
A better Load Balancer 
Better idea: calculate EWMA average of the latencies 
EWMA(n+1) = EWMA(n) * ⍺ + (1 - ⍺) * Xn+1
Experimental Latencies
A better Load Balancer 
The devil is in the details 
! 
Recency of data: EWMA unevenly spaced t-Series 
EWMA(n+1) = EWMA(n) * e-td/Tau + (1 - e-td/Tau) * Xn+1 
No history: Initial cost=0 + Probation
Cost & Experimental Latencies
A Better Load Balancer 
The devil is in the details 
! 
Speed of convergence: Cost “rides the peaks” 
Outliers: Decaying cost
Cost & Experimental Latencies
A Better Load Balancer 
The devil is in the details 
! 
CPU intensive: “The Power of 2 Choices”
A Better Load Balancer 
“The Power of 2 Choices in Randomized Load Balancing” P.h.D 
Thesis of M. Mitzenmacher
Load balancing 
0 20 
0 
10 
0 
cost: 20ms 
cost: 10ms 
cost: 10ms
cost: 18ms 
Load balancing 
0 20 
0 
10 
0 
20ms 
cost: 10ms 
cost: 10ms
The “Simplified” Full Picture 
Stats 
Timeout 
Draining 
Load Balancer 
Monitor 
Stats 
Failure accrual 
Timeout 
Conn. Pool 
Expiration Dispatcher 
ServiceFactory 
Service
Finagle’s Architecture 
Experience from writing “large scale” software 
! 
Independent modules 
Simple contracts 
Powerful combinators
Conclusion 
• Finagle is a library that lets you treat RPC as functions 
• Finagle is itself composed of independent functions 
• Very widely used at Twitter, Foursquare, Tumblr, 
Pinterest, SoundCloud… 
• Protocol agnostic (thrift, http, redis, mysql…) 
Github: github.com/twitter/finagle 
“Your server as a Function” http://monkey.org/~marius/ 
funsrv.pdf
@finagle 
@stevegury

More Related Content

What's hot

Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics LabNeil Mathew
 
The Uncertain Enterprise
The Uncertain EnterpriseThe Uncertain Enterprise
The Uncertain EnterpriseClarkTony
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..Dr. Volkan OBAN
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignmentAbdullah Al Shiam
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsKandarp Tiwari
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manualVivek Kumar Sinha
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manualAnkit Kumar
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicalsManoj Chauhan
 
Deep learning study 3
Deep learning study 3Deep learning study 3
Deep learning study 3San Kim
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmKapil Pandit
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Dimitrios Platis
 
Parallel Prefix Adders Presentation
Parallel Prefix Adders PresentationParallel Prefix Adders Presentation
Parallel Prefix Adders PresentationPeeyush Pashine
 
Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Deepak Singh
 

What's hot (20)

Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics Lab
 
The Uncertain Enterprise
The Uncertain EnterpriseThe Uncertain Enterprise
The Uncertain Enterprise
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
Computer Graphics Lab File C Programs
Computer Graphics Lab File C ProgramsComputer Graphics Lab File C Programs
Computer Graphics Lab File C Programs
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Mosaic plot in R.
Mosaic plot in R.Mosaic plot in R.
Mosaic plot in R.
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
computer graphics practicals
computer graphics practicalscomputer graphics practicals
computer graphics practicals
 
Deep learning study 3
Deep learning study 3Deep learning study 3
Deep learning study 3
 
Wap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithmWap in c to draw a line using DDA algorithm
Wap in c to draw a line using DDA algorithm
 
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]Writing SOLID C++ [gbgcpp meetup @ Zenseact]
Writing SOLID C++ [gbgcpp meetup @ Zenseact]
 
Parallel Prefix Adders Presentation
Parallel Prefix Adders PresentationParallel Prefix Adders Presentation
Parallel Prefix Adders Presentation
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Reactive Collections
Reactive CollectionsReactive Collections
Reactive Collections
 
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
 
Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000Cbse question paper class_xii_paper_2000
Cbse question paper class_xii_paper_2000
 

Viewers also liked

Scaling PyData Up and Out
Scaling PyData Up and OutScaling PyData Up and Out
Scaling PyData Up and OutTravis Oliphant
 
Buzzwords Numba Presentation
Buzzwords Numba PresentationBuzzwords Numba Presentation
Buzzwords Numba Presentationkammeyer
 
Numba: Flexible analytics written in Python with machine-code speeds and avo...
Numba:  Flexible analytics written in Python with machine-code speeds and avo...Numba:  Flexible analytics written in Python with machine-code speeds and avo...
Numba: Flexible analytics written in Python with machine-code speeds and avo...PyData
 
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Intel® Software
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyTravis Oliphant
 

Viewers also liked (7)

Numba Overview
Numba OverviewNumba Overview
Numba Overview
 
Scaling PyData Up and Out
Scaling PyData Up and OutScaling PyData Up and Out
Scaling PyData Up and Out
 
PyData Paris 2015 - Track 3.3 Antoine Pitrou
PyData Paris 2015 - Track 3.3 Antoine PitrouPyData Paris 2015 - Track 3.3 Antoine Pitrou
PyData Paris 2015 - Track 3.3 Antoine Pitrou
 
Buzzwords Numba Presentation
Buzzwords Numba PresentationBuzzwords Numba Presentation
Buzzwords Numba Presentation
 
Numba: Flexible analytics written in Python with machine-code speeds and avo...
Numba:  Flexible analytics written in Python with machine-code speeds and avo...Numba:  Flexible analytics written in Python with machine-code speeds and avo...
Numba: Flexible analytics written in Python with machine-code speeds and avo...
 
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
Accelerate Your Python* Code through Profiling, Tuning, and Compilation Part ...
 
Numba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
 

Similar to Scala.io

Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleVladimir Kostyukov
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsFrançois Garillot
 
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_PresentDzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_PresentDžanan Bajgorić
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Ittay Dror
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Satalia
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJSKyung Yeol Kim
 
The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++Alexander Granin
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiInfluxData
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in SwiftNetguru
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksSeniorDevOnly
 
Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器vito jeng
 
Monadologie
MonadologieMonadologie
Monadologieleague
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordKit Eason
 
Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams Seiya Mizuno
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Ruslan Shevchenko
 
Language Language Models (in 2023) - OpenAI
Language Language Models (in 2023) - OpenAILanguage Language Models (in 2023) - OpenAI
Language Language Models (in 2023) - OpenAISamuelButler15
 

Similar to Scala.io (20)

Async Microservices with Twitter's Finagle
Async Microservices with Twitter's FinagleAsync Microservices with Twitter's Finagle
Async Microservices with Twitter's Finagle
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
Scala Collections : Java 8 on Steroids
Scala Collections : Java 8 on SteroidsScala Collections : Java 8 on Steroids
Scala Collections : Java 8 on Steroids
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_PresentDzanan_Bajgoric_C2CUDA_MscThesis_Present
Dzanan_Bajgoric_C2CUDA_MscThesis_Present
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)Functional Programming from OO perspective (Sayeret Lambda lecture)
Functional Programming from OO perspective (Sayeret Lambda lecture)
 
Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++Options and trade offs for parallelism and concurrency in Modern C++
Options and trade offs for parallelism and concurrency in Modern C++
 
Compose Async with RxJS
Compose Async with RxJSCompose Async with RxJS
Compose Async with RxJS
 
The present and the future of functional programming in c++
The present and the future of functional programming in c++The present and the future of functional programming in c++
The present and the future of functional programming in c++
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
Hidden Gems in Swift
Hidden Gems in SwiftHidden Gems in Swift
Hidden Gems in Swift
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 
Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器Quill - 一個 Scala 的資料庫存取利器
Quill - 一個 Scala 的資料庫存取利器
 
Monadologie
MonadologieMonadologie
Monadologie
 
F# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, HerefordF# Presentation for SmartDevs, Hereford
F# Presentation for SmartDevs, Hereford
 
Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams Connect S3 with Kafka using Akka Streams
Connect S3 with Kafka using Akka Streams
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 
Language Language Models (in 2023) - OpenAI
Language Language Models (in 2023) - OpenAILanguage Language Models (in 2023) - OpenAI
Language Language Models (in 2023) - OpenAI
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 

Recently uploaded

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

Scala.io

  • 1. Finagle: Twitter’s RPC Library 24 Oct. 2014 Steve Gury @stevegury
  • 2. > whoami stevegury 2005 2008 2011 2014 time Distributed Systems Massively Multiplayer Online Games Twitter Scala
  • 3. Agenda 1. Motivation 2.Finagle TL;DR 3.Three Key Abstractions 4.Finagle Big Picture
  • 4. Motivation & Context 2006 2010 2014 >2M Tweets / day (January 2009) >65M Tweets / day (July 2010) >500M Tweets / day (August 2013)
  • 5. Agenda 1. Motivation 2.Finagle TL;DR 3.Three Key Abstractions 4.Finagle Big Picture
  • 6. Finagle TL;DR Compose RPC like you compose functions
  • 7. Composing Functions getUserId(name: String): Int getTweets(userId: Int): Tweets getTweets(name: String): Tweets = getUserId ◦ getTweets (name)
  • 8. Agenda 1. Motivation 2.Finagle TL;DR 3.Three Key Abstractions 4.Finagle Big Picture
  • 9. Futures Futures are containers for value Pending Successful Failed Present
  • 10. Futures a val a: Future[Int]
  • 11. Futures a b val a: Future[Int] val b: Future[Int] = a map { x => x + 512 }
  • 12. Futures a b c val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x }
  • 13. Futures a b c d val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c)
  • 14. Futures a b c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 15. Futures 16 b a c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 16. Futures 16 b a c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 17. Futures 16 a 528 b c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 18. Futures 16 a 528 b c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 19. Futures 16 a 528 b 4 c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 20. Futures 16 a 528 b 4 c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 21. Futures 16 a 528 b 4 c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 22. Futures 16 a 528 b 4 (528, 4) c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 23. Futures 16 a 528 b 4 (528, 4) c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 24. Futures 16 a 528 b 532 4 (528, 4) c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 25. Futures 0 b a c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 26. Futures 0 a 512 b c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 27. Futures 0 a 512 b Ex c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 28. Futures 0 a 512 b Ex Ex c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 29. Futures 0 a 512 b Ex Ex Ex c d e val a: Future[Int] val b: Future[Int] = a map { x => x + 512 } val c = a map { x => 64 / x } val d = Future.join(b,c) val e = d map { case (x, y) => x + y }
  • 30. Futures Lots of combinators: ! map -> add an edge+node in the graph flatMap -> combine two graphs together handle -> deal with exceptions join -> merge multiple nodes of the graphs select -> select the first node with a value ! …more
  • 31. Programming with Futures == Building a Graph
  • 32. Service Remember the key idea: treat RPC like functions
  • 33. Service Service is a Function from Request to Response ! trait Service[Request, Response] {! def apply(req: Request): Response! }! ! Equivalent to Scala’s Function1: Request=>Response
  • 34. Service But it has to be asynchronous, and treat exception as value ! trait Service[Request, Response] {! def apply(req: Request): Future[Response]! }! !
  • 35. Service It also has to be closable for proper management of resources. ! trait Service[Request, Response] {! def apply(req: Request): Future[Response]! def close(): Future[Unit]! }!
  • 36. ServiceFactory Factory of Service (Function that returns a Function)
  • 37. ServiceFactory Function that asynchronously returns a Service ! trait ServiceFactory[Req, Rep] {! def apply(): Future[Service[Req, Rep]]! def close(): Future[Unit]! }
  • 38. Agenda 1. Motivation 2.Finagle TL;DR 3.Three Key Abstractions 4.Finagle Big Picture
  • 39. Transport trait Transport[In, Out] { def write(req: In): Future[Unit] def read(): Future[Out] } Transport
  • 40. Dispatcher class Dispatcher[A, B] extends Service[…] { def apply(req: A): Future[B] } Dispatcher Transport
  • 41. Connection Pool class ConnPool[A,B] extends ServiceFactory[…]{ def apply(): Future[Service[A, B]] } Connection Dispatcher Transport Pool
  • 42. Load Balancer class LoadBalancer[A,B] extends ServiceFactory[…]{ def apply(): Future[Service[A, B]] } Connection Dispatcher Transport Pool Load Balancer
  • 43. Finagle in Action Connection Dispatcher Transport Pool Load Balancer val req: Request loadbalancer() // LB select an host // Pool select a connection
  • 44. Finagle in Action val req: Request loadbalancer() flatMap { service => // LBService(PoolService(disp)) } Connection Dispatcher Transport Pool Load Balancer
  • 45. Finagle in Action val req: Request loadbalancer() flatMap { service => // LBService(PoolService(disp)) service(req) // disp write req on Transp. } Connection Dispatcher Transport Pool Load Balancer
  • 46. Finagle in Action val req: Request loadbalancer() flatMap { service => // LBService(PoolService(disp)) service(req) ensure { service.close() // close LBService // close PoolService } } Connection Dispatcher Transport Pool Load Balancer
  • 47. FactoryToService class FactoryToService[A, B](factory: ServiceFactory[A, B]) extends Service[A, B] { def apply(request: A): Future[B] = factory() flatMap { service => service(request) ensure { service.close() } } } Connection Dispatcher Transport Pool Load Balancer FactoryTo Service
  • 48. Connection Dispatcher Transport Pool Load Balancer Finagle is “just” a composition of independent functions on top of a Transport FactoryTo Service
  • 49. The “Simplified” Full Picture Stats Timeout Draining Load Balancer Monitor Stats Failure accrual Timeout Conn. Pool Expiration Dispatcher ServiceFactory Service
  • 50. The Stack is configured for you You rarely have to configured the stack, we have a series of predefined stack for you. ! scala> val client: ServiceFactory[Req, Res] = Http.client! .newClient(“localhost:8080")! !
  • 51. The Stack is configured for you You rarely have to configured the stack, we have a series of predefined stack for you. ! scala> val client: Service[Req, Res] = Http.client! .newClient(“localhost:8080")! .toService! scala> client(req)!
  • 52. The Stack is configured for you You rarely have to configured the stack, we have a series of predefined stack for you. ! scala> val client: Service[Req, Res] = Http.client! .configured(DefaultPool.Param(5, 10, 0, 1.minute, 100))! .newClient(“localhost:8080")! .toService! scala> client(req)! ! You can configure any layer of the Stack
  • 53. Finagle is doing more… • Load balancing • Connection pooling and request buffering • Dynamic membership (Zookeeper) • Failure detection and mitigation (fail-fast & failure accrual) • Statistics for visibility • Distributed tracing (Zipkin) • Cancellation propagation • Automatic retrying • Graceful shutdown and request draining • GC avoidance - traffic shaping • Backup requests
  • 57. Load balancing 24 25 22 0
  • 58. A Better Load Balancer Key idea: Use history of recorded latencies to estimate the “cost” of sending a request to a server
  • 60. A better Load Balancer First idea: calculate an average of the latencies
  • 62. A better Load Balancer Better idea: calculate EWMA average of the latencies EWMA(n+1) = EWMA(n) * ⍺ + (1 - ⍺) * Xn+1
  • 64. A better Load Balancer The devil is in the details ! Recency of data: EWMA unevenly spaced t-Series EWMA(n+1) = EWMA(n) * e-td/Tau + (1 - e-td/Tau) * Xn+1 No history: Initial cost=0 + Probation
  • 65. Cost & Experimental Latencies
  • 66. A Better Load Balancer The devil is in the details ! Speed of convergence: Cost “rides the peaks” Outliers: Decaying cost
  • 67. Cost & Experimental Latencies
  • 68. A Better Load Balancer The devil is in the details ! CPU intensive: “The Power of 2 Choices”
  • 69. A Better Load Balancer “The Power of 2 Choices in Randomized Load Balancing” P.h.D Thesis of M. Mitzenmacher
  • 70. Load balancing 0 20 0 10 0 cost: 20ms cost: 10ms cost: 10ms
  • 71. cost: 18ms Load balancing 0 20 0 10 0 20ms cost: 10ms cost: 10ms
  • 72. The “Simplified” Full Picture Stats Timeout Draining Load Balancer Monitor Stats Failure accrual Timeout Conn. Pool Expiration Dispatcher ServiceFactory Service
  • 73. Finagle’s Architecture Experience from writing “large scale” software ! Independent modules Simple contracts Powerful combinators
  • 74. Conclusion • Finagle is a library that lets you treat RPC as functions • Finagle is itself composed of independent functions • Very widely used at Twitter, Foursquare, Tumblr, Pinterest, SoundCloud… • Protocol agnostic (thrift, http, redis, mysql…) Github: github.com/twitter/finagle “Your server as a Function” http://monkey.org/~marius/ funsrv.pdf