This repository was archived by the owner on Sep 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Support rolling restart in tick-cluster #96
Open
mennopruijssers
wants to merge
2
commits into
master
Choose a base branch
from
feature/tick-cluster-rolling-restart
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| 'use strict'; | ||
|
|
||
| var _ = require('lodash'); | ||
| var async = require('async'); | ||
| var childProc = require('child_process'); | ||
| var color = require('cli-color'); | ||
| var farmhash = require('farmhash').hash32; | ||
|
|
@@ -318,6 +319,11 @@ function onData(char) { | |
| state = 'readnum'; | ||
| process.stdout.write('terminate count: '); | ||
| break; | ||
| case 'r': | ||
| func = restartProc; | ||
| state = 'readnum'; | ||
| process.stdout.write('batch size: '); | ||
| break; | ||
| case 'K': | ||
| reviveProcs(); | ||
| break; | ||
|
|
@@ -519,6 +525,60 @@ function terminateProc(count) { | |
| }); | ||
| } | ||
|
|
||
| function restartProc(batchSize) { | ||
| if (batchSize === 0) { | ||
| return; | ||
| } | ||
| var coolDownDelay = 1000; | ||
|
|
||
| var processGroups = _.chain(procs) | ||
| .filter(function(proc) { | ||
| return !proc.killed && !proc.suspended; | ||
| }) | ||
| .chunk(batchSize) | ||
| .value(); | ||
|
|
||
| async.eachOfSeries(processGroups, restartProcessGroup, function() { | ||
| logMsg('cluster', color.green('rolling restart completed')); | ||
| }); | ||
|
|
||
| function restartProcessGroup(group, index, cb) { | ||
| logMsg('cluster', color.cyan('rolling restart batch: ' + (index + 1) + ' / ' + processGroups.length)); | ||
| async.each(group, restartSingleProcess, cb); | ||
| } | ||
|
|
||
| function restartSingleProcess(proc, done) { | ||
| var index = procs.indexOf(proc); | ||
|
|
||
| stopProcess(terminated); | ||
|
|
||
| function stopProcess(cb) { | ||
| logMsg(proc.port, color.green('pid ' + proc.pid) + color.red(' terminating ' + index)); | ||
| var hardKillTimer = setTimeout(function() { | ||
| logMsg(proc.port, color.green('pid ' + proc.pid) + color.red(' didn\'t terminate in 5 seconds. Hard killing...')); | ||
| proc.proc.kill('SIGKILL'); | ||
| }, 5000); | ||
| proc.proc.once('exit', function() { | ||
| clearTimeout(hardKillTimer); | ||
| logMsg(proc.port, color.green('pid ' + proc.pid) + color.green(' terminated.')); | ||
| proc.killed = Date.now(); | ||
| cb(); | ||
| }); | ||
| proc.proc.kill('SIGTERM'); | ||
| } | ||
|
|
||
| function terminated() { | ||
| setTimeout(startProcess, coolDownDelay); | ||
| } | ||
|
|
||
| function startProcess() { | ||
| logMsg(proc.port, color.red('restarting ' + index + ' after ') + color.green((Date.now() - proc.killed) + 'ms')); | ||
| procs[index] = new ClusterProc(proc.port); | ||
| setTimeout(done, coolDownDelay); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function startCluster() { | ||
| procs = []; // note module scope | ||
| for (var i = 0; i < procsToStart ; i++) { | ||
|
|
@@ -570,6 +630,7 @@ function displayMenu(logFn) { | |
| logFn('\tK\t\tRevive suspended or killed processes'); | ||
| logFn('\tl <count>\tSuspend processes'); | ||
| logFn('\tm <count>\tTerminate processes'); | ||
| logFn('\tr <batch size>\tRestart processes'); | ||
|
||
| logFn('\tp\t\tPrint out protocol stats'); | ||
| logFn('\tq\t\tQuit'); | ||
| logFn('\ts\t\tPrint out stats'); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add output to indicate it is backing out because of invalid input
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At all other places,
tick-clustersilently ignores incorrect input