play concurrency
TRANSCRIPT
![Page 1: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/1.jpg)
CONCURRENCY IN
PLAY 2.0Ola Wiberg
Wednesday, 11 July, 12
![Page 2: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/2.jpg)
OVERVIEW
• Background
• Play architecture
• Integrated Akka
• API
• Asynchronous IO
Wednesday, 11 July, 12
![Page 3: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/3.jpg)
A PLATFORM FOR THE FUTURE
"The web has evolved from static to dynamic to real-time."
"Play is a framework for highly-scalable real-time applications!"
Wednesday, 11 July, 12
![Page 4: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/4.jpg)
DESIGN DECISIONS
• Designed for asynchronous HTTP
• Assumes that any request is long-lived (streams/sockets)
• Concurrency using Actors (Akka) instead of Threads
• Reactive (event based) model for IO
• Keep things simple!
Wednesday, 11 July, 12
![Page 5: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/5.jpg)
• One process/thread per request
• Resource intense / upper bound limit
• State is handled by the stack
• Requests handled in "isolation"
• Easy to track control flow
• Apache, Tomcat
• Single process for all requests
• Less resource intense
• State maintained in program
• Single event-loop, with event call-backs
• Difficult to track control flow
• Lighttp, Nodejs
BACKGROUNDThreads or Events
Wednesday, 11 July, 12
![Page 6: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/6.jpg)
A BETTER SOLUTION
• Threads are good
• Events are good
• Why not make use of them both?
• To do it well the complete framework stackneeds to support it!
Wednesday, 11 July, 12
![Page 7: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/7.jpg)
Java EE compared to Play
Wednesday, 11 July, 12
![Page 8: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/8.jpg)
Play framework stack
Wednesday, 11 July, 12
![Page 9: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/9.jpg)
PLAY CONCURRENCY
• Integrated support for Akka
• For concurrent, distributed, event-driven solutions
• Asynchronous IO (play specific)
• Reactive model using Iteratee IO
• Event driven, non-blocking IO (streams/sockets)
• Netty for HTTP
• Asynchronous event-driven framework (NIO)
• Stateless architecture
Wednesday, 11 July, 12
![Page 10: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/10.jpg)
Wednesday, 11 July, 12
![Page 11: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/11.jpg)
AKKA
• Akka is used internally for concurrency features in Play
• Built in ActorSystem to be used by the application
• play.api.libs.concurrent.Akka helper object
• Startup new ActorSystems
• Access remote ActorSystems
Wednesday, 11 July, 12
![Page 12: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/12.jpg)
WHEN TO USE AKKA
• When executing long running tasks.
• Calculations, data crunching, long running queries.
• When accessing web services.
• When accessing remote ActorSystems.
• When scheduling tasks.
Wednesday, 11 July, 12
![Page 13: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/13.jpg)
CREATE AN ACTORBuilt in ActorSystem
Wednesday, 11 July, 12
![Page 14: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/14.jpg)
USING AN ACTOR
Wednesday, 11 July, 12
![Page 15: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/15.jpg)
CREATE AN ACTOR SYSTEM
Wednesday, 11 July, 12
![Page 16: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/16.jpg)
EXECUTE A TASKWithout creating an Actor
Wednesday, 11 July, 12
![Page 17: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/17.jpg)
HELPER METHOD
Wednesday, 11 July, 12
![Page 18: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/18.jpg)
CALLING A WEB SERVICE
Wednesday, 11 July, 12
![Page 19: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/19.jpg)
REQUEST => RESPONSE
Wednesday, 11 July, 12
![Page 20: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/20.jpg)
What type of request, stream or regular request?
Wednesday, 11 July, 12
![Page 21: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/21.jpg)
In-memory request
Wednesday, 11 July, 12
![Page 22: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/22.jpg)
Stream/socket based request
Wednesday, 11 July, 12
![Page 23: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/23.jpg)
REACTIVE MODEL
• Handling data streams reactively
• Remove IO stream limitation (Blocking, memory, threads)
• “React” to input only at a rate it is needed (no buffering)
• Implemented using Iteratees, Enumerators, Enumeratees (Consumer/Producer Pattern)
• Topic for another presentation!
Async IO
Wednesday, 11 July, 12
![Page 24: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/24.jpg)
Example System Overview
Wednesday, 11 July, 12
![Page 25: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/25.jpg)
SUMMARY
• Play 2.0 is implemented for high concurrency applications
• Play 2.0 has a simple API for concurrency features
• Play 2.0 is great for :
• high throughput, low memory usage
• many concurrent requests / socket connection
Wednesday, 11 July, 12
![Page 26: Play concurrency](https://reader036.vdocuments.net/reader036/viewer/2022062418/554f5610b4c905423f8b5552/html5/thumbnails/26.jpg)
THANK YOU!
@OlaWiberg
Wednesday, 11 July, 12