Permalink
Browse files

Update mysql2 example

  • Loading branch information...
1 parent 3c797a9 commit c0a4300bac8f8c56c4afd28f577cce13d199524b @felixge committed Oct 3, 2012
@@ -1,27 +1,33 @@
-SHELL := /bin/bash
+benchmarks = poc mysql2
-fixtures = benchmark/fixtures/100k-blog-rows.mysql
-tsv_files = $(wildcard results/*.tsv)
-png_files = $(subst pdf,png,$(wildcard pdfs/*.pdf))
+include ../common.mk
-all: pdfs pngs tsvs fixtures
-fixtures: $(fixtures)
+#SHELL := /bin/bash
-tsvs: $(tsv_files)
+#benchmarks = poc mysql2
+#tsv_files = $(addprefix results/,$(addsuffix .tsv,$(benchmarks)))
+#fixtures = benchmark/fixtures/100k-blog-rows.mysql
+#png_files = $(subst pdf,png,$(wildcard pdfs/*.pdf))
-$(tsv_files): results/%.tsv: benchmark/%/run.js
- ./$^ | tee $@
+#all: pdfs pngs tsvs fixtures
-$(fixtures):
- curl -z '$@' -o '$@' 'http://felixge.s3.amazonaws.com/12/`basename $@`'
+#fixtures: $(fixtures)
-pdfs: $(tsv_files)
- cd pdfs && ./generate.r
+#tsvs: $(tsv_files)
-pngs: $(png_files)
+#$(tsv_files): results/%.tsv: benchmark/%/run.js
+ #./$^ | tee $@
-$(png_files): pngs/%.png: pdfs/%.pdf
- convert -density 300 $^ -resize 1024x $@
+#$(fixtures):
+ #curl -z '$@' -o '$@' 'http://felixge.s3.amazonaws.com/12/`basename $@`'
-.PHONY: all fixtures pdfs pngs tsvs
+#pdfs: $(tsv_files)
+ #cd pdfs && ./generate.r
+
+#pngs: $(png_files)
+
+#$(png_files): pngs/%.png: pdfs/%.pdf
+ #convert -density 300 $^ -resize 1024x $@
+
+#.PHONY: all fixtures pdfs pngs tsvs
Binary file not shown.
@@ -1,51 +0,0 @@
-var iterations = 200;
-
-var FixtureStream = require('./FixtureStream');
-
-var fields = [
- {name: 'id'},
- {name: 'title'},
- {name: 'text'},
- {name: 'created'},
- {name: 'updated'},
-];
-
-function printHeaders() {
- console.log(['hz', 'time', 'lib', 'rss', 'heapUsed', 'heapTotal'].join('\t'));
-}
-
-var printedHeaders = false;
-
-exports.run = function(name, benchmark) {
- if (!printedHeaders) {
- printHeaders();
- printedHeaders = true;
- }
-
- var stream = new FixtureStream(__dirname + '/fixtures/100k-blog-rows.mysql');
-
- function iterate() {
- if (!iterations--) {
- return;
- }
-
- var start = Date.now();
- benchmark(stream, fields, function(err, rows) {
- if (err) throw err;
-
- var duration = Date.now() - start;
- var hz = Math.round(rows / (duration / 1000));
- var memory = process.memoryUsage();
-
- console.log([hz, Date.now(), name, memory.rss, memory.heapUsed, memory.heapTotal].join('\t'));
-
- stream.removeAllListeners();
-
- process.nextTick(iterate);
- });
-
- stream.resume();
- }
-
- iterate();
-};
@@ -1,10 +1,7 @@
-#!/usr/bin/env node
-
-var common = require('../common');
var Parser = require('mysql/lib/protocol/Parser');
var RowDataPacket = require('mysql/lib/protocol/packets/RowDataPacket');
-common.run('mysql2', function(stream, fields, cb) {
+module.exports = function(stream, fields, cb) {
var parser = new Parser({packetParser: onPacket});
parser._nextPacketNumber = 8;
@@ -23,4 +20,4 @@ common.run('mysql2', function(stream, fields, cb) {
.on('end', function() {
cb(null, rows);
});
-});
+};
@@ -1,9 +1,6 @@
-#!/usr/bin/env node
-
-var common = require('../common');
var Protocol = require('./Protocol');
-common.run('poc', function(stream, fields, cb) {
+module.exports = function(stream, fields, cb) {
var protocol = new Protocol();
// This would normally happen when the fields are received
@@ -21,4 +18,4 @@ common.run('poc', function(stream, fields, cb) {
.on('end', function() {
cb(null, rows);
});
-});
+};
@@ -0,0 +1,26 @@
+#!/usr/bin/env node
+
+var common = require('../../common');
+var FixtureStream = require('./FixtureStream');
+var libName = process.argv[2];
+var lib = require('./' + libName);
+
+var rows = 100* 1000;
+var stream = new FixtureStream(__dirname + '/fixtures/100k-blog-rows.mysql');
+
+var fields = [
+ {name: 'id'},
+ {name: 'title'},
+ {name: 'text'},
+ {name: 'created'},
+ {name: 'updated'},
+];
+
+common.run(libName, function(cb) {
+ lib(stream, fields, function(err, rows) {
+ stream.removeAllListeners();
+
+ cb(err, {bytes: stream.length, rows: rows});
+ });
+ stream.resume();
+});
@@ -0,0 +1,64 @@
+#!/usr/bin/env RScript
+
+library(ggplot2)
+library(scales)
+
+outputWidth=8
+outputHeight=6
+
+files <- Sys.glob("results/*.tsv")
+
+results <- lapply(files, function(.file){
+ .in <- read.table(.file, sep="\t", header=T)
+ .in$time = ISOdatetime(1970,1,1,0,0,0) + .in$time / 1000
+ .in$mbit = (.in$bytes / (.in$duration / 1000) * 8) / 1024 / 1024
+ .in
+})
+
+results <- do.call(rbind, results)
+
+# Bar plot
+mysql2 = subset(results, benchmark == 'mysql2')
+poc = subset(results, benchmark == 'poc')
+
+medians <- data.frame(
+ lib = c('mysql2', 'poc'),
+ mbit = c(median(mysql2$mbit), median(poc$mbit))
+)
+
+p <- ggplot(medians, aes(lib, mbit, fill=lib))
+p <- p + scale_y_continuous(label=comma_format(),name="mbit (median)")
+p + geom_bar()
+
+ggsave(filename="pdfs/mbit-bar.pdf", width=outputWidth, height=outputHeight)
+
+# Jitter Graph
+p <- ggplot(results, aes(benchmark, mbit, color=benchmark))
+p <- p + scale_y_continuous(label=comma_format())
+p + geom_jitter()
+
+ggsave(filename="pdfs/mbit-jitter.pdf", width=outputWidth, height=outputHeight)
+
+# Line graph
+p <- ggplot(results, aes(number, mbit, color=benchmark))
+p <- p + scale_y_continuous(label=comma_format())
+#p <- p + scale_x_datetime(label=date_format("%H:%M:%S"))
+p + geom_line()
+
+ggsave(filename="pdfs/mbit-line.pdf", width=outputWidth, height=outputHeight)
+
+# Heap Used
+p <- ggplot(results, aes(number, heapUsed / 1024 / 1024, color=benchmark))
+p <- p + labs(y = "Heap Used (MB)")
+#p <- p + scale_x_datetime(label=date_format("%H:%M:%S"))
+p + geom_line()
+
+ggsave(filename="pdfs/heap-used-line.pdf", width=outputWidth, height=outputHeight)
+
+# Heap Total
+p <- ggplot(results, aes(number, heapTotal / 1024 / 1024, color=benchmark))
+p <- p + labs(y = "Heap Total (MB)")
+#p <- p + scale_x_datetime(label=date_format("%H:%M:%S"))
+p + geom_line()
+
+ggsave(filename="pdfs/heap-total-line.pdf", width=outputWidth, height=outputHeight)
@@ -1,50 +0,0 @@
-#!/usr/bin/env RScript
-
-library(ggplot2)
-library(scales)
-
-outputWidth=8
-outputHeight=6
-
-mysql2 <- read.table("../results/mysql2.tsv", sep="\t", header=T)
-poc <- read.table("../results/poc.tsv", sep="\t", header=T)
-
-mysql2$time = ISOdatetime(1970,1,1,0,0,0) + mysql2$time / 1000
-poc$time = ISOdatetime(1970,1,1,0,0,0) + poc$time / 1000
-
-combined <- merge(mysql2, poc, all=T)
-
-# Bar plot
-medians <- data.frame(
- lib = c("mysql2", "poc"),
- hz = c(median(mysql2$hz), median(poc$hz))
-)
-
-p <- ggplot(medians, aes(lib, hz, fill=lib))
-p <- p + scale_y_continuous(label=comma_format(),name="hz (median)")
-p + geom_bar()
-
-ggsave(filename="bar.pdf", width=outputWidth, height=outputHeight)
-
-# Jitter Graph
-p <- ggplot(combined, aes(lib, hz, color=lib))
-p <- p + scale_y_continuous(label=comma_format())
-p + geom_jitter()
-
-ggsave(filename="jitter.pdf", width=outputWidth, height=outputHeight)
-
-# Line graph
-p <- ggplot(combined, aes(time, hz, color=lib))
-p <- p + scale_y_continuous(label=comma_format())
-p <- p + scale_x_datetime(label=date_format("%H:%M:%S"))
-p + geom_line()
-
-ggsave(filename="line.pdf", width=outputWidth, height=outputHeight)
-
-# Memory Line graph
-p <- ggplot(combined, aes(time, heapUsed / 1024 / 1024, color=lib))
-p <- p + labs(y = "Heap Used (MB)")
-p <- p + scale_x_datetime(label=date_format("%H:%M:%S"))
-p + geom_line()
-
-ggsave(filename="memory-line.pdf", width=outputWidth, height=outputHeight)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Oops, something went wrong.

0 comments on commit c0a4300

Please sign in to comment.