Play framework and high CPU usage

If you notice your CPU usage going higher than it should, do not worry; there is a fix for it. Actually, the issue is related to SBT. Just make sure that, when you run Activator, you pass the following parameter:

$ activator -Dsbt.task.forcegc=false.

Going back to ReactiveWebStore, let's create new routes. Open


GET /rnd/double


GET /rnd/call controllers.RndDoubleGeneratorController.rndCall

GET /rnd/rx controllers.RndDoubleGeneratorController.rxCall

GET /rnd/rxbat


Once we have the new routes, we need to create the new controller. This controller needs to be located with the other controllers at ReactiveWebStore/app/controllers.


The RndDoubleGeneratorController class file should look like this:


class RndDoubleGeneratorController @Inject() (service:IRndService) extends Controller {

import play.api.libs.concurrent.Execution.


def rndDouble = Action { implicit request =>

Ok( )


def rndCall = Action.async { implicit request => { res => Ok(res) }


def rxCall = Action { implicit request =>



def rxScalaCallBatch = Action { implicit request =>




All methods in the preceding controller call the service IRndService. All operations in RndService call ng-microservice. Here we have some flavors of operations, which will be covered in great detail next when we explore the service implementation.

There are some interesting things here: for instance, for the second operation called rndCall, we see Action.async in use, which means our controller will return a Future, and this Future comes from the service. We also execute a Map to transform the result into an Ok.

The last operation called rxScalaCallBatch is the most interesting, and the one we will be using for our UI. However, you can use the other one if you wish, since they all return doubles, and that's good.

< Prev   CONTENTS   Source   Next >