balderdashy/sails — pull request #1716 by jbielick (2014-05-17 19:52:43+00:00)
Title: Sails Cluster / Auto Reload

![screen shot 2014-05-17 at 3 51 47 pm](https://cloud.githubusercontent.com/assets/1413330/3005944/bb1ea174-ddfc-11e3-8703-b7abe4db9f1c.png)
Attempting to address the auto reloading feature in development environment with cluster processes.

Master proc bootstraps the app, and starts grunt task, but only forks workers in start.js instead of starting http server and listening. Worker processes are delegated the server.listen() and can be set in `--workers n` or in `sails.config.workers`.

Master proc watches ./api tree and on change cycles the cluster of workers with a kill signal. Didn't see a need to gracefully restart workers since cycling the workers is a development-only task.

There's a monkey patch for npm cluster in start.js addressing the missing port attribute on server(). It's not yet been addressed, but with the provided patch, the tests and servers all run correctly.

I've screenshot some preliminary benchmarking on concurrency and request timing with siege and results can be seen below.

I'm sure I've missed some issues, but all tests pass and I'd be glad to work through whatever issues arise as well as strategize how to write the tests for this.

![300 concurrent connections](https://cloud.githubusercontent.com/assets/1413330/3005936/813bcd42-ddfc-11e3-9994-d84b03d8a34d.png)
![300 concurrent connections](https://cloud.githubusercontent.com/assets/1413330/3005937/813d1968-ddfc-11e3-8653-26a729f218b9.png)
![1000 concurrent connections](https://cloud.githubusercontent.com/assets/1413330/3005939/813d7750-ddfc-11e3-87c4-839d7091aaa5.png)
![1000 concurrent connections](https://cloud.githubusercontent.com/assets/1413330/3005938/813d5ed2-ddfc-11e3-8ef5-2f50da5489c7.png)