@@ -25,8 +25,8 @@ http://x.co/bpnode
25
25
Video:
26
26
27
27
http://x.co/bpnodevid
28
-
29
-
28
+
29
+
30
30
## Getting Started
31
31
32
32
Your existing application, be it console app or service of some kind:
@@ -77,7 +77,7 @@ or for a full list of commands...
77
77
or for help on a specific command:
78
78
79
79
help {command}
80
-
80
+
81
81
We can also issue commands from a seperate process, or even a remote machine (assuming proper access):
82
82
83
83
npm install -g cluster-service
@@ -144,14 +144,19 @@ Or within your node app:
144
144
(in bytes), the process will be restarted gracefully. Only one worker will be restarted at a time.
145
145
* ` restartOnUpTime ` (default: disabled) - If a worker process exceeds the specified uptime threshold
146
146
(in seconds), the process will be restarted gracefully. Only one worker will be restarted at a time.
147
+ * ` restartConcurrencyRatio ` (default ` 0.33 ` ) - The ratio of workers that can be restarted concurrently
148
+ during a restart or upgrade process. This can greatly improve the speed of restarts for applications
149
+ with many concurrent workers and/or slow initializing workers.
147
150
* ` commands ` - A single directory, an array of directories, or a comma-delimited list of directories
148
151
may be provided to auto-register commands found in the provided folders that match the ".js"
149
152
extension. If the module exposes the "id" property, that will be the name of the command,
150
153
otherwise the filename (minus the extension) will be used as the name of the command. If relative
151
154
paths are provided, they will be resolved from process.cwd().
152
155
* ` master ` - An optional module to execute for the master process only, once ``` start ``` has been completed.
153
-
154
-
156
+ * ` proxy ` - Optional path to a JSON config file to enable Proxy Support.
157
+ * ` workerGid ` - Group ID to assign to child worker processes (recommended ` nobody ` ).
158
+ * ` workerUid ` - User ID to assign to child worker processes (recommended ` nobody ` ).
159
+
155
160
156
161
## Console & REST API
157
162
@@ -177,7 +182,7 @@ Or better yet, use the ```run``` option to do the work for you:
177
182
cservice "help" --accessKey "lksjdf982734"
178
183
// same as
179
184
cservice --run "help" --accessKey "lksjdf982734"
180
-
185
+
181
186
182
187
183
188
## Cluster Commands
@@ -210,12 +215,12 @@ Or if you prefer to manually do so via code:
210
215
// can also fire custom events
211
216
cservice.trigger("on.custom.complete", 1, 2, 3);
212
217
};
213
-
218
+
214
219
cservice.on("test", function(evt, cb, testScript, timeout) { // we're overriding the "test" command
215
220
// arguments
216
221
// do something, no callback required (events may optionally be triggered)
217
- };
218
-
222
+ };
223
+
219
224
// can also issue commands programatically
220
225
cservice.trigger("custom", function(err) { /* my callback */ }, "arg1value", "arg2value");
221
226
@@ -253,8 +258,8 @@ Additionally, a worker may optionally perform cleanup tasks prior to exit, via:
253
258
process.exit(); // we're responsible for exiting if we register this cb
254
259
}
255
260
});
256
-
257
-
261
+
262
+
258
263
259
264
## Access Control
260
265
@@ -275,8 +280,75 @@ Or may be overriden at runtime via:
275
280
require (" cluster-service" ).control ({ " exit" : " local" });
276
281
```
277
282
278
-
279
-
283
+ ## Proxy Support
284
+
285
+ Proxy mode specifically caters to Web Servers that you want to enable automatic
286
+ versioning of your service. Any version requested (via ` versionHeader ` ) that is
287
+ not yet loaded will automatically have a worker process spun up with the new
288
+ version, and after ready, the proxy will route to that worker.
289
+
290
+ Every version of your app * must* adhere to the ` PROXY_PORT ` environment
291
+ variable like so:
292
+
293
+ require("http").createServer(function(req, res) {
294
+ res.writeHead(200);
295
+ res.end("Hello world!");
296
+ }).listen(process.env.PROXY_PORT || 3000 /* port to use when not running in proxy mode */);
297
+
298
+ ### Proxy Options
299
+
300
+ * ` versionPath ` (default: same directory as proxy JSON config) - Can override
301
+ to point to a new version folder.
302
+ * ` defaultVersion ` - The version (folder name) that is currently active/live.
303
+ If you do not initially set this option, making a request to the Proxy without
304
+ a `versionHeader` will result in a 404 (Not Found) since there is no active/live
305
+ version.
306
+ Upgrades will automatically update this option to the latest upgraded version.
307
+ * ` versionHeader ` (default: ` x-version ` ) - HTTP Header to use when determining
308
+ non-default version to route to.
309
+ * ` workerFilename ` (default: ` worker.js ` ) - Filename of worker file.
310
+ * ` bindings ` (default: ` [{ port: 80, workerCount: 2 }] ` ) - An array of ` Proxy Bindings ` .
311
+ * ` versionPorts ` (default: ` 11000-12000 ` ) - Reserved port range that can be used to
312
+ assign ports to different App versions via ` PROXY_PORT ` .
313
+ * ` nonDefaultWorkerCount ` (default: 1) - If a version is requested that is not
314
+ a default version, this will be the number of worker processes dedicated to
315
+ that version.
316
+ * ` nonDefaultWorkerIdleTime ` (default: 3600) - The number of seconds of inactivity
317
+ before a non-default version will have its workers shut down.
318
+
319
+ ### Proxy Bindings
320
+
321
+ Binding options:
322
+
323
+ * ` port ` - Proxy port to bind to.
324
+ * ` workerCount ` (default: 2) - Number of worker processes to use for this
325
+ binding. Typically more than 2 is unnecessary for a proxy, and less than 2
326
+ is a potential failure point if a proxy worker ever goes down.
327
+ * ` tlsOptions ` - TLS Options if binding for HTTPS.
328
+ * ` key ` - Filename that contains the Certificate Key.
329
+ * `cert` - Filename that contains the Certificate.
330
+ * `pem` - Filename that contains the Certificate PEM if applicable.
331
+
332
+ A full list of TLS Options: https://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
333
+
334
+ ### Proxy Commands
335
+
336
+ Work like any other ` Cluster Commands ` .
337
+
338
+ * ` proxy start configPath ` - Start the proxy using the provided JSON config file.
339
+ * ` proxy stop ` - Shutdown the proxy service.
340
+ * ` proxy version workerVersion workerCount ` - Set a given App version to the
341
+ desired number of worker processes. If the version is not already running,
342
+ it will be started. If 2 workers for the version are already running, and you
343
+ request 4, 2 more will be started. If 4 workers for the version are already
344
+ running, and you request 2, 2 will be stopped.
345
+ * ` proxy promote workerVersion workerCount ` - Works identical to the
346
+ ` proxy version ` command, except this will flag the version as active/live,
347
+ resulting in the Proxy Config file being updated with the new `defaultVersion`.
348
+ * ` proxy info ` - Fetch information about the proxy service.
349
+
350
+
351
+
280
352
## Tests & Code Coverage
281
353
282
354
Download and install:
@@ -285,20 +357,20 @@ Download and install:
285
357
cd node-cluster-service
286
358
npm install
287
359
288
- Now test:
360
+ Now test:
289
361
290
362
npm test
291
363
292
364
View code coverage in any browser:
293
365
294
366
coverage/lcov-report/index.html
295
367
296
-
368
+
297
369
## Change Log
298
370
299
371
[ Change Log] ( https://github.com/godaddy/node-cluster-service/blob/master/CHANGELOG.md )
300
372
301
-
373
+
302
374
303
375
## License
304
376
0 commit comments