I can do a simple load test of 50000 contacts CSV file with "siege" - a command line load testing tool. Siege unable run those test. It will print following output.
siege command
siege -d10 -c50 http://localhost:3000
index.js
// require express and create an instance of it
const express = require('express');
const rethinkdb = require("rethinkdb");
const fs = require("fs");
const convertHrtime = require('convert-hrtime');
const csv2jsonConverter = require("csvtojson").Converter;
const app = express();
const router = express.Router();
const db = require('./db');
const csvFilePath = __dirname + "/csv/50000-contacts.csv";
db.init();
app.use(db.createConnection);
app.get('/', function (req, res) {
try {
let startTime = process.hrtime();
let objCsv2jsonConverter = new csv2jsonConverter({});
console.log('startTime', startTime);
fs.createReadStream(csvFilePath).pipe(objCsv2jsonConverter);
objCsv2jsonConverter.on("end_parsed", (arrCSVContacts) => {
console.log("- Actual CSV records length", arrCSVContacts.length, "-", convertHrtime(process.hrtime(startTime)));
return res.status(200).json({ 'total_records': arrCSVContacts.length, 'Time': convertHrtime(process.hrtime(startTime)) });
});
} catch (e) {
throw new Error(e);
}
});
// change the 404 message modifing the middleware
app.use(function (req, res, next) {
res.status(404).send("Sorry, that route doesn't exist. Have a nice day :)");
});
// start the server in the port 3000 !
app.listen(3000, function () {
console.log('Example app listening on port 3000.');
});
// close DB connection
app.use(db.closeConnection);
output
** SIEGE 4.0.2
** Preparing 50 concurrent users for battle.
The server is now under siege...^C
Lifting the server siege...
Transactions: 0 hits
Availability: 0.00 %
Elapsed time: 49.21 secs
Data transferred: 0.00 MB
Response time: 0.00 secs
Transaction rate: 0.00 trans/sec
Throughput: 0.00 MB/sec
Concurrency: 0.00
Successful transactions: 0
Failed transactions: 0
Longest transaction: 0.00
Shortest transaction: 0.00
But rather to add csv file reading the code, if I shall write simple console log then it will print the whole log I don't know how to do this load testing of file reading.
index.js
// require express and create an instance of it
const express = require('express');
const rethinkdb = require("rethinkdb");
const fs = require("fs");
const convertHrtime = require('convert-hrtime');
const csv2jsonConverter = require("csvtojson").Converter;
const app = express();
const router = express.Router();
const db = require('./db');
const csvFilePath = __dirname + "/csv/50000-contacts.csv";
db.init();
app.use(db.createConnection);
app.get('/', function (req, res) {
console.log("hello world!");
});
// change the 404 message modifing the middleware
app.use(function (req, res, next) {
res.status(404).send("Sorry, that route doesn't exist. Have a nice day :)");
});
// start the server in the port 3000 !
app.listen(3000, function () {
console.log('Example app listening on port 3000.');
});
// close DB connection
app.use(db.closeConnection);
output
> performance@1.0.0 start /var/www/mystuff/performance
> node index.js
Example app listening on port 3000.
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
Hello world
db.js
"use strict";
var dbConst = {
"host": "localhost",
"port": 28015,
"db": "qtr"
};
var r = require('rethinkdb');
var rConnection = null;
module.exports = class DBConfig {
static init() {
if (true === !!rConnection) {
next();
} else {
r.connect(dbConst, function (err, conn) {
if (err) {
DBConfig.handleError(err.message);
process.exit(1);
}
rConnection = conn;
// next();
})
}
}
static createConnection(req, res, next) {
if (true === !!rConnection) {
req._rdbConn = rConnection;
next();
} else {
r.connect(dbConst).then(function (err, conn) {
if (err) {
DBConfig.handleError(err.message);
process.exit(1);
} else {
req._rdbConn = conn;
rConnection = conn;
}
}).error(DBConfig.handleError(res));
}
}
static closeConnection(req, res, next) {
req._rdbConn.close();
rConnection.close();
}
static handleError(res) {
return function (error) {
res.status(500).send(error.message);
};
}
static rConnection() {
return rConnection;
}
};
I would like to know programming code's performance testing with seige. I really apperciate about your openion or guidelines.
Aucun commentaire:
Enregistrer un commentaire