How fast is play framework




















So imagine that instead of an HTTP request, there's a book that contains pages. Imagine instead of a CPU core, there's a paper shredder, in another room. And imagine that instead of a thread, there's a person who has the job ripping out some pages out of the room with the book, going into the shredder room, and feeding a page into the paper shredder. One person ripping pages out and feeding pages into a shredder is doing as much work as possible, but the IO -- the cost of going backwards and forwards between different rooms -- means that the shredder is idle while the person is bringing more pages to it.

Even worse, some times the door to the book room is locked, and the person has to wait blocking until the door opens again. You can shred more pages if you add more people. Each person will hold some pages out of a book, and they will hold those pages and make an orderly line to the shredder. If you calculate it right using Little's Law , the average wait time balances out with the arrival and departure time and the shredder always has pages to shred.

So far so good. But there's a wrinkle: there's never one single HTTP request. Instead, there are multiple HTTP requests. Who Owns the Future? Jaron Lanier. Tarun Mahajan. Zaher Nourredine. Home at Home.

David Santiago Barrera. Manoj Santhakumaran. Vikas Kollur Vijayakumar. Leon Bam , software engineer at Youappi at YouAppi. Vagner Cotrim , Show More. Views Total views. Actions Shares. No notes for slide. Why Play Framework is fast 1. What Makes Play Framework Fast? Applications written using Play Framework will do more with the same hardware. Reactive Applications 5 6. Computers Then Reactive Applications 7 8. If you have to get more paper IO , the shredder idles Reactive Applications 9 Reactive Applications 11 Since we want to delete the functionality too, we will need to identify each task using a unique ID, which means that our model should have two properties: an ID and a name.

The Task model will be:. In this model, we are using a taskList private variable to keep track of the tasks for the session. In the add method, whenever a new task is added, we append it to this list. Instead of keeping another variable to keep count of the IDs, I choose to increment the ID of the last element in the list.

In the delete method, we simply filter out the task with the given ID and the all method returns the list for this session. Now, we need to call these methods in our controller and then bind them to a request route. Now, update the controller in this way:. Try running the app now! It'll throw a compilation error, which says that values tasks is not a member of controllers.

This occurs because we haven't yet updated the routes. We have now added a form in the view, which takes a text input with the taskName name and submits this data to a TaskController. Notice that we have now added a tasks argument for this template and are displaying it in the view.

Scala elements and predefined templates are prepended with the twirl symbol in the views. Now, when running the app, we will be able to add tasks as well as view existing ones, as shown here:. The only thing remaining in our app is the ability to delete a task. We also need to define deleteTask in our view. To do this, we can simply add a script:. Ideally, we shouldn't be defining JavaScript methods in the window's global namespace.

It has been done in this example, so as to keep it simple and it's not advised for any real-time application. Now, when we run the app, we can add tasks as well as remove them, as shown here:. I am leaving the task of beautifying the app up to you.

Add a style sheet in the public directory and declare it in the main template. For example, if the taskTracker. This chapter gives a basic introduction to the Play Framework. In this chapter, we have learned how to build simple applications using the Play Framework.

We have gone through its project structure to understand how the framework plugs in required settings through the build file. We have also discussed the various bits and pieces of such applications: models, routes, views, controllers, and so on. Shiti Saxena is a software engineer with around 4 years of work experience. She is currently working with Imaginea a business unit of Pramati. She has previously worked with Tata Consultancy Services Ltd.

She loves to travel, is a movie buff, and likes to spend time playing her piano whenever she is not programming. About this book Play Framework is an open source web application framework that is written in Java and Scala.

Publication date: May Publisher Packt. Pages ISBN Chapter 1. Getting Started with Play. Venturing into the world of Play. The tasks can be considered the operations that gather items for our box before shipping it to the receiver.

In Play, the T represents the type of item that will be placed inside the box. The tasks would be each individual step defined within a Play action. Instead of going to a store, a task would involve going to a database.

The core of the developer experience in Play are actions , which are functions that are executed when an incoming request is routed to that action based on URI matching. An action can be defined as synchronous or asynchronous. Actions have a return type as follows:. As you can see, without futures you simply have synchronous actions. When you combine actions with futures, you have asynchronous actions. The following Scala action is synchronous:. The following Scala action is asynchronous:.

All that separates a synchronous action from an asynchronous action in Play is. One of the biggest mistakes I find during Play code reviews is a fundamental misunderstanding of what async means, and without the proper use of. In this Java example we process a simple form from the client and grab the items of a shopping cart asynchronously:.

The syntactic difference of implementing efficient concurrency and scheduling is subtle, just like the inefficiencies in our anecdotal example. Modern web applications rely on many blocking calls to produce results, such as making requests from external web services and databases. The four modes of concurrency, from best to worse, are:.



0コメント

  • 1000 / 1000