Closed micalevisk closed 1 year ago
(I don't know why, but for some reason, GitHub didn't notify me about this issue. That's why I'm only responding to it now.)
A controller whose instance is not created for each request makes very little sense at all. Currently, it is not possible to compare Ditsmod vs NestJS + Fastify without @Controller({ scope: Scope.REQUEST })
, because in Ditsmod, the controller instance is created for each request.
@micalevisk, for what cases, in your opinion, are controllers that are instantiated only once necessary? In my opinion, such a feature is only necessary for static routes. Sometimes it is indeed necessary, but in very rare cases, and this task is better performed, for example, by Nginx.
I'm thinking more on memory consumption and garbage collector work. We can take the singleton pattern as a general rule to avoid increasing them
I have just checked my hypothesis, which I described in the previous comment. It turns out that NestJS passes the request object to controller methods, even if the controller is created without the @Controller({ scope: Scope.REQUEST })
option. Therefore, I was wrong to assume that this option is suitable only for static routes and rarely used otherwise.
Hi, @micalevisk. Ditsmod v2.50.0 finally has the ability to create singleton controllers. And you know what? With this feature, in some modes, Ditsmod overtakes even Fastify!
If you now run this command:
wrk -t1 -c10 -d5 -H 'Connection: close' http://localhost:3006/hello
You will see better results with Ditsmod than with Fastify (on 3003 port).
what do you think on adding another version of nestjs+fastify that doesn't uses the request scope since we know that this minor change will impact the performance?
https://github.com/ditsmod/vs-webframework/blob/f6a39cf0c37a40016ed7e2d2ba89e5617ace0b5c/nestjs/app.module.ts#L4
Since we couldn't have a new Ditsmod version that doesn't uses the
Res
, I'm unsure if this comparison will be fair tho.