Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var mysql = require('mysql2');
- var async = require('async');
- var connection = mysql.createConnection({ user: 'benchmark', database: 'benchmark', password: 'benchpass'});
- var cluster = require('cluster');
- var numCPUs = require('os').cpus().length;
- if (cluster.isMaster) {
- // Fork workers.
- for (var i = 0; i < numCPUs; i++) {
- cluster.fork();
- }
- cluster.on('exit', function (worker, code, signal) {
- console.log('worker ' + worker.process.pid + ' died');
- });
- } else {
- http.createServer(function (req, res) {
- res.writeHead(200, {'Content-Type': 'text/html'});
- connection.query('SELECT * FROM users LIMIT 100;', function (err, rows) {
- if (err) {
- throw new Error('Connection failed');
- }
- var table = '<table><tr><th>id</th><th>username</th><th>password</th><th>banking account</th><th>phone number</th></tr>';
- async.forEach(rows, function (row, callback) {
- table += '<tr><td>' + row.id + '</td><td>' + row.username + '</td><td>' + row.password + '</td><td>' + row.banking_account + '</td><td>' + row.phone_number + '</td></tr>';
- callback();
- }, function (err) {
- if (err) {
- throw new Error('Async failed!');
- }
- table += '</table>';
- table += '<div style="color:red">Hello from cluster worker: ' + cluster.worker.id + '</div>';
- res.end(table);
- });
- });
- }).listen(9615);
- console.log("Server running at http://localhost:9615 on cluster worker number " + cluster.worker.id);
- }
- Benchmark results:
- ab -n 100000 -c 200 http://127.0.0.1:9615/
- This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
- Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
- Licensed to The Apache Software Foundation, http://www.apache.org/
- Benchmarking 127.0.0.1 (be patient)
- Completed 10000 requests
- Completed 20000 requests
- Completed 30000 requests
- Completed 40000 requests
- Completed 50000 requests
- Completed 60000 requests
- Completed 70000 requests
- Completed 80000 requests
- Completed 90000 requests
- Completed 100000 requests
- Finished 100000 requests
- Server Software:
- Server Hostname: 127.0.0.1
- Server Port: 9615
- Document Path: /
- Document Length: 11001 bytes
- Concurrency Level: 200
- Time taken for tests: 11.692 seconds
- Complete requests: 100000
- Failed requests: 0
- Total transferred: 1110100000 bytes
- HTML transferred: 1100100000 bytes
- Requests per second: 8553.03 [#/sec] (mean)
- Time per request: 23.384 [ms] (mean)
- Time per request: 0.117 [ms] (mean, across all concurrent requests)
- Transfer rate: 92721.84 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.1 0 3
- Processing: 0 23 16.8 20 113
- Waiting: 0 23 16.8 20 113
- Total: 0 23 16.8 20 113
- Percentage of the requests served within a certain time (ms)
- 50% 20
- 66% 28
- 75% 34
- 80% 37
- 90% 45
- 95% 52
- 98% 63
- 99% 80
- 100% 113 (longest request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement