From b8114919a5c55af6ce5746ac022ec78bf41ff126 Mon Sep 17 00:00:00 2001 From: Mircea Danila Dumitrescu Date: Mon, 12 May 2014 09:42:15 +0100 Subject: [PATCH] Less browser verbosity and WIP: Packet generator --- bin/generator-config.js | 10 ++++++ bin/generator.js | 46 ++++++++++++++++++++++++++++ examples/event-stream/event-put.html | 6 ++-- lib/cube/aggregator.js | 2 +- 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 bin/generator-config.js create mode 100644 bin/generator.js diff --git a/bin/generator-config.js b/bin/generator-config.js new file mode 100644 index 0000000..4727a1e --- /dev/null +++ b/bin/generator-config.js @@ -0,0 +1,10 @@ +module.exports = { + "packetsInInterval": 10000, + "intervalInMS": 60000, + "sampleRateInMS": 100, + "data": { + "country": ["US", "US", "US", "US", "US", "US", "US", "US", "US", "US", "US", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "GB", "IN", "IN", "IN", "IN", "IN", "IN", "FR", "FR", "FR", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "JP", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "GA", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"], + "device": ["web", "iphone", "android"], + "gender": ["male", "male", "male", "female", "female", "female", "female", "female", "female", "female"] + } +}; \ No newline at end of file diff --git a/bin/generator.js b/bin/generator.js new file mode 100644 index 0000000..482f6a1 --- /dev/null +++ b/bin/generator.js @@ -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); + } +} \ No newline at end of file diff --git a/examples/event-stream/event-put.html b/examples/event-stream/event-put.html index caf0fcf..962cbd7 100644 --- a/examples/event-stream/event-put.html +++ b/examples/event-stream/event-put.html @@ -44,8 +44,10 @@

Streaming Events - Put

} })); index++; - console.log("sent", index); - }, 100); + if (index % 100 === 0) { + console.log("sent", index); + } + }, 5); }; socket.onmessage = function (message) { diff --git a/lib/cube/aggregator.js b/lib/cube/aggregator.js index 6ca13fa..7a8fa65 100644 --- a/lib/cube/aggregator.js +++ b/lib/cube/aggregator.js @@ -470,7 +470,7 @@ exports.register = function (dbs, endpoints, options) { }; options.aggregations.forEach(function (aggregationObject) { - validateAndRunAggregation(aggregationObject, 20); + validateAndRunAggregation(aggregationObject, 1000); }); } ;