2
votes

Are there any special tuning tips for strengthening an API built on top of the hapijs framework?

Especially if you have lots of concurrent request (+10000/sec) that are accessing the DB?

  • I'm using PM2 to start my process in "cluster mode" to be able to load-balance to different cores on the server
  • I don't need to serve static content, so there's no apache/nginx proxy

update 17:11

Running tests with 1000 requests/sec (with loader.io) results in this curve - ok, so far. but I'm wondering if there is still room for improvements.
(hardware: 64gb / 20 core digital ocean droplet)

Running test with 1000 requests/sec

1
You should consider use a reverse nginx proxy anyway, even without static content, for security reasons. Also, when using the reverse proxy, you can launch the app multiple times, on different ports, and do the load-balancing with nginx. - ItalyPaleAle
@Qualcuno security isn't an issue right now. I was wondering if the nginx part doesn't add more overhead than performance gain ... but I will try and run some test with PM2/hapi vs nginx/hapi. - Philipp Kyeck
That's why I posted a comment and not an answer. It was just a heads-up, having a reverse proxy is always a good idea IMHO. We still use PM2 to fork (not cluster) multiple instances of the app and keep them alive, but the load balancing is done by nginx. - ItalyPaleAle
Anyways, as a tip for "strengthening your api", check memory usage and ensure you're not leaking memory. - ItalyPaleAle
Do you really need to hit the DB 10000+/sec. Sounds like an opportunity to use hapijs.com/tutorials/caching - Matt Harrison

1 Answers

0
votes

In the end I just used a combination of node's http and the body-parser module to achieve what I needed.

But I think that this was only viable, because my application had just two endpoint (one GET, one POST).

If your application logic is rather complicated and you want to stick with hapi, think about using a load-balancer and dividing the load to multiple VMs.

Loadtest results (new setup on an even smaller DO droplet):

loadtest results