服务器端路由上的流星铁路由器 - 为什么这么慢?

时间:2015-01-15 20:10:35

标签: node.js meteor iron-router

原始节点11,222个请求/秒......

var http = require('http');
http.createServer(function(req, res) {
    res.end('done');
}).listen(1337, '127.0.0.1');

=

  

gobench -c 100 -t 5 -u http://localhost:1337

Requests:                            56112 hits
Successful requests:                 56112 hits
Network failed:                          0 hits
Bad requests failed (!2xx):              0 hits
Successfull requests rate:           11222 hits/sec
Read throughput:                   1369156 bytes/sec
Write throughput:                  1349088 bytes/sec
Test time:                               5 sec

但是Meteor中的Iron-Router服务器端路由返回相同的东西......

Router.route('/test', function() {
    this.response.end('done');
}, {
    where: 'server'
});

=

  

gobench -c 100 -t 5 -u http://localhost:3000/test

Requests:                             6544 hits
Successful requests:                  6544 hits
Network failed:                          0 hits
Bad requests failed (!2xx):              0 hits
Successfull requests rate:            1308 hits/sec
Read throughput:                    189776 bytes/sec
Write throughput:                   164771 bytes/sec
Test time:                               5 sec

瓶颈是Meteor还是Iron-Router?

1 个答案:

答案 0 :(得分:1)

瓶颈是一些事情的组合。

当您使用vanilla http服务器时,您错过了Meteor和Iron Router使用的中间件(bodysarser&路由匹配)&路线匹配套件(流星侧)。另请注意,Iron Router使用regexp来匹配路由。

另一件事是meteor run模式(不是来自meteor build的捆绑应用)在应用程序本身的顶部有一个额外的代理服务器。

还有一些其他的middlware来检查文件的路由,(即它是否是静态资产)(包括哪种架构(cordova或客户端)。

此外,必须在Meteor中为每个运行时生成index.html文件。

Meteor使用的中间件的提示来自webapp包:https://github.com/meteor/meteor/blob/devel/packages/webapp/webapp_server.js