sheldonkreger
sheldonkreger

Reputation: 938

How are asynchronous callbacks processed in the Play! Framework?

I understand that a typical Play application will utilize one thread per CPU core. If I am not mistaken, when a thread hits an asynchronous I/O function, it opens up that thread for other processes while it waits for the return value.

My question is in regard to what happens when the value is returned. When the callback is ready to be executed, how does the Play Framework re-distribute this task into the application? Does it have a queue like Node.js, where each 'ready' callback is thrown into a master queue, and an application-wide event loop pushes them one-by-one back into a thread as they become available?

Upvotes: 2

Views: 535

Answers (1)

James Roper
James Roper

Reputation: 12850

Everything you need to know is here:

https://www.playframework.com/documentation/2.3.x/ThreadPools

Unlike node, Play doesn't just have one event loop, Play has thread pools. Play's thread pools actually typically are configured with more than one thread per core, and there are multiple pools for different purposes.

As far as exactly how the events are triggered, it depends on the task. Doing IO on an http connection, well there is a Netty boss thread that calls select to receive new events for all the registered http connections. As soon as something happens, it delegates the work to a Netty worker thread, and then Play will do some work, and potentially delegate further work to the Play thread pools. But there may be other event loops depending on what other libraries you are using, for connection pools, etc.

Upvotes: 1

Related Questions