View
770
Download
0
Category
Preview:
DESCRIPTION
Introduction to Finagle
Citation preview
Introduction to Finagle
@
puneet@twitter.com
Core Services - Platform Engineering
In the beginning ...
A brave new world ...
TypesafeExpressivePerformant
(thank you JVM)...
Futures
Synchronous Futures
def piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int]
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
Synchronous Futures
Synchronous Futuresdef piDigit ( n : Int ) : Int def piDigit ( n : Int ) : Future[Int]
println ( piDigit ( 100 ) ) piDigit ( 100 ) onSuccess println
println ( piDigit ( 100 ) * 10 ) ) piDigit ( 100 ) map { _ * 10 } onSuccess println
println ( piDigit ( piDigit ( 100 ) ) ) piDigit ( 100 ) flatMap piDigit onSuccess println
println ( ( 0 to 100 ) map piDigit ) Future.collect {
( 0 to 100 ) map piDigit
} onSuccess println
Address resolution
TCP handshake
Serialization => Deserialization
the networking glue ...
: Request => Future [ Response ]
trait UserService {def getByUserId( userId : Long ) : Future [ User ]def getByScreenName( screenName: String ) : Future [ User ]
}
trait TweetService {def findByUserId( userId : Long ) : Future [ Seq[ Tweet ] ]
}
trait UserTweetService {val userService : UserServiceval tweetService : TweetService
def findUserAndTweets(userId : Long
) : Future [ ( User, Seq[Tweet] ) ] = Future.join (
userService.findByUserId( userId ), tweetService.findByUserId( userId )
)
}}
1
2 3 2 3
4
trait ScreenNameTweetService {val userService : UserServiceval tweetService : TweetService
def findByScreenName(screenName: String
) : Future [ Seq[Tweet] ] = {
userService.findByScreenName( screenName ) flatMap {user => tweetService.findByUserId( user.id )
}
}}
1
2 3 4 5
6
other benefits ...
val someService = Http.client(“inet!google.com:80”)
val anotherService =Http.client(
“zk!myzkhost.mycompany.com:2181!/my/zk/path”)
Address Resolution
Source Load Balancing
vs
Thanks!
twitter.github.io/finagle@finagle@pzdk
Recommended