1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 10:12:41 +01:00

Decrease JX.Leader lease duration from 16,000ms to 1,500ms and usurp more aggressively

Summary:
Ref T12573. `JX.Leader` synchronizes the Aphlict connection across multiple windows.

Currently, we only test to see if the leader window has been closed every 16 seconds. Instead, test every 1.5 seconds.

Also, make windows keep trying to become the leader forever. This was removed previously (in D15806) but I think that change decreased robustness here.

Test Plan:
  - Opened two windows to the "Realtime" tab in DarkConsole.
  - Saw one become the leader and one become a follower.
  - (Optionally, wait for 10 seconds here to test the "keep trying to become the leader" behavior.)
  - Closed the leader.
  - Saw the follower become the leader after ~1.5 seconds.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12573

Differential Revision: https://secure.phabricator.com/D17703
This commit is contained in:
epriestley 2017-04-17 12:10:29 -07:00
parent f394fefe6f
commit 28c68eb4fd
2 changed files with 49 additions and 39 deletions

View file

@ -10,8 +10,8 @@ return array(
'conpherence.pkg.css' => 'a34d59bd',
'conpherence.pkg.js' => '5f86c17d',
'core.pkg.css' => '959330a2',
'core.pkg.js' => 'deabcef7',
'darkconsole.pkg.js' => 'e7393ebb',
'core.pkg.js' => '941db947',
'darkconsole.pkg.js' => '061371d8',
'differential.pkg.css' => '90b30783',
'differential.pkg.js' => 'ddfeb49b',
'diffusion.pkg.css' => '91c5d3a6',
@ -20,7 +20,7 @@ return array(
'maniphest.pkg.css' => '4845691a',
'maniphest.pkg.js' => '5ab2753f',
'rsrc/css/aphront/aphront-bars.css' => '231ac33c',
'rsrc/css/aphront/dark-console.css' => 'f54bf286',
'rsrc/css/aphront/dark-console.css' => '07dd8d38',
'rsrc/css/aphront/dialog-view.css' => '685c7e2d',
'rsrc/css/aphront/list-filter-view.css' => '5d6f0526',
'rsrc/css/aphront/multi-column.css' => '84cc6640',
@ -234,7 +234,7 @@ return array(
'rsrc/externals/javelin/lib/DOM.js' => '805b806a',
'rsrc/externals/javelin/lib/History.js' => 'd4505101',
'rsrc/externals/javelin/lib/JSON.js' => '69adf288',
'rsrc/externals/javelin/lib/Leader.js' => 'fea0eb47',
'rsrc/externals/javelin/lib/Leader.js' => '7f243deb',
'rsrc/externals/javelin/lib/Mask.js' => '8a41885b',
'rsrc/externals/javelin/lib/Quicksand.js' => '6b8ef10b',
'rsrc/externals/javelin/lib/Request.js' => '94b750d2',
@ -363,7 +363,7 @@ return array(
'rsrc/image/texture/table_header_tall.png' => 'd56b434f',
'rsrc/js/application/aphlict/Aphlict.js' => '5359e785',
'rsrc/js/application/aphlict/behavior-aphlict-dropdown.js' => 'caade6f2',
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'fb20ac8d',
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'd82b1ff9',
'rsrc/js/application/aphlict/behavior-aphlict-status.js' => '5e2634b9',
'rsrc/js/application/aphlict/behavior-desktop-notifications-control.js' => 'd5a2d665',
'rsrc/js/application/calendar/behavior-day-view.js' => '4b3c4443',
@ -482,7 +482,6 @@ return array(
'rsrc/js/core/behavior-autofocus.js' => '7319e029',
'rsrc/js/core/behavior-badge-view.js' => '8ff5e24c',
'rsrc/js/core/behavior-choose-control.js' => '327a00d1',
'rsrc/js/core/behavior-dark-console.js' => 'f411b6ae',
'rsrc/js/core/behavior-detect-timezone.js' => '4c193c96',
'rsrc/js/core/behavior-device.js' => 'bb1dd507',
'rsrc/js/core/behavior-drag-and-drop-textarea.js' => '484a6e22',
@ -521,6 +520,9 @@ return array(
'rsrc/js/core/behavior-user-menu.js' => '31420f77',
'rsrc/js/core/behavior-watch-anchor.js' => '9f36c42d',
'rsrc/js/core/behavior-workflow.js' => '0a3f3021',
'rsrc/js/core/darkconsole/DarkLog.js' => 'c8e1ffe3',
'rsrc/js/core/darkconsole/DarkMessage.js' => 'c48cccdd',
'rsrc/js/core/darkconsole/behavior-dark-console.js' => '3725c90c',
'rsrc/js/core/phtize.js' => 'd254d646',
'rsrc/js/phui/behavior-phui-dropdown-menu.js' => 'b95d6f7d',
'rsrc/js/phui/behavior-phui-file-upload.js' => 'b003d4fb',
@ -536,7 +538,7 @@ return array(
'symbols' => array(
'almanac-css' => 'dbb9b3af',
'aphront-bars' => '231ac33c',
'aphront-dark-console-css' => 'f54bf286',
'aphront-dark-console-css' => '07dd8d38',
'aphront-dialog-view-css' => '685c7e2d',
'aphront-list-filter-view-css' => '5d6f0526',
'aphront-multi-column-view-css' => '84cc6640',
@ -584,7 +586,7 @@ return array(
'javelin-aphlict' => '5359e785',
'javelin-behavior' => '61cbc29a',
'javelin-behavior-aphlict-dropdown' => 'caade6f2',
'javelin-behavior-aphlict-listen' => 'fb20ac8d',
'javelin-behavior-aphlict-listen' => 'd82b1ff9',
'javelin-behavior-aphlict-status' => '5e2634b9',
'javelin-behavior-aphront-basic-tokenizer' => 'b3a4b884',
'javelin-behavior-aphront-drag-and-drop-textarea' => '484a6e22',
@ -603,7 +605,7 @@ return array(
'javelin-behavior-conpherence-pontificate' => '55616e04',
'javelin-behavior-conpherence-search' => '9bbf3762',
'javelin-behavior-countdown-timer' => 'e4cc26b3',
'javelin-behavior-dark-console' => 'f411b6ae',
'javelin-behavior-dark-console' => '3725c90c',
'javelin-behavior-dashboard-async-panel' => '469c0d9e',
'javelin-behavior-dashboard-move-panels' => '408bf173',
'javelin-behavior-dashboard-query-panel-select' => '453c5375',
@ -720,7 +722,7 @@ return array(
'javelin-history' => 'd4505101',
'javelin-install' => '05270951',
'javelin-json' => '69adf288',
'javelin-leader' => 'fea0eb47',
'javelin-leader' => '7f243deb',
'javelin-magical-init' => '3010e992',
'javelin-mask' => '8a41885b',
'javelin-quicksand' => '6b8ef10b',
@ -774,6 +776,8 @@ return array(
'phabricator-content-source-view-css' => '4b8b05d4',
'phabricator-core-css' => '9f4cb463',
'phabricator-countdown-css' => '16c52f5c',
'phabricator-darklog' => 'c8e1ffe3',
'phabricator-darkmessage' => 'c48cccdd',
'phabricator-dashboard-css' => 'fe5b1869',
'phabricator-drag-and-drop-file-upload' => '58dea2fa',
'phabricator-draggable-list' => 'bea6e7f4',
@ -1118,6 +1122,16 @@ return array(
'javelin-dom',
'javelin-workflow',
),
'3725c90c' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-util',
'javelin-dom',
'javelin-request',
'phabricator-keyboard-shortcut',
'phabricator-darklog',
'phabricator-darkmessage',
),
'3ab51e2c' => array(
'javelin-behavior',
'javelin-behavior-device',
@ -1475,6 +1489,9 @@ return array(
'javelin-behavior',
'javelin-history',
),
'7f243deb' => array(
'javelin-install',
),
'8018ee50' => array(
'javelin-install',
'javelin-util',
@ -2066,6 +2083,20 @@ return array(
'javelin-dom',
'phabricator-draggable-list',
),
'd82b1ff9' => array(
'javelin-behavior',
'javelin-aphlict',
'javelin-stratcom',
'javelin-request',
'javelin-uri',
'javelin-dom',
'javelin-json',
'javelin-router',
'javelin-util',
'javelin-leader',
'javelin-sound',
'phabricator-notification',
),
'd835b03a' => array(
'javelin-behavior',
'javelin-dom',
@ -2173,14 +2204,6 @@ return array(
'f12cbc9f' => array(
'phui-oi-list-view-css',
),
'f411b6ae' => array(
'javelin-behavior',
'javelin-stratcom',
'javelin-util',
'javelin-dom',
'javelin-request',
'phabricator-keyboard-shortcut',
),
'f50152ad' => array(
'phui-timeline-view-css',
),
@ -2203,20 +2226,6 @@ return array(
'javelin-install',
'javelin-dom',
),
'fb20ac8d' => array(
'javelin-behavior',
'javelin-aphlict',
'javelin-stratcom',
'javelin-request',
'javelin-uri',
'javelin-dom',
'javelin-json',
'javelin-router',
'javelin-util',
'javelin-leader',
'javelin-sound',
'phabricator-notification',
),
'fbe497e7' => array(
'javelin-behavior',
'javelin-util',
@ -2242,9 +2251,6 @@ return array(
'javelin-view-visitor',
'javelin-util',
),
'fea0eb47' => array(
'javelin-install',
),
),
'packages' => array(
'conpherence.pkg.css' => array(

View file

@ -33,6 +33,8 @@ JX.install('Leader', {
events: ['onBecomeLeader', 'onReceiveBroadcast'],
statics: {
_leaseDuration: 1500,
_interval: null,
_timeout: null,
_broadcastKey: 'JX.Leader.broadcast',
@ -130,8 +132,10 @@ JX.install('Leader', {
// If we haven't installed an update timer yet, do so now. This will
// renew our lease every 5 seconds, making sure we hold it until the
// tab is closed.
if (!self._interval && lease.until > now + 10000) {
self._interval = window.setInterval(self._write, 5000);
var interval = parseInt(self._leaseDuration / 3, 10);
if (!self._interval && lease.until > now + (interval * 2)) {
self._interval = window.setInterval(self._write, interval);
}
self._becomeLeader();
@ -227,7 +231,7 @@ JX.install('Leader', {
_write: function() {
var self = JX.Leader;
var str = [self._id, ((+new Date()) + 16000)].join(':');
var str = [self._id, ((+new Date()) + self._leaseDuration)].join(':');
window.localStorage.setItem(self._leaderKey, str);
},
@ -311,8 +315,8 @@ JX.install('Leader', {
*/
_usurp: function() {
var self = JX.Leader;
self.call(JX.bag);
self._timeout = null;
self.call(JX.bag);
},