Caballero
Caballero

Reputation: 12101

Play Framework can't handle more than 12 concurrent connections

I have a vanilla Play 2.6 app that can't handle more than 12 concurrent connections. It also affects Play 2.5.

This is an example controller:

public class TestController extends Controller {

    public Result index() {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return ok("");
    }

}

Testing with 12 concurrent connections:

ab -n 12 -c 12 http://localhost:9000/

output:

...
Concurrency Level:      12
Time taken for tests:   1.005 seconds
Complete requests:      12
...

So all 12 concurrent requests responded in 1 second which is what was expected.

Testing with 13 concurrent connections:

ab -n 13 -c 13 http://localhost:9000/

output:

...
Concurrency Level:      13
Time taken for tests:   2.004 seconds
Complete requests:      13
...

Now 13 concurrent connections took 2 seconds. Both situations tested multiple times and produced consistent results.

Why is this happening? Surely Play should be able handle more than 12 concurrent connections?

Upvotes: 1

Views: 1673

Answers (1)

vdebergue
vdebergue

Reputation: 2404

Play at its base uses non-blocking IO and it won't allocate a thread per request. So when you use a method like Thread.sleep, you prevent Play from using the thread to handle other requests.

When doing blocking IO, the documentation recommends to use a dedicated thread pool. You can read more information and how to handle this case in the official documentation: https://www.playframework.com/documentation/2.6.x/ThreadPools#Understanding-Play-thread-pools

Upvotes: 5

Related Questions