在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cevio/koa-rapid-router开源软件地址:https://github.com/cevio/koa-rapid-router开源编程语言:JavaScript 100.0%开源软件介绍:koa-rapid-routerIt is a routing architecture suitable for any service, and we usually use it on KOA, this is currently the fastest routing architecture. Installnpm i koa-rapid-router DocumentUsage in koaconst Koa = require('koa');
const Router = require('koa-rapid-router');
const app = new Koa();
const route = new Router();
const router = route.create('/interface/api');
router.get('/uuid/{uid:number}', async (ctx) => {
ctx.body = ctx.params.uid;
});
app.use(route.Koa()).listen(3000, err => {
if (err) throw err;
console.log('app run at 3000');
}); Add your own typesroute.expression('xyz', '[x-z]+');
// then you can use it like this
router.get('/uuid/{uid:xyz}', async (ctx) => {
ctx.body = ctx.params.uid;
}); PerformanceIts performance is 100 times faster then koa-router, but it's similar to fastify (if you don't use the KOA infrastructure, use http). Test sample: 10,000 static routes are injected into different architectures. The test commands are the same: Using static Routerfor (let i = 0; i < 10000; i++) {
router.get('/uuid/' + (i + 1), async (ctx) => ctx.body = 'ok');
vrouter.get('/uuid/' + (i + 1), (res) => res.end('ok'));
route_2.get('/interface/api/uuid/' + (i + 1), async (ctx) => ctx.body = 'ok');
fastify.get('/interface/api/uuid/' + (i + 1), (request, reply) => reply.send('ok'));
} Preview: Results
Using Dynamic Routerrouter.get('/zzz/{a:number}', async (ctx) => ctx.body = 'ok');
vrouter.get('/zzz/{a:number}', (res) => res.end('ok'));
route_2.get('/interface/api/zzz/:a(\\d+)', async (ctx) => ctx.body = 'ok');
fastify.get('/interface/api/zzz/:a', (request, reply) => reply.send('ok')); Preview: Results
ResultIt is clear from the data that the performance advantages of the service can be established through Data tells us that KOA architecture performance is very poor, we are fully possible to achieve near native HTTP performance routing, as long as we continue to explore the factors affecting performance, we will be able to close to native performance. It's the same as the principle of approaching the speed of light. It's impossible to be equal, but it's approachable. How to test?First open a new command line: npm run dev Then, open a new command line npm run test You can see a very shocking result. LicenseCopyright (c) 2018-present, yunjie (Evio) shen |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论