【问题标题】:why is node https request faster than http request为什么节点https请求比http请求快
【发布时间】:2015-11-24 17:41:15
【问题描述】:

我有以下代码,我使用 http 和 https url 对帖子进行了性能测试。结果着实让我吃惊。 https 请求表现更好。

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    

任何人都可以在这里发光吗?

【问题讨论】:

    标签: node.js performance-testing


    【解决方案1】:

    当同一个客户端一次又一次地重新连接时,SSL 握手会缩短(请参阅 Here ),因此要提供准确的图像,您需要在各种客户端进程和机器上进行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      相关资源
      最近更新 更多