Cscott has uploaded a new change for review.
https://gerrit.wikimedia.org/r/243399
Change subject: Bring back the completion hint for the batcher
......................................................................
Bring back the completion hint for the batcher
This avoids being quite as critically dependent on the scheduling of
setTimeout() -vs- process.nextTick() in order to ensure good batch
sizes, while (hopefully) avoiding having to wait for the timeout to
expire for the final batch.
Change-Id: I84d9d0ef3ec699d1a78d36e09fd57f414453b892
---
M lib/mediawiki.Batcher.js
M lib/mediawiki.TokenTransformManager.js
2 files changed, 23 insertions(+), 4 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid
refs/changes/99/243399/1
diff --git a/lib/mediawiki.Batcher.js b/lib/mediawiki.Batcher.js
index 5b9569b..c11f3b2 100644
--- a/lib/mediawiki.Batcher.js
+++ b/lib/mediawiki.Batcher.js
@@ -52,10 +52,15 @@
}
}
- // Don't dispatch right away, but set a 0-value timeout
+ // Don't dispatch right away, but set a short timeout
// to ensure that we keep the event loop alive. This also
// ensures that we make forward progress by dispatching a
// batch whenever the batcher is idle.
+ //
+ // To prevent always waiting for this timeout to expire when
+ // sending the final batch, the #completionHint method below
+ // will hurry things up at the end of the token processing
+ // pipeline.
//
// As long as we get new requests within that timeout period,
// keep postponing the premature dispatch. When the current
@@ -63,7 +68,7 @@
// automatically above. This kicks off the
// dispatch -> API response -> dispatch -> .. loop
// which keeps things moving.
- this.resetForwardProgressTimer();
+ this.resetForwardProgressTimer(false);
};
Batcher.prototype.clearForwardProgressTimer = function() {
@@ -73,7 +78,7 @@
}
};
-Batcher.prototype.resetForwardProgressTimer = function() {
+Batcher.prototype.resetForwardProgressTimer = function(rightNow) {
this.clearForwardProgressTimer();
// `setTimeout` is guaranteed to be called *after*
// `process.nextTick`, and `Promise#then` callbacks (but not after
@@ -81,7 +86,19 @@
// Parsoid pipeline uses `Promise#then` or `process.nextTick`,
// then the forward progress timer will be invoked only after all
// available work has been done.
- this.forwardProgressTimer =
setTimeout(this.makeForwardProgress.bind(this), 0);
+ this.forwardProgressTimer = setTimeout(
+ this.makeForwardProgress.bind(this),
+ rightNow ? 0 : 5
+ );
+};
+
+// A hint that a pipeline has finished, and so we might want to send off
+// the next batch sooner rather than waiting for the forward progress timer
+// to expire.
+Batcher.prototype.completionHint = function() {
+ if (this.forwardProgressTimer) {
+ this.resetForwardProgressTimer(true);
+ }
};
/**
diff --git a/lib/mediawiki.TokenTransformManager.js
b/lib/mediawiki.TokenTransformManager.js
index f99a79e..677df99 100644
--- a/lib/mediawiki.TokenTransformManager.js
+++ b/lib/mediawiki.TokenTransformManager.js
@@ -424,6 +424,8 @@
// Reset accumulators
this.reset();
}
+ // This might be a good time to send off a batch.
+ this.env.batcher.completionHint();
};
// Debug counter, provides an UID for transformTokens calls so that callbacks
--
To view, visit https://gerrit.wikimedia.org/r/243399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I84d9d0ef3ec699d1a78d36e09fd57f414453b892
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits