Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var mysql = require('mysql2');
- 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>';
- res.write(table);
- for (var i = 0; i < rows.length; i++) {
- res.write('<tr><td>' + rows[i].id + '</td><td>' + rows[i].username + '</td><td>' + rows[i].password + '</td><td>' + rows[i].banking_account + '</td><td>' + rows[i].phone + '</td></tr>');
- }
- res.write('</table><div style="color:red">Hello from cluster worker: ' + cluster.worker.id + '</div>');
- res.end();
- });
- }).listen(9615);
- console.log("Server running at http://localhost:9615 on cluster worker number " + cluster.worker.id);
- }
- 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: 10939 bytes
- Concurrency Level: 200
- Time taken for tests: 34.954 seconds
- Complete requests: 100000
- Failed requests: 0
- Total transferred: 1103900000 bytes
- HTML transferred: 1093900000 bytes
- Requests per second: 2860.90 [#/sec] (mean)
- Time per request: 69.908 [ms] (mean)
- Time per request: 0.350 [ms] (mean, across all concurrent requests)
- Transfer rate: 30841.23 [Kbytes/sec] received
- Connection Times (ms)
- min mean[+/-sd] median max
- Connect: 0 0 0.1 0 6
- Processing: 1 70 46.1 60 621
- Waiting: 0 69 45.7 59 611
- Total: 1 70 46.1 60 621
- Percentage of the requests served within a certain time (ms)
- 50% 60
- 66% 70
- 75% 79
- 80% 86
- 90% 108
- 95% 135
- 98% 219
- 99% 273
- 100% 621 (longest request)
Add Comment
Please, Sign In to add comment