3

What will a hapi server do if it is overloaded and is there something like toobusy-js to prevent a fallout of the server by shortcutting some requests with errors.

morsecoder
  • 1,479
  • 2
  • 15
  • 24
Alinex
  • 914
  • 8
  • 18

1 Answers1

8

Yes it's embedded in the framework, look at load on connections settings. You have 3 options :

  • maxHeapUsedBytes - maximum V8 heap size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
  • maxRssBytes - maximum process RSS size over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit).
  • maxEventLoopDelay - maximum event loop delay duration in milliseconds over which incoming requests are rejected with an HTTP Server Timeout (503) response. Defaults to 0 (no limit). `

And you must not forget to set a sample interval (time between 2 checks) on server.load config:

  • sampleInterval - the frequency of sampling in milliseconds. Defaults to 0 (no sampling).

Example :

server configuration :

{
  "load": {
    "sampleInterval": 1000
  }
}

connection configuration :

{
  "load": {
    "maxHeapUsedBytes": 1073741824,
    "maxRssBytes": 1610612736,
    "maxEventLoopDelay": 5000
  }
}
Pierre Inglebert
  • 3,858
  • 1
  • 18
  • 22
  • 1
    Sorry to bother you but what's the reasonable values for the options ? – Whisher Aug 04 '15 at 20:16
  • 1
    The reason is to prevent a complete fallout of the server (see the question above). I better reject some users in the web service and work for others instead of the server goes into a heavy load and becomes unmanagable. – Alinex Aug 05 '15 at 05:27
  • @Pierre Inglebert the options works in dev env but doesn't work in test env with lab – Whisher Aug 05 '15 at 08:40
  • @Pierre Inglebert when I run npm test I got this (take a look at https://gist.github.com/whisher/3a6b1d0abe14057a5ba8) – Whisher Aug 05 '15 at 09:52
  • Have you start the server ? Check this test for example : https://github.com/hapijs/hapi/blob/cf267f91eb179555956fd7081cd86444a53dd8c6/test/server.js#L260 I dont set load conf in my tests. – Pierre Inglebert Aug 05 '15 at 10:09
  • Yes without your option it works I'm using Lab take a look at this post there is a suite test http://stackoverflow.com/questions/31807290/hapi-lab-how-do-i-have-shared-state-between-lab-experiments – Whisher Aug 05 '15 at 10:16
  • If you add these options, you must call `server.start` before testing your routes. Btw, it's useless to set it for tests unless you want to test this behavior. – Pierre Inglebert Aug 05 '15 at 11:00
  • Yes you right just get rid of the options in the configuration file it's just to point it out. – Whisher Aug 05 '15 at 11:28