1
我有下面的代碼,並且使用http和https url對郵件進行了性能測試。結果讓我驚訝。 https請求表現更好。爲什麼節點https請求比http請求更快
var express = require('express');
var fs =require('fs');
var https = require('https');
var http = require('http');
var authTransaction = require('./routes/trans');
var app = express();
app.configure(function(){
app.use(express.logger('dev'));
app.use(express.bodyParser());
});
var privateKey = fs.readFileSync(mykey.pem', 'utf8');
var certificate = fs.readFileSync('mycert.pem', 'utf8');
var passphrase ="blahblah";
var credentials = {key: privateKey, cert: certificate,passphrase:passphrase};
var httpsServer = https.createServer(credentials, app).listen(9090);
var httpServer = http.createServer(app).listen(5000);
app.get('/',function(req,res){
res.send("hello ");
})
app.post('/trans', function(req,res){
var purchase= new Purchase(req.body);
purchase.save(function(err){
if(err) {
res.send({'error': 'An error occured'});
}else{
res.json({
"status": {
"message": [
"Success"
]
}
});
}
});
});
我跑了10個線程1小時,低於
結果結果:
的NodeJS - HTTPS
Test Min Max Avg Last Count Throughput Bytes BPS
Trans 5 3017 12.69 7 47010 13.05 13961970 3878
的NodeJS - HTTP
Test Min Max Avg Last Count Throughput Bytes BPS
Trans 17 3031 40.26 29 45326 12.59 13461822 3739
任何人都可以扔一些光在這裏?