Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tune the scalability of play framework app?

I am using Play framework 2.1 to develop my app. It is quite easy-to-use framework. I am able to develop my app quickly. But I also ran into some scalability issues. It seems the Play 2.1 doesn't run as fast as claimed. Maybe that is because I didn't know to tune the performance.

My problem is following: I have an API to login a user with his/her email.

I used Apache Benchmark (ab) to use the performance. One single request takes about 230ms. When there are 5 concurrent requests, the response time is still fast enough, about 280ms.

Concurrency Level:      5
Time taken for tests:   0.306 seconds
Complete requests:      5
Failed requests:        0
Write errors:           0
Total transferred:      3495 bytes
Total POSTed:           1065
HTML transferred:       3135 bytes
Requests per second:    16.34 [#/sec] (mean)
Time per request:       306.009 [ms] (mean)
Time per request:       61.202 [ms] (mean, across all concurrent requests)
Transfer rate:          11.15 [Kbytes/sec] received
                        3.40 kb/s sent
                        14.55 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1    1   0.1      1       1
Processing:   280  290  13.8    292     305
Waiting:      278  288  13.7    291     304
Total:        280  291  13.9    293     306

However, when I used 100 concurrent requests, I got very bad results.

Concurrency Level:      100
Time taken for tests:   4.243 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      69900 bytes
Total POSTed:           21300
HTML transferred:       62700 bytes
Requests per second:    23.57 [#/sec] (mean)
Time per request:       4243.058 [ms] (mean)
Time per request:       42.431 [ms] (mean, across all concurrent requests)
Transfer rate:          16.09 [Kbytes/sec] received
                        4.90 kb/s sent
                        20.99 kb/s total

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        1   62  31.5     83      89
Processing:   996 3744 544.7   3902    4146
Waiting:      995 3727 542.0   3894    4146
Total:       1084 3806 542.6   3968    4204

My server machine: Intel i7, 8 cores, 2.8GHz, 8GB memory. I used default setting of play framework. Anyone knows how to tune the performances of play framework?

I think it relates to thread pool size. The document says play's default thread pool size is # cores. In that case, the expected time to handle all 100 requests is:

230ms * (100 / 8) = 2875ms

So, should I increase the size of default thread pool? But the document says I should get the best performance when pool size is equal to # cores.

Also, will netty's (play's web server) thread pool size affect the performance? I didn't find any information about its default value. Anyone knows how it is configured?

Thank you!

like image 372
Xiaomo Liu Avatar asked Jul 08 '13 22:07

Xiaomo Liu


People also ask

Is Play framework still used?

Play is rock-solid and used by hundreds of thousands of Java and Scala developers every month. Play is still extremely relevant to today's application and web development and has a passionate and very capable community around it ensuring that it has many good years left.

Which component is responsible for building play framework?

Play Framework is an open-source web application framework which follows the model–view–controller (MVC) architectural pattern. It is written in Scala and usable from other programming languages that are compiled to JVM bytecode, e.g. Java.

Why use Play Framework?

Play Framework makes it easy to build web applications with Java & Scala. Play is based on a lightweight, stateless, web-friendly architecture. Built on Akka, Play provides predictable and minimal resource consumption (CPU, memory, threads) for highly-scalable applications.

How does play framework work?

The Play framework is a web framework for the JVM that breaks away from the Servlet Specification. Play embraces a fully reactive programming model through the use of futures for asynchronous programming, work stealing for maximizing available threads, and Akka for distribution of work.


1 Answers

Play's default threads configuration is designed for applications that use asynchronous APIs.

If you make a lot of blocking calls (typically, "standard" JDBC database calls), you will need to adjust the default ThreadPool, or execute your DB calls in another specifically configured ThreadPool.

To understand all these mechanisms, I can suggest you to read the Thread Pools section of the Play Framework documentation. It contains very useful informations on this subject.

like image 108
mguillermin Avatar answered Sep 28 '22 07:09

mguillermin