diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-10-21 12:42:14 +0200 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-10-21 12:42:14 +0200 |
| commit | e71bf21c47734f02717ab84c8b4ab4921be23cd9 (patch) | |
| tree | 16b4865c0224cfe1addac7f9b2afd54e3eb4977b | |
| parent | 3ebe9932642bf96b888946d555420c4b4579afda (diff) | |
| download | cruncher-e71bf21c47734f02717ab84c8b4ab4921be23cd9.tar.gz cruncher-e71bf21c47734f02717ab84c8b4ab4921be23cd9.zip | |
add option to randomly drop jobs
| -rw-r--r-- | worker.js | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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); |
