Skip to content

Commit

Permalink
some updates of the program to handle performance testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePrimeagen committed Aug 25, 2015
1 parent 533f6b2 commit 2d80e01
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/Model.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var ModelRoot = require("./ModelRoot");
var ModelDataSourceAdapter = require("./ModelDataSourceAdapter");

var RequestQueue = require("./request/RequestQueue");
var RequestQueue = require("./request/RequestQueueRx");
var GetResponse = require("./response/GetResponse");
var ModelResponse = require("./response/ModelResponse");
var SetResponse = require("./response/SetResponse");
Expand Down
29 changes: 29 additions & 0 deletions lib/request/RequestQueueRx.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var Rx = require('rx');
var RequestQueue = require('./RequestQueue');
var RequestQueueV2 = require('./RequestQueueV2');

function RequestQueueRx(model, scheduler) {
this.model = model;
this.scheduler = scheduler;
this.requests = this._requests = [];
}

// RX MONKEY PATCH
var getRequest = RequestQueueV2.prototype.get;
RequestQueueRx.prototype.get = function(paths) {
debugger
var self = this;
return Rx.Observable.create(function(observer) {
debugger
getRequest.call(self, paths, paths, function() {
observer.onNext();
observer.onCompleted();
});
});
};

RequestQueueRx.prototype.set = RequestQueue.prototype.set;
RequestQueueRx.prototype.call = RequestQueue.prototype.call;
RequestQueueRx.prototype.removeRequest = RequestQueueV2.prototype.removeRequest;

module.exports = RequestQueueRx;
2 changes: 1 addition & 1 deletion lib/request/RequestQueueV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var GetRequest = require('./GetRequestV2');
function RequestQueueV2(model, scheduler) {
this.model = model;
this.scheduler = scheduler;
this._requests = [];
this.requests = this._requests = [];
}

