I have been trying to create a view module for an MVC framework.
I have 2 versions of code. One that does Sync and one Async.
I know that i should be using the Async version. However whenever I do a loadtest via AB I'm getting better results from the Sync version.
Am I doing something wrong? This is a sample of the code I'm testing
Sync Version:
var fs = require('fs'),
path = require('path'),
dot = require('dot');
Step = require('../libraries/step.js');
var view = function(){};
view.prototype = {
renderView : function(source, data, layout, callback)
{
var self = this;
if (typeof callback !== 'function') throw ViewCallbackException;
layout = layout ? layout : 'default';
(function(sources, datas, layouts, callbacks)
{
content = fs.readFileSync('./views/layouts/' + layouts + '/index.html', 'utf-8');
callbacks(null, content);
})(source, data, layout, callback);
}
}
Async Version:
var fs = require('fs'),
path = require('path'),
dot = require('dot');
Step = require('../libraries/step.js');
var view = function(){};
view.prototype = {
renderView : function(source, data, layout, callback)
{
var self = this;
if (typeof callback !== 'function') throw ViewCallbackException;
layout = layout ? layout : 'default';
(function(sources, datas, layouts, callbacks)
{
Step(
function()
{
fs.readFile('./views/layouts/' + layouts + '/index.html', 'utf-8', this);
},
callbacks
);
})(source, data, layout, callback);
}
}