From e71bf21c47734f02717ab84c8b4ab4921be23cd9 Mon Sep 17 00:00:00 2001 From: schneefux Date: Sat, 21 Oct 2017 12:42:14 +0200 Subject: add option to randomly drop jobs --- worker.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); -- cgit v1.3.1