|
@@ -9,24 +9,8 @@ var cluster = require('cluster')
|
|
|
, mongoose = require('mongoose')
|
|
|
, async = require('async')
|
|
|
, conn = mongoose.connect('mongodb://localhost/hello_world')
|
|
|
- , Sequelize = require("sequelize")
|
|
|
- , sequelize = new Sequelize('hello_world', 'benchmarkdbuser', 'benchmarkdbpass', {
|
|
|
- host: 'localhost',
|
|
|
- logging: false,
|
|
|
- define: { timestamps: false },
|
|
|
- maxConcurrentQueries: 100,
|
|
|
- pool: { maxConnections: 800, maxIdleTime: 30 }
|
|
|
- })
|
|
|
- , World = sequelize.define('World', {
|
|
|
- randomNumber: Sequelize.INTEGER
|
|
|
- }, {
|
|
|
- freezeTableName: true
|
|
|
- })
|
|
|
- , Fortune = sequelize.define('Fortune', {
|
|
|
- message: Sequelize.STRING
|
|
|
- }, {
|
|
|
- freezeTableName: true
|
|
|
- });
|
|
|
+ , Mapper = require('mapper')
|
|
|
+ , connMap = { user: 'benchmarkdbuser', password: 'benchmarkdbpass', database: 'hello_world' };
|
|
|
|
|
|
var Schema = mongoose.Schema
|
|
|
, ObjectId = Schema.ObjectId;
|
|
@@ -37,6 +21,9 @@ var WorldSchema = new Schema({
|
|
|
}, { collection : 'world' });
|
|
|
var MWorld = conn.model('World', WorldSchema);
|
|
|
|
|
|
+Mapper.connect(connMap, {verbose: false, strict: false});
|
|
|
+var World = Mapper.map("World", "id", "randomNumber");
|
|
|
+var Fortune = Mapper.map("Fortune", "id", "message");
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
// Fork workers.
|
|
@@ -93,14 +80,14 @@ if (cluster.isMaster) {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- app.get('/sequelize', function(req, res) {
|
|
|
+ app.get('/mysql-orm', function(req, res) {
|
|
|
var queries = req.query.queries || 1
|
|
|
, worlds = []
|
|
|
, queryFunctions = [];
|
|
|
|
|
|
for (var i = 1; i <= queries; i++ ) {
|
|
|
queryFunctions.push(function(callback) {
|
|
|
- World.find(Math.floor(Math.random()*10000) + 1).success(function (world) {
|
|
|
+ World.findById(Math.floor(Math.random()*10000) + 1, function (err, world) {
|
|
|
worlds.push(world);
|
|
|
callback(null, 'success');
|
|
|
});
|
|
@@ -113,7 +100,7 @@ if (cluster.isMaster) {
|
|
|
});
|
|
|
|
|
|
app.get('/fortune', function(req, res) {
|
|
|
- Fortune.findAll().success(function (fortunes) {
|
|
|
+ Fortune.all(function (err, fortunes) {
|
|
|
var newFortune = Fortune.build({message: "Additional fortune added at request time."});
|
|
|
fortunes.push(newFortune);
|
|
|
fortunes.sort(sortFortunes);
|