Share
Embed
Not a toy! The Play Framework for Scalable Web Applications
Martin Lehmann: „Not a toy! The Play Framework for Scalable Web Applications”. Eclipse Democamp, 30. November 2015
https://wiki.eclipse.org/Eclipse_DemoCamp_November_2015/Frankfurt
Martin Lehmann
November 30, 2015
Transcript
20 slides
-
1 Kein Spielzeug! Das Play Framework für skalierbare Web-Anwendungen Martin
Lehmann, Accso GmbH – Eclipse Democamp, Frankfurt 30.11.2015 -
2 Not a toy! The Play Framework for Scalable Web
Applications Martin Lehmann, Accso GmbH – Eclipse Democamp, Frankfurt Nov 30th, 2015 -
3 Computer science Since 2010 member of management
board and CTO at Accso – Accelerated Solutions GmbH in Darmstadt, www.accso.de Since end of the 90s working in several projects with scope on individual software development, focussing mainly on technical architecture Java, SW architecture, SW Engineering, Distributed Systems Active member of iSAQB and IASA # who am i -
4 Copyright © Accso GmbH Requirements on Performance: short response
times, low latency, high throughput Requirements on Scalability: growing numbers of named/concurrent users, multi-core Requirements on Availability: 24x7, failover, fault-tolerancy What are the Requirements? Reactive Manifesto: Responsive, Resilient, Elastic, Message-Driven Event based Many parallel requests Lots of subscribers Pipelining, Data chains -
5 Copyright © Accso GmbH Traditional concurrent programming model is
too low-level, too complex, too error-prone! Another Requirement: Control the Complexity Traditional concurrent programming model does not get the optimum out of available resources. Actor Model Reactor Pattern -
6 Copyright © Accso GmbH Actor Model Carl Hewitt, 1973
Model for concurrent programming Actors as the executables in the system Shared-Nothing architecture (no global state) Asynchronous messaging Actor Actor Actor State State State -
7 Copyright © Accso GmbH Design Pattern for event handling
Reactor = Dispatcher (of events to callback handlers) Decouples application logic from execution logic Reactor Pattern: 1 Event-Loop-Thread Multi-Reactor Pattern: Scale to n ELTs Handler has to avoid to block the ELT at all cost! (Multi-)Reactor Pattern Douglas Schmidt et al, 1996f Client Client Client Event Loop -
8 Copyright © Accso GmbH (Multi-)Reactor Pattern Douglas Schmidt et
al, 1996f loop { // you control the flow doSomething(); } registerHandler(doSomething); loop { // event loop controls the flow // calls registered callback event = getEventFromEventQueue(); dispatch(event); } Event Driven Normal -
9 Copyright © Accso GmbH Good old stuff from the
70s and 90s used nowadays -
Copyright © Accso GmbH 10 Overview Play-Framework Since 2007 Currently
V2.4 (V3 expected soon) (don‘t mix up with Play 1.x) Web- Framework (MVC) Open-Source (Apache 2) reactive Typesafe Reactive Platform extendable > 80 modules listed at https://www.playframework.com/documen tation/2.4.x/ModuleDirectory -
Copyright © Accso GmbH 11 sbt Build System Resource Handling
View Templates (Scala, HTML) Sonstige Libraries JSON, Security, … Play Core (MVC) Persistence (EBeans or JPA, h2 database) Netty (Web- server) Play Application JUnit, Selenium Akka Java or Scala CoffeeScript / JavaScript CSS / LESS Overview Play-Framework -
Copyright © Accso GmbH Play Web Applications are based on
MVC: routes Configuration and Controller in Java 13 # Routes GET /presents controllers.XMasController.getPresentList() GET /daysToXMas controllers.XMasController.howManyDaysUntilXMas() Route: URL to Controller method Call the View public class XMasController extends Controller { @Inject Initialize init; public Result getPresentList() { List<Present> presents = Present.list(); return ok(showPresentList.render(presents)); } public Result howManyDaysUntilXMas() { LocalDate xMasDay = LocalDate.of(2015, Month.DECEMBER, 24); LocalDate now = LocalDate.now(); … int days = (Period.between(now, xMasDay)).getDays(); return ok(daysToGo.render(days)); } } Controller-Methode (public, static) Controller method -
Copyright © Accso GmbH @(presents: List[Present]) @* showPresentList.scala.html *@ @main("XMasPresents")
{ <h1>List of XMas presents</h1> <p> <ul> @for(present <- presents) { <li>@present.name is for @present.presentee</li> } </ul> } Play Web Applications are based on MVC: View Templates in HTML & Scala Main elements: for loop, iterator, if-then-else and Template composition 13 Parameter from Controller Scala-Code Starts with @ -
Copyright © Accso GmbH Play Web Applications are based on
MVC: Persistence with ORM via EBeans (or Hibernate/JPA) 15 import javax.persistence.*; @Entity public class Present extends Model { @Id @GeneratedValue @Column(nullable = false) private Long id; @Column(nullable = false) public String name; @Column(nullable = false) public String presentee; ... private static Model.Find<Long, Present> finder = new Model.Find<Long, Present>(){}; public static List<Present> list() { return finder.findList(); } } EBeans-Model super class plus enhancement Annotations from javax.persistence Finder methods, Query API EBeans is pretty simple. No session. Attention: Still usable though Ebeans seems (is?) kind of dead meanwhile. -
Copyright © Accso GmbH Configuration and Modularization of a Play
Web Application 16 Central config file in application.conf Divide to and include of other config files Modularization of a Play App -
Copyright © Accso GmbH 17 What about the Development Tool
Chain? • Integration with Eclipse / Scala IDE easy • Hot-Deployment and Debugging straight forward • Tests with JUnit and Selenium • Build with sbt, Ivy • Integration with Maven possible but tricky • Templates, routes etc are compiled, too • Eclipse 4.4.2 (Luna) • Scala IDE 4.2.0 • Scala 2.11.7 and Scala 2.10.5 • Sbt 0.13.8 • Scala Worksheet 0.4.0 • Play Framework support 0.5.0 • ScalaTest support 2.9.3 • Scala Refactoring 0.7.0 • Scala Search 0.2.5 • access to the full Scala IDE ecosystem -
Copyright © Accso GmbH 18 Table visualization taken from: Lutz
Huehnken, Typesafe, JAX 2015: „Von Enterprise zu Reactive“ http://de.slideshare.net/lutzh/von-enterprise-zu-reactive Traditional Servlet Model: Thread per Request Dispatching (n Threads per m Requests) Attention Don‘t rely on ThreadLocal! Blocking IO (e.g. JDBC) blocks the thread! Play standalone or via Plugin in Servlet Container? Plugin see https://github.com/play2war/play2-war-plugin/ -
Copyright © Accso GmbH Play uses Akka under the hood
for Asynchronous Web Processing 19 Browser Server Proc. Unit Proc. Unit Proc. Unit Proc. Unit Proc. Unit Proc. Unit -
20 Begeisterung für die anspruchsvollen Aufgaben unserer Kunden Accso –
Accelerated Solutions GmbH www.accso.de twitter.com/accso Berliner Allee 58 64295 Darmstadt Telefon: +49 (6151) 13029-0 Fax: +49 (6151) 13029-10 Moltkestraße 131 a 50674 Köln Telefon: +49 (221) 630691-0 Fax: +49 (221) 630691-10 Theatinerstraße 11 80333 München Telefon: +49 (89) 71042-2040 Fax: + 49 (89) 71042-2001