RequestQueueV2.prototype = {
Expand Down
25 changes: 25 additions & 0 deletions performance/TriggerDataSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Rx = require('rx');
var TriggerDataSource = function TriggerDataSource(response) {
this.response = response;
this._triggers = [];
};

TriggerDataSource.prototype = {
get: function(paths) {
var self = this;
return Rx.Observable.create(function(observer) {
self._triggers.push(function() {
observer.onNext(self.response);
observer.onCompleted();
});
});
},
trigger: function() {
this._triggers.forEach(function(t) {
t();
});
this._triggers = [];
}
};

module.exports = TriggerDataSource;
8 changes: 1 addition & 7 deletions performance/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,8 @@ var compose = function(f, g) {
var models = testConfig.models;
var formats = testConfig.formats;
var tests = testConfig.get;
var suite = testConfig.suite;

suite.tests = testSuiteGenerator({
models: {
'model': models.modelWithSource
},
formats: ['PathMap', 'JSON']
});
var suite = require('./tests/get/request-queue');

var gc = function() {
if (typeof window !== 'undefined' && window && window.gc) {
Expand Down
11 changes: 2 additions & 9 deletions performance/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ var device;
var models = testConfig.models;
var formats = testConfig.formats;
var tests = testConfig.get;
var suite = testConfig.suite;
var suite = require('./tests/get/request-queue');

try {
// Needs explicit 'npm install nf-falcor-device-perf'. Not part of package.json
device = require('nf-falcor-device-perf');

suite.tests = testSuiteGenerator({
models: {
'model': models.modelWithSource
},
formats: ['PathMap', 'JSON']
});

device.runTests(suite, testRunner, testSuiteGenerator, CSVFormatter);

} catch (e) {
console.log('Not running device tests. Need to npm install "nf-falcor-device-perf"');
}
}
11 changes: 2 additions & 9 deletions performance/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ var compose = function(f, g) {
var models = testConfig.models;
var formats = testConfig.formats;
var tests = testConfig.get;
var suite = testConfig.suite;

suite.tests = testSuiteGenerator({
models: {
'model': models.modelWithSource
},
formats: ['PathMap', 'JSON']
});
var suite = require('./tests/get/request-queue');

var gc = function() {
if (typeof global !== 'undefined' && global && global.gc) {
return function() {
global.gc();
}
};
} else {
return null;
}
Expand Down
5 changes: 2 additions & 3 deletions performance/testRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function run(suites, env, onBenchmarkComplete, onComplete, log) {
}).
on('error', function(e) {
var error = e.target.error;
debugger

log(error);
log(error.stack);
Expand All @@ -86,9 +87,7 @@ function run(suites, env, onBenchmarkComplete, onComplete, log) {
_run();
}
}).
run({
async: true
});
run({defer: false});
};

_run();
Expand Down
51 changes: 51 additions & 0 deletions performance/tests/get/request-queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var Model = require('./../../../lib').Model;
var simple = [['videos', 1234, 'summary']];
var noOp = function() {};
var RequestQueueV2 = require('./../../../lib/request/RequestQueueV2');
var RequestQueue = require('./../../../lib/request/RequestQueue');
var ImmediateScheduler = require('./../../../lib/schedulers/ImmediateScheduler');

var TriggerDataSource = require('./../../TriggerDataSource');
var triggerSource = new TriggerDataSource({
jsonGraph: {
videos: {
1234: {
summary: 'Test'
}
}
}
});
var triggerModel = new Model({
source: triggerSource
});
var triggerQV2 = new RequestQueueV2(triggerModel, new ImmediateScheduler());
var triggerQ = new RequestQueue(triggerModel, new ImmediateScheduler());

module.exports = {
name: 'RequestQueue',
tests: {
'RequestQueueV2.get#Simple Path': function(done) {
triggerQV2.get(simple, simple, function() {
});
triggerSource.trigger();
},

'RequestQueue(OLD).get#Simple Path': function(done) {
triggerQ.get(simple).subscribe(noOp, noOp, function() {
});
triggerSource.trigger();
},

'RequestQueueV2.batch-and-dedupe#Simple Path': function(done) {
triggerQV2.get(simple, simple, function() { });
triggerQV2.get(simple, simple, function() { });
triggerSource.trigger();
},

'RequestQueue(OLD).batch-and-dedupe#Simple Path': function(done) {
triggerQ.get(simple).subscribe(noOp, noOp, function() { });
triggerQ.get(simple).subscribe(noOp, noOp, function() { });
triggerSource.trigger();
}
}
};
25 changes: 25 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var Model = require('./lib').Model;
var simple = [['videos', 1234, 'summary']];
var noOp = function() {};
var RequestQueueV2 = require('./lib/request/RequestQueueV2');
var ImmediateScheduler = require('./lib/schedulers/ImmediateScheduler');
var TriggerDataSource = require('./performance/TriggerDataSource');
var triggerSource = new TriggerDataSource({
jsonGraph: {
videos: {
1234: {
summary: 'Test'
}
}
}
});
var triggerModel = new Model({
source: triggerSource
});
var triggerQV2 = new RequestQueueV2(triggerModel, new ImmediateScheduler());

for (var i = 0; i < 200000; ++i) {
triggerQV2.get(simple, simple, function() { });
triggerQV2.get(simple, simple, function() { });
triggerSource.trigger();
}
2 changes: 1 addition & 1 deletion test/internal/request/GetRequest.batch.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var Model = require('./../../../lib').Model;
var LocalDataSource = require('./../../data/LocalDataSource');
var Cache = require('./../../data/Cache.js');
var noOp = function() {};
var zipArray = require('./../../zipSpy');
var zipSpy = require('./../../zipSpy');

describe('#batch', function() {
var videos1234 = ['videos', 1234, 'summary'];
Expand Down
2 changes: 1 addition & 1 deletion test/internal/request/RequestQueue.get.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('#get', function() {
disposable2();
});

it.only('should make a couple requests where only part of the second request is deduped then both are disposed.', function(done) {
it('should make a couple requests where only part of the second request is deduped then both are disposed.', function(done) {
var scheduler = new ImmediateScheduler();
var getSpy = sinon.spy();
var source = new LocalDataSource(Cache(), {wait: 100});
Expand Down

0 comments on commit 2d80e01

Please sign in to comment.