我为什么要使用 Restify?

我需要在 node.js 中构建一个 REST API,并且正在寻找一个比 Express.js 更轻量级的框架,这个框架可能会避免不需要的特性,并且会像一个定制构建的框架一样构建 REST API。对于同一情况,建议从其介绍中重新定义。

阅读 为什么使用静止而不是表达?似乎是一个不错的选择。

但是惊喜来了,当我尝试了两个负载。

我在 Restify 上制作了一个示例 REST API,每秒发出1000个请求。让我惊讶的是,路线在一段时间后开始没有反应。构建在 Express.js 上的同一个应用程序处理了所有。

我目前正在通过

var FnPush = setInterval(function() {
for(i=0;i<1000;i++)
SendMsg(makeMsg(i));
}, 1000);


function SendMsg(msg) {
var post_data = querystring.stringify(msg);
var post_options = {
host: target.host,
port: target.port,
path: target.path,
agent: false,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length,
"connection": "close"
}
};


var post_req = http.request(post_options, function(res) {});
post_req.write(post_data);
post_req.on('error', function(e) {
});
post_req.end();
}

我得到的结果看起来合理吗?如果是这样,那么在这种情况下,表达比重新定义更有效吗?或者我测试的方法有什么错误?

根据评论更新

安定的行为

  1. 当加载超过1000个请求时,它会在1秒内停止处理,直到接收到1015个请求,然后什么也不做。也就是说。用于计算传入请求的计数器在1015之后停止递增。

  2. 当喂食时,即使负荷100个要求。直到10点15分才有反应,之后就没反应了。

89550 次浏览

I ran into a similar problem benchmarking multiple frameworks on OS X via ab. Some of the stacks died, consistently, after around the 1000th request.

I bumped the limit significantly, and the problem disappeared.

You can you check your maxfiles is at with ulimit, (or launchctl limit < OS X only) and see what the maximum is.

Hope that helps.

According to the Node Knockout description:

restify is a node.js module purpose built to create REST web services in Node. restify makes lots of the hard problems of building such a service, like versioning, error handling and content-negotiation easier. It also provides built in DTrace probes that you get for free to quickly find out where your application’s performance problems lie. Lastly, it provides a robust client API that handles retry/backoff for you on failed connections, along with some other niceties.

Performance issues and bugs can probably be fixed. Maybe that description will be adequate motivation.

i was confused with express or restify or perfectAPI. even tried developing a module in all of them. the main requirement was to make a RESTapi. but finally ended up with express, tested my self with the request per second made on all the framework, the express gave better result than others. Though in some cases restify outshines express but express seams to win the race. I thumbs up for express. And yes i also came across locomotive js, some MVC framework build on top of express. If anyone looking for complete MVC app using express and jade, go for locomotive.

Corrigendum: this information is now wrong, keep scrolling!

there was an issue with the script causing the Restify test to be conducted on an unintended route. This caused the connection to be kept alive causing improved performance due to reduced overhead.


This is 2015 and I think the situation has changed a lot since. Raygun.io has posted a recent benchmark comparing hapi, express and restify.

It says:

We also identified that Restify keeps connections alive which removes the overhead of creating a connection each time when getting called from the same client. To be fair, we have also tested Restify with the configuration flag of closing the connection. You’ll see a substantial decrease in throughput in that scenario for obvious reasons.

Benchmark image from Raygun.io

Looks like Restify is a winner here for easier service deployments. Especially if you’re building a service that receives lots of requests from the same clients and want to move quickly. You of course get a lot more bang for buck than naked Node since you have features like DTrace support baked in.

This is 2017 and the latest performance test by Raygun.io comparing hapi, express, restify and Koa.

It shows that Koa is faster than other frameworks, but as this question is about express and restify, Express is faster than restify.

And it is written in the post

This shows that indeed Restify is slower than reported in my initial test.

enter image description here

In 2021, benchmarking done by Fastify (https://www.fastify.io/benchmarks/) indicates that Restify is now slightly faster than Express.

The code used to run the benchmark can be found here https://github.com/fastify/benchmarks/.

a brief summary on how fastify overhead performed against the some other well known Node.js web frameworks