anyone benchmark this?
i5ting opened this issue · comments
so slow....
express-static qps = 6199.4
express qps = 7566
koa2-router-static qps = 2800.6
koa2-router qps = 7073.2
koa2-static qps = 2600.6
koa2 qps = 9603.6
const Koa = require('koa')
const serve = require('koa-static')
const app = new Koa()
// $ GET /package.json
app.use(serve('.'))
// response
app.use(ctx => {
ctx.body = 'Hello Koa'
})
// app.listen(3000)
module.exports = app.callback()
const Koa = require('koa')
const router = require('koa-router')()
const serve = require('koa-static')
const app = new Koa()
// $ GET /package.json
app.use(serve('.'))
router.get('/', function (ctx, next) {
ctx.body = 'Hello Koa'
})
app
.use(router.routes())
.use(router.allowedMethods())
// app.listen(3000)
module.exports = app.callback()
const Koa = require('koa');
const app = new Koa();
// response
app.use(ctx => {
ctx.body = 'Hello Koa';
});
// app.listen(3000);
module.exports = app.callback()
Slow? So your service does over 224,640,000 requests per day on a single node? With no CDN? :p
@tj i mean koa is so fast, but when i mount static middleware, it's really slow 4x: 9600/2600
. maybe we can optimization performance with koa-send & koa-static
2600 rps isn't slow though, that's the 224M requests / day. Just my .02 but I think anyone with that kind of traffic would have a CDN going, or at least two nodes for redundancy, which would then support half a billion per day.
Also try the defer: true
option so it does not sit in front of every request, that should reduce the latency there.
app.use(serve('.'))
IMO, this is a bad practice, as every request will hit koa-static and will be checked does request.url exists (a file or a directory).
var stats = yield fs.stat(path);
The better way used is combine with a router, eg:
router.get('/public/*', async function(ctx, next) {
ctx.url = path.basename(ctx.url)
await next()
}, staticServer(resolve('./public'), {gzip: true}))
yes, filtering your routes and using defer: true
will help increase performance