Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
atProductivity and Performance at Scale
You are a developer using Java tobuild web services.
This is your life:
Waiting. [1]
tail -f logs/catalina.out
XML soup
"Convenient proxy factory bean superclass for proxyfactory beans that create only singletons." [2]
Thread pool usageLatencyThread pool hell
There is a better way.
Ruby on Rails!
Nah, just kidding. We have real work to do.
A modern web framework for Java and Scala
The world’s largest professional network
atWeve been using Play in production formore than 6 months [3]
A few apps built on Play
Channels (frontend)
Premium Subscriptions (frontend)
Polls (frontend + backend)
REST search (internal tool)
About meLeading the Play project as part of LinkedIns Service Infrastructure Team.Also: hackdays, engineering blog, incuba...
This talk is the story of building web servicesat massive scale with Java and Scala...
... while maintaining performance,reliability, and developerproductivity.
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Download and install Play fromhttp://www.playframework.com
> play new my-app
> play idea> play eclipse
> play run
http://localhost:9000
Application layoutapp → Application sources└ assets → Compiled asset sources└ controllers → Application controllers└ model...
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
public class HelloWorld extends Controller {public static Result index() {return ok("Hello World");}}Create a new controll...
Dont worry about the use of static. Yes,Play supports IOC. Using static (and othershortcuts) lets me keep the examples sim...
GET /hello controllers.HelloWorld.index()Expose the controller/action at a URLconf/routes
Now, restart the server.
Nah, just kidding. Refresh the page.
Woohoo, hot reload!
http://localhost:9000/hello
public class HelloWorld extends Controller {public static Result index(String name) {return ok("Hello " + name);}}Add a pa...
GET /hello controllers.HelloWorld.index( name)Read the parameter from the query stringconf/routes
http://localhost:9000/hello?name=Jim
GET /hello/:name controllers.HelloWorld.index(name)Read the parameter from the URL insteadconf/routes
http://localhost:9000/hello/Jim
public class HelloWorld extends Controller {public static Result index(String name, int age) {return ok("Hello " + name + ...
GET /hello/:name/ :age controllers.HelloWorld.index(name: String, age: Int)Add the parameter. Note the type checking!conf/...
http://localhost:9000/hello/Jim/28
@(name: String, age: Int)<html><head></head><body><img src="/assets/images/play-logo.png"/><p>Hello <b>@name</b>, you are ...
public class HelloWorld extends Controller {public static Result index(String name, int age) {return ok(views.html.hello.r...
http://localhost:9000/hello/Jim/28
location = "JaxConf"How about some config?app/conf/application.conf
public class HelloWorld extends Controller {public static Result index(String name, int age) {String location = getConfig(...
@(name: String, age: Int, location: String)<html><head></head><body><img src="/assets/images/play-logo.png"/><p>Hello <b>@...
Refresh the page. Config hot reloads too!
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
In dev mode, Play shows error messagesright in the browser.
Parameter type checking
A helpful 404 page
Compile errors show problematic source codein the browser
Views are compiled as well
The routes file too
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Most people are used to threaded servers
Threaded servers assign one thread perrequest and use blocking I/Ovoid doGet(HttpServletRequest req, HttpServletResponse r...
Evented servers are gaining popularity
Evented servers have one thread/process perCPU core and use non-blocking I/OMyNodeApp.jsvar callback = function(data) {con...
Why threaded vs. evented matters forLinkedIn
LinkedIn uses a Service Oriented ArchitectureInternet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerB...
void doGet(HttpServletRequest req, HttpServletResponse res) {// Call a number of backend services to get dataProfile profi...
I/O is very expensive [4]
In a threaded server, threads spend most ofthe time idle, waiting on I/O
Threading dilemma1. Creating new threads on the fly is expensive:a. Use a thread pool2. Too many threads in the thread poo...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
Internet LoadBalancerFrontendServerFrontendServerFrontendServerBackendServerBackendServerBackendServerBackendServerBackend...
This is thread pool hell [5]
Play is built on top of Netty, so it supports non-blocking I/O [6]
NIO benefits1. No sensitivity to downstream slowness2. Easy to parallelize I/O3. Supports many concurrent and long-running...
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
public class Proxy extends Controller {public static Result index(String url) {// Non blocking HTTP callPromise<Response> ...
A Promise<T> will eventually contain thevalue T (or an error)
(Play Framework source code)Play has a built-in subclass of Result calledAsyncResult that takes a Promise<Result>public st...
public class Proxy extends Controller {public static Result index(String url) {// Non blocking HTTP callPromise<Response> ...
GET /proxy controllers.Proxy.index(url)Lets add this endpoint to the routes fileconf/routes
http://localhost:9000/proxy?url=http://example.com
We just built a completelynon-blocking proxy!
public class Proxy extends Controller {public static Result index(String url) {Logger.info("Before the HTTP call");Promise...
Refresh the page and the logs show theHTTP call really is non-blocking
NIO makes parallel requests easy.Lets try it.
class Timing {public String url;public long latency;public Timing(String url, long latency) {this.url = url;this.latency =...
public class Parallel extends Controller {public static Result index() {// A Promise that will redeem when the 3 parallel/...
GET /parallel controllers.Parallel.index()Add it to the routes fileconf/routes
http://localhost:9000/parallel
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Play has native support for Scala
app/controllers/HelloWorldScala.scalaJust add a .scala file under /app andPlay will compile itobject HelloWorldScala exten...
GET /scala controllers.HelloWorldScala.index()Add it to the routes file as usualconf/routes
http://localhost:9000/scala
Play/Scala: the good parts
Sequential async calls// 2 sequential async callsfor {foo <- WS.url(url1).get()bar <- WS.url(buildUrl(foo)).get()} yield {...
Interactive console with full classpath of your app
Play is Scala at its core: main libraries,routes, templates, SBT, etc [7]
Play/Scala: the less good parts
Simple Build Tool: Plays build system. Verypowerful, but very steep learning curve.
project/Build.scalaval settings = Seq(bootPath <<= target( _ / "boot" ),buildDir <<= baseDirectory(_ / ".." / "build"),src...
project/Build.scalafabrics <++= Seq("EI", "EI2")WTF is <++=? Some kind of fish bones?How do I google that?
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Is Play web scale? [8]
Scalability can be measured alongmany dimensions
RawhorsepowerConcurrenthorsepowerSingledeveloperMultipledevelopers
Raw horsepower: theoretical maximumperformance for the server in idealconditions. A measure of language andframework overh...
Concurrent horsepower: performance withmany users, I/O, and more real-worldscenarios. A measure of the frameworksapproach ...
Single developer: how easy it is to getstarted, how quickly a single developer canbuild things. A measure of the framework...
Multiple developers: how the frameworktolerates many developers workingconcurrently over many years. A measure ofcode rot ...
Here is how Id rate some of theframeworks Ive used. YMMV.
● Pros○ Good raw throughput (qps, latency)○ Type safety reduces code rot● Cons○ Not developer friendly. Getting things don...
RawhorsepowerConcurrenthorsepowerSingledeveloperMultipledevelopersSpringMVC
● Pros○ Set the bar for developer productivity; all otherframeworks are still trying to catch up.● Cons○ Ruby is slow○ Rub...
RawhorsepowerConcurrenthorsepowerSingledeveloperMultipledevelopersRails
● Pros○ v8 engine is pretty fast for raw throughput○ Non-blocking I/O at the core makes concurrencyeasy○ Strong open sourc...
RawhorsepowerConcurrenthorsepowerSingledeveloperMultipledevelopersNode.js
● Pros○ Fast for raw throughput○ Non-blocking I/O at the core makes concurrencyeasy○ Hot reload makes it possible to get t...
RawhorsepowerConcurrenthorsepowerSingledeveloperMultipledevelopersPlay
Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6...
Play is open source [7]
LinkedIn is contributing
Very active google group (mailing list) [9]
StackOverflow tag [10]
Open source modules and plugins [11]
Weve open sourced a few of our plugins,with many more on the way [12]
Commercial support from Typesafe [13]
Recap1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6. ...
Thats the story of Play at LinkedIn so far...
But were just getting started.
LinkedIn Engineering Blog [14]
@LinkedInEng on twitter [15]
Thank you!
References1. http://zeroturnaround.com/java-ee-productivity-report-2011/2. http://static.springsource.org/spring/docs/2.5....
Outline1. Getting started with Play2.
Nächste SlideShare
Wird geladen in …5
×

Outline1. Getting started with Play2. The Play Framework at LinkedIn

227.648 Aufrufe

Veröffentlicht am

Outline1. Getting started with Play2. Make a change and reload3. Error handling4. Threaded vs. evented5. Non-blocking I/O6. Scala7. Performance8. Community

Veröffentlicht in: Technologie, Bildung

×