summaryrefslogtreecommitdiff
path: root/jstests/aggregation
diff options
context:
space:
mode:
authorU-tellus\cwestin <cwestin@10gen.com>2011-06-13 12:04:13 -0700
committerU-tellus\cwestin <cwestin@10gen.com>2011-06-13 12:04:13 -0700
commitedaa0577b56906c6732dcbff3db41ca0056089c5 (patch)
tree65954667f5264d86cfa5b85c24d1709b9925e268 /jstests/aggregation
parent15e883cc8b668f0c9948d7752e76a5bd99120ad2 (diff)
downloadmongo-edaa0577b56906c6732dcbff3db41ca0056089c5.tar.gz
simple aggregation benchmark
Diffstat (limited to 'jstests/aggregation')
-rwxr-xr-xjstests/aggregation/mrabench.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/jstests/aggregation/mrabench.js b/jstests/aggregation/mrabench.js
new file mode 100755
index 00000000000..915076435c7
--- /dev/null
+++ b/jstests/aggregation/mrabench.js
@@ -0,0 +1,61 @@
+/*
+ In order to run this, you need to have a local copy of the usage data.
+
+ One way to do this is to dump and restore it using mongodump and mongorestore
+ */
+
+db = db.getSisterDB( "mongousage" )
+
+function rollupMap() {
+ emit( this._id.t , { total : this.value , unique : 1 } )
+}
+
+function rollupReduce(key, values) {
+ var res = { total : 0 , unique : 0 };
+ for ( var i=0; i<values.length; i++ ){
+ res.total += values[i].total;
+ res.unique += values[i].unique;
+ }
+ return res;
+}
+
+function mrrollups() {
+
+ res = db.gen.monthly.ip.mapReduce( rollupMap , rollupReduce ,
+ { out : "gen.monthly" } )
+ res.find().sort( { _id : -1 } ).forEach( printjsononeline )
+
+ res = db.gen.weekly.ip.mapReduce( rollupMap , rollupReduce ,
+ { out : "gen.weekly" } )
+ res.find().sort( { _id : -1 } ).forEach( printjsononeline )
+}
+
+function rollupMonthlyMR() {
+ resMonthlyMR = db.gen.monthly.ip.mapReduce( rollupMap , rollupReduce ,
+ { out: { inline : 1 }} )
+}
+
+function rollupWeeklyMR() {
+ resWeeklyMR = db.gen.weekly.ip.mapReduce( rollupMap , rollupReduce ,
+ { out : {inline : 1 }} )
+}
+
+function rollupMonthlyA() {
+ resMonthlyA = db.runCommand( { aggregate: "gen.monthly.ip", pipeline : [
+ { $group : {
+ _id : { month: "_id.t" },
+ total : { $sum : "$value" },
+ unique : { $sum : 1 }
+ }}
+ ]});
+}
+
+function rollupWeeklyA() {
+ resWeeklyA = db.runCommand( { aggregate: "gen.weekly.ip", pipeline : [
+ { $group : {
+ _id : { month: "_id.t" },
+ total : { $sum : "$value" },
+ unique : { $sum : 1 }
+ }}
+ ]});
+}