summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-10-21 12:42:14 +0200
committerschneefux <schneefux+commit@schneefux.xyz>2017-10-21 12:42:14 +0200
commite71bf21c47734f02717ab84c8b4ab4921be23cd9 (patch)
tree16b4865c0224cfe1addac7f9b2afd54e3eb4977b
parent3ebe9932642bf96b888946d555420c4b4579afda (diff)
downloadcruncher-e71bf21c47734f02717ab84c8b4ab4921be23cd9.tar.gz
cruncher-e71bf21c47734f02717ab84c8b4ab4921be23cd9.zip
add option to randomly drop jobs
-rw-r--r--worker.js10
1 files changed, 9 insertions, 1 deletions
diff --git a/worker.js b/worker.js
index a1c99a5..691e57b 100644
--- a/worker.js
+++ b/worker.js
@@ -29,7 +29,9 @@ const RABBITMQ_URI = process.env.RABBITMQ_URI,
BATCHSIZE = parseInt(process.env.BATCHSIZE) || 1000,
LOAD_TIMEOUT = parseInt(process.env.LOAD_TIMEOUT) || 5, // s
// wait time before next batch
- SLOWMODE = parseFloat(process.env.SLOWMODE) || 0; // s
+ SLOWMODE = parseFloat(process.env.SLOWMODE) || 0, // s
+ // chance that a message will be taken into account for statistics (drops others for performance)
+ RELIABILITY = parseFloat(process.env.RELIABILITY) || 1.0;
const logger = new (winston.Logger)({
transports: [
@@ -130,6 +132,12 @@ amqp.connect(RABBITMQ_URI).then(async (rabbit) => {
return;
}
+ if (RELIABILITY < 1.0 && Math.random() > RELIABILITY) {
+ // randomly drop some data :)
+ await ch.nack(msg, false, false);
+ return;
+ }
+
participants.add(msg.content.toString());
buffer.add(msg);
if (timeout == undefined) timeout = setTimeout(tryCrunch, LOAD_TIMEOUT*1000);