jug.parallel

April 6, 2017 ยท View on GitHub

under development

jug.parallel allows processing jug requests in parallel. Under the hood it launches a node.js based load balancer which in turn spins up n different instances of your jug instance. A round-robin approach is used to distribute the requests.

Requirements

  • node.js installation

Installation

devtools::install_github("Bart6114/jug.parallel")

Example

Start up 8 jug instances in parallel:

library(jug)

jug() %>%
  get("/", function(req, res, err){
    "Hello World!"
  }) %>%
  simple_error_handler_json() %>%
  serve_it_parallel(processes=8)
curl 127.0.0.1:8080
Hello World!

One can also call serve_it_parallel with wait=FALSE. This way the terminal will not be blocked and the jug instances will be served in the background. Remember that you will have to clean up the servers manually.

Stop and clean-up all servers:

kill_servers()
[1] TRUE
Stopping servers...success

Benchmarks

Below (non-exhaustive) load tests have been done using loadtest on a MacBook Pro with a 2,5 GHz Intel Core i7 CPU. The requests per second (rps) parameter was set to 1000.

typeconcurrencyrequestsduration (secs)errors
jug61e20.480
jug.parallel61e20.620
jug61e31.951
jug.parallel61e31.370
jug61e415.08458
jug.parallel61e412.300

The most important take away here is that jug.parallel only becomes interesting in cases where you are expecting a (very) high load or where the request processing duration is significant.