Skip to content

Commit

Permalink
Less browser verbosity and WIP: Packet generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Mircea Danila Dumitrescu committed May 12, 2014
1 parent d150c80 commit b811491
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 3 deletions.
10 changes: 10 additions & 0 deletions bin/generator-config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions bin/generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict";
var options = require("./generator-config.js"),
samples = Math.floor(options.intervalInMS / options.sampleRateInMS);

function rnd_snd() {
return (Math.random() * 2 - 1) + (Math.random() * 2 - 1) + (Math.random() * 2 - 1);
}

function rnd(min, max, mean, stdev) {
var x = Math.round(rnd_snd() * stdev + mean);
if (x < min) {
return 0;
}
if (x > max) {
return max;
}
}

function computePacketsPerSampleInInterval(packets, samples) {
var a = [],
i,
mean = options.packetsInInterval / samples,
deviation = mean,
remainingPackets;
remainingPackets = packets;
for (i = 0; i < samples; i++) {
mean = remainingPackets / (samples - i);
a[i] = rnd(mean, deviation);
remainingPackets -= a[i];
}
return a;
}

function sendPackets(n) {
var i;
for (i = 0; i < n; i++) {
sendPacket();
}
}

function sendForIntervals(a) {
var i;
for (i = 0; i < a.length; i++) {
setTimeout(sendPackets(a[i]), i * options.sampleRateInMS);
}
}
6 changes: 4 additions & 2 deletions examples/event-stream/event-put.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ <h1>Streaming Events - Put</h1>
}
}));
index++;
console.log("sent", index);
}, 100);
if (index % 100 === 0) {
console.log("sent", index);
}
}, 5);
};

socket.onmessage = function (message) {
Expand Down
2 changes: 1 addition & 1 deletion lib/cube/aggregator.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ exports.register = function (dbs, endpoints, options) {
};

options.aggregations.forEach(function (aggregationObject) {
validateAndRunAggregation(aggregationObject, 20);
validateAndRunAggregation(aggregationObject, 1000);
});
}
;
Expand Down

0 comments on commit b811491

Please sign in to comment.