scaling Ratpack a la vert.x

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

scaling Ratpack a la vert.x

silviu
Hello Luke and Ratpack Team,

I've followed Ratpack in the past few months and I am very impressed with your commitment to building an awesome web framework tailored to Groovy and Java 8. I watched a video of your presentation at the end of last year, and I liked the easy way a Ratpack app can get bundled into a zip, and subsequently deployed using a script.

I have a quick question (and apologize if it's too generic): Does the Ratpack API currently have any concept of "instances" , something like Vert.x. verticles, where you can instantiate 4 or 8 or more in a very easy way, and it automatically frees the user from the multi-threaded traps and hassles ?

In short, I was wondering if you have, or plan to add in the future, functionality that could be harnessed via that startup script
(e.g. groovy-web-console "10" - where "10" would be the number of instances of the http server).

I apologize for any mistaken assumptions regarding Ratpack's functionality and its future direction :)

Regards !
silviu
Reply | Threaded
Open this post in threaded view
|

Re: scaling Ratpack a la vert.x

Luke Daley
Administrator
Hi Silviu,

The short answer is no. 

What lets Vert.x scale is its messaging bus. You only get scalability in vertx if you write your app to leverage the message bus. It’s not completely free or magical. I decided not to bundle something like this in because there are lots of solutions out there for messaging fabrics and locking into one doesn’t make sense to me. Instead you’d have to pick your own messaging or IPC framework and plug it in.

Furthermore, Ratpack doesn’t use the vertical concept. Instead it by default starts as many threads as there are cores * 2 and spreads the workload across them. What it does do though is _serialise_ execution segments so that you don’t have to worry about overlapping due to asynchronous calls. Some details on this can be found here: http://www.ratpack.io/manual/0.9.6/api/ratpack/exec/Execution.html
Reply | Threaded
Open this post in threaded view
|

Re: scaling Ratpack a la vert.x

Silviu
Hi Luke,

Thanks for the quick response and explanation ! I am a bit familiar with Vert.x as I dabbled a bit into it a few months ago, and even reported a (valid) bug dealing with messaging in a cluster :)

If you don't mind me asking, shall I assume that the moment Ratpack is instantiated via that shell script, it "behaves" just like a single Node.js instance would, where, in your case, Netty handles the event loop ?

The reason I'm asking is that for Node, there are somewhat relatively mature solutions out there to practically scale it "externally" (e.g. https://github.com/Unitech/pm2 ) but still keep a single listening http port.

To your knowledge, are there similar open source solutions for Java / Groovy that would fit well with Ratpack ?

(my first instinct would be to use NginX as a load-balancer / dispatcher but I was wondering whether there are more intelligent solutions that do not require multiplication of the http / https listening port if the instances are on the same machine)

Regards
Silviu
Reply | Threaded
Open this post in threaded view
|

Re: scaling Ratpack a la vert.x

Luke Daley
Administrator
node.js is single threaded, Netty (and hence Ratpack is multithreaded). 

There’s no benefit in running multiple instances of the application on the same hardware as by default it will use all the available compute resources. Because node.js is single threaded, you have to use tools like pm2 to use all the compute resources. 

The downside of this is that your app is multi threaded. The upside is that vertical scaling is much easier because the app will just implicitly use the available resources. If you want to scale horizontally you will need an external load balancer and some kind of communication fabric between the nodes (e.g. database, redis, messaging etc.).
 
Reply | Threaded
Open this post in threaded view
|

Re: scaling Ratpack a la vert.x

Silviu
all clear now, thanks !