机器信息:4C32G
测试工具:wrk
Node: v14.17.0
express.js
'use strict'const express = require('express')const app = express()app.get('/', function (req, res) {res.json({ hello: 'world' })})app.listen(3000)
fastify.js
'use strict'const fastify = require('fastify')()fastify.get('/', function (req, reply) {reply.send({ hello: 'world' })})fastify.listen(3000)~
测试结果
# express.jsRunning 10s test @ http://127.0.0.1:300012 threads and 400 connectionsThread Stats Avg Stdev Max +/- StdevLatency 55.36ms 11.53ms 173.22ms 93.16%Req/Sec 602.58 113.03 830.00 84.97%72034 requests in 10.10s, 17.31MB readRequests/sec: 7134.75Transfer/sec: 1.71MB# fastify.jsRunning 10s test @ http://127.0.0.1:300012 threads and 400 connectionsThread Stats Avg Stdev Max +/- StdevLatency 16.26ms 5.73ms 105.76ms 96.26%Req/Sec 2.08k 490.82 14.63k 94.92%249114 requests in 10.09s, 44.43MB readRequests/sec: 24688.94Transfer/sec: 4.40MB
fastify是express的3.4倍, 所以对性能有所追求的话,最好用fastify。
