0
votes

I have an API service implemented in a Play 2 App, Currently the api handles 5-7000 requests per second on 5 servers. I have benchmarked Spray.IO and Play2 recently and see almost 3x the performance on simple http requests.

I would prefer not to re-implement everything in Spray, if instead I can somehow embed the spray HTTP server in my Play app, than use that to server http requests.

Is this possible? and is there an example of this out there?

3
Do you know if the framework is really the bottleneck? Of course, it helps if the framework/web server is fast but for normal applications it's more often the application itself which makes up for the bottlenecks. In the end, you will always need to do profiling to find opportunities for speeding up your application, so start with profiling, and if you find out that something in play seems to be slow, report it. - jrudolph

3 Answers

1
votes

I can say that Spray actually is the fastest JVM-based toolkit for web-based development, you can check out the latest benchmarks on the official blog.

As for the question. If you want to write your own implementation for a little HTTP server then you should check spray-can http based api, spray-io is just a layer between Akka IO and Java NIO. I'm not very good at Play, but as a way i would sugest to create a multi-build sbt config or separate project with Spray http server and connect them through REST api.

Architecture would be pretty simple cause it's based on Akka actors in the simplest case would look like a bunch of cases in the receive method:

def receive = {
  case HttpRequest(GET, Uri.Path("/ping"), _, _, _) =>
    sender ! HttpResponse(entity = "PONG")
}

On the Play side you should use Akka or Play's routing file for describing routes.

Also check out Spray routing api. It's much easier to implement and to use and looks very similar to what Spray can give you with route file, but more flexible and readable.

Also Spray has many great very detailed examples on their Github repo: spray-can and spray-routing.

BTW Spray team also made available Play template engine for front-end and called it Twirl so porting your application to Spray won't take much time

1
votes

We see that Play rates well for a full stack framework:

http://www.techempower.com/benchmarks/#section=data-r6&hw=i7&test=db&c=1&d=2&a=1

We see that there are trade-offs in terms of developer productivity i.e. the faster you want to go, the less productive your developers will typically be. You need to know whether Play will achieve the performance that your application demands.

Incidentally we have been focused and continue to focus on improving Play's performance.

I hope that this helps.

1
votes

Actually, The Play framework will soon be using Spray I/O for it's http serverices. So it looks like you'll be able to have the best of both worlds!