Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extract retry package from livedata

  • Loading branch information...
commit c37d009d96feef10d975c80ee643944f003e42d3 1 parent 7341966
@awwx awwx authored n1mmy committed
View
4 packages/autoupdate/autoupdate_client.js
@@ -44,9 +44,7 @@ Autoupdate.newClientAvailable = function () {
-// XXX Livedata exporting this via DDP is a hack. See
-// packages/livedata/livedata_common.js
-var retry = new DDP._Retry({
+var retry = new Retry({
// Unlike the stream reconnect use of Retry, which we want to be instant
// in normal operation, this is a wacky failure. We don't want to retry
// right away, we can start slowly.
View
2  packages/autoupdate/package.js
@@ -5,7 +5,7 @@ Package.describe({
Package.on_use(function (api) {
api.use('webapp', 'server');
- api.use('deps', 'client');
+ api.use(['deps', 'retry'], 'client');
api.use(['livedata', 'mongo-livedata'], ['client', 'server']);
api.use('deps', 'client');
api.use('reload', 'client', {weak: true});
View
5 packages/livedata/livedata_common.js
@@ -115,8 +115,3 @@ stringifyDDP = function (msg) {
// state in the DDP session. Meteor.setTimeout and friends clear
// it. We can probably find a better way to factor this.
DDP._CurrentInvocation = new Meteor.EnvironmentVariable;
-
-
-// This is private and a hack. It is used by autoupdate_client. We
-// should refactor. Maybe a separate 'exponential-backoff' package?
-DDP._Retry = Retry;
View
4 packages/livedata/package.js
@@ -6,7 +6,8 @@ Package.describe({
Npm.depends({sockjs: "0.3.8", websocket: "1.0.8"});
Package.on_use(function (api) {
- api.use(['check', 'random', 'ejson', 'json', 'underscore', 'deps', 'logging'],
+ api.use(['check', 'random', 'ejson', 'json', 'underscore', 'deps',
+ 'logging', 'retry'],
['client', 'server']);
// It is OK to use this package on a server architecture without making a
@@ -33,7 +34,6 @@ Package.on_use(function (api) {
// Transport
api.use('reload', 'client', {weak: true});
api.add_files('common.js');
- api.add_files('retry.js', ['client', 'server']);
api.add_files(['sockjs-0.3.4.js', 'stream_client_sockjs.js'], 'client');
api.add_files('stream_client_nodejs.js', 'server');
api.add_files('stream_client_common.js', ['client', 'server']);
View
1  packages/retry/.gitignore
@@ -0,0 +1 @@
+.build*
View
10 packages/retry/package.js
@@ -0,0 +1,10 @@
+Package.describe({
+ summary: "Retry logic with exponential backoff",
+ internal: true
+});
+
+Package.on_use(function (api) {
+ api.use('underscore', ['client', 'server']);
+ api.export('Retry');
+ api.add_files('retry.js', ['client', 'server']);
+});
View
23 packages/livedata/retry.js → packages/retry/retry.js
@@ -1,24 +1,23 @@
// Retry logic with an exponential backoff.
+//
+// options:
+// baseTimeout: time for initial reconnect attempt (ms).
+// exponent: exponential factor to increase timeout each attempt.
+// maxTimeout: maximum time between retries (ms).
+// minCount: how many times to reconnect "instantly".
+// minTimeout: time to wait for the first `minCount` retries (ms).
+// fuzz: factor to randomize retry times by (to avoid retry storms).
Retry = function (options) {
var self = this;
_.extend(self, _.defaults(_.clone(options || {}), {
- // time for initial reconnect attempt.
- baseTimeout: 1000,
- // exponential factor to increase timeout each attempt.
+ baseTimeout: 1000, // 1 second
exponent: 2.2,
- // maximum time between reconnects. keep this intentionally
- // high-ish to ensure a server can recover from a failure caused
- // by load
+ // The default is high-ish to ensure a server can recover from a
+ // failure caused by load.
maxTimeout: 5 * 60000, // 5 minutes
- // time to wait for the first 2 retries. this helps page reload
- // speed during dev mode restarts, but doesn't hurt prod too
- // much (due to CONNECT_TIMEOUT)
minTimeout: 10,
- // how many times to try to reconnect 'instantly'
minCount: 2,
- // fuzz factor to randomize reconnect times by. avoid reconnect
- // storms.
fuzz: 0.5 // +- 25%
}));
self.retryTimer = null;
Please sign in to comment.
Something went wrong with that request. Please try again.