I have made two projects, one using nestJS/mongoDB and the other Fastify/MongoDB in order to compare performance of both frameworks. I made a simple get resource API querying a mongo document having ~400Kb. Both projects route responds with the JSON document over 300ms. Can someone explain to me from where comes the extra 280ms as mongo responds no more than 20ms.
It's not a matter of the framework they both responds with the same time. Is it the compression done by the API, is it the time taken by node server
When I profile the code, mongo responds no more than 20ms, in both case, with the document that is immediately returned by the get handler. There is no boilerplate code or extra logging, just plain HttpServer.
in Fastify I'm doing this way
{
method: 'GET',
url: '/api/trees/:id',
handler: async (req, reply) => {
try {
const id = req.params.id
const tree = await TaxonomiesTrees.findById(id)
return tree.data
} catch (err) {
throw boom.boomify(err)
}
}
}
in NestJS like this
@Get(':id')
async getTree(@Param('id') code: string) {
const result = await this.treesCollection.findOne({id});
return result.data
}