-
-
Save jbr/310204 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Forward: | |
Instantiating Query Object | |
Selecting SELECT ... FROM ... FOR UPDATE ... (501) | |
Did not timeout! Yay fast database | |
Measured select at 0 seconds | |
Instantiating Query Object | |
Executing INSERT ... (501) | |
Did not timeout! Yay fast database | |
Measured select at 0 seconds | |
Executing INSERT ... (501) | |
Did not timeout! Yay fast database | |
Measured select at 0 seconds | |
Backward: | |
Instantiating Query Object | |
Selecting SELECT ... FROM ... FOR UPDATE ... (793) | |
Measured select at 0 seconds | |
Did not timeout! Yay fast database | |
Instantiating Query Object | |
Executing INSERT ... (793) | |
Measured select at 0 seconds | |
Did not timeout! Yay fast database | |
Executing INSERT ... (793) | |
Measured select at 0 seconds | |
Did not timeout! Yay fast database |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Forward: | |
Instantiating Query Object | |
Selecting SELECT ... FROM ... FOR UPDATE ... on #<Object:0x11f6750> | |
Did not timeout! Yay fast database! | |
Measured select at 1.00 seconds | |
Instantiating Query Object | |
Executing INSERT ... on #<Object:0x11f6750> | |
Did not timeout! Yay fast database! | |
Measured select at 1.00 seconds | |
Executing INSERT ... on #<Object:0x11f6750> | |
Did not timeout! Yay fast database! | |
Measured select at 1.00 seconds | |
Backward: | |
Instantiating Query Object | |
Selecting SELECT ... FROM ... FOR UPDATE ... on #<Object:0x11f4ea0> | |
Measured select at 1.00 seconds | |
Did not timeout! Yay fast database! | |
Instantiating Query Object | |
Executing INSERT ... on #<Object:0x11f4ea0> | |
Measured select at 1.00 seconds | |
Did not timeout! Yay fast database! | |
Executing INSERT ... on #<Object:0x11f4ea0> | |
Measured select at 1.00 seconds | |
Did not timeout! Yay fast database! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wrap = function (original, decoration) { | |
var replacement = {} | |
for (var key in original) replacement[key] = (function() { | |
var inner = original[key], outer = decoration[key] | |
if (typeof outer === 'function' && typeof inner === 'function') { | |
return function() { return outer.apply (inner, arguments) } | |
} else return outer || inner }) () | |
return replacement } | |
pipeline = function (item, decorators) { | |
for each (var decorator in decorators) | |
item = wrap (item, decorator) | |
return item } | |
BasicQuery = { | |
transaction: function (transaction) { | |
var pipe = this, connection = pipe.allocateConnection (pipe.opts) | |
transaction ({ | |
query: function (string) { pipe.query (pipe.buildQuery (string, connection), pipe.opts)}, | |
execute: function (string) { pipe.execute (pipe.buildQuery (string, connection), pipe.opts)} }) }, | |
allocateConnection: function (opts) { return { connectionId: Math.round (Math.random() * 1000) }}, | |
buildQuery: function (queryString, connection) { | |
print ("Instantiating Query Object") | |
return { | |
connection: connection, | |
queryString: queryString } }, | |
withOptions: function (options) { | |
this.opts = options | |
return this }, | |
execute: function (query, options) | |
{ print ("Executing " + query.queryString + " (" + query.connection.connectionId + ")") }, | |
query: function (query, options) | |
{ print ("Selecting " + query.queryString + " (" + query.connection.connectionId + ")") } } | |
Memoizer = { | |
memos: {}, | |
allocateConnection: function (options) { | |
connection = this (options) | |
Memoizer.memos[connection] = {} | |
return connection }, | |
buildQuery: function (queryString, connection) { | |
if (typeof Memoizer.memos [connection] [queryString] === 'undefined') | |
Memoizer.memos [connection] [queryString] = this (queryString, connection) | |
return Memoizer.memos [connection] [queryString] } } | |
Stats = { | |
query: function () { Stats.stats.apply (this, arguments) }, | |
execute: function () { Stats.stats.apply (this, arguments) }, | |
stats: function (query, options) { | |
if (options.stats) { | |
var time = (new Date()).getTime() | |
var value = this (query, options) | |
print ("Measured select at " + ((new Date()).getTime() - time) + " seconds") | |
return value | |
} else return this (query, options) } } | |
TimeoutMonitor = { | |
query: function () { TimeoutMonitor.monitor.apply (this, arguments) }, | |
execute: function () { TimeoutMonitor.monitor.apply (this, arguments) }, | |
monitor: function (query, options) { | |
value = this (query, options) | |
print ('Did not timeout! Yay fast database') | |
return value } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load ('olympic.js') | |
var forward = [ TimeoutMonitor, Stats, Memoizer ], | |
options = { stats: true, connectionPoolSize: 20, timeout: 1000 } | |
print ("Forward:") | |
pipeline (BasicQuery, forward) | |
.withOptions (options) | |
.transaction (function (t) { | |
t.query ('SELECT ... FROM ... FOR UPDATE ...') | |
t.execute ('INSERT ...') | |
t.execute ('INSERT ...') }) | |
print ("\nBackward:") | |
pipeline (BasicQuery, forward.reverse()) | |
.withOptions (options) | |
.transaction (function (t) { | |
t.query ('SELECT ... FROM ... FOR UPDATE ...') | |
t.execute ('INSERT ...') | |
t.execute ('INSERT ...') }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment