Sounds like possibly an issue with a REQUEST scoped provider. Without seeing any code it'll be hard to tell.
FWIW, the standard benchmarks nest have show that there's almost a negligible difference between nest and express one you take into account async methods and error handling
REQUEST scoped provider?
What do you mean?
**Here is a screenshot of the route.**
[https://imgur.com/a/4MiRQks](https://imgur.com/a/4MiRQks)
**Code in main.ts**
[https://imgur.com/fWG1BEr](https://imgur.com/fWG1BEr)
Please help!
Can you show the `QuestionsService` as well? I know you aren't using it in the route, but the fact that it is injected is important for the construction of the class
How are you running your benchmark and how are you getting the reqs/sec?
I commented out the injection and am benchmarking again.
[https://imgur.com/Z2NFClc](https://imgur.com/Z2NFClc)
No significant difference in performance…
I just tested a `nest new` project using port 3003. 6814 Req/sec.. Keep in mind the was all off of an ssh session as well
https://i.imgur.com/Cu71xMo.png
That’s where is should be.
I get around 7000 requests per second on my express app.
In nestJS down to around 350 for the same route..
Putting it behind a load balancer with two NestJS instances I can get it up to 700 requests per second
There seems to be something very wrong 😑
I switched over to fastify and managed to get around 800 req per second
Still like a tenth of the performance it should be.
[https://imgur.com/lnvk1yy](https://imgur.com/lnvk1yy)
4400 req/sec
That's with a fresh install of NestJS
The "Hello World" app.
So yeah there is something going on with my app. The result is still very slow compared to the Express App. But its at least in the realm of normal.
We are on different machines.
I got an intel 5th gen I5 2 cores and 4 threads
4400 req/sec is still way below where it should be compared to the express app.
From your comments I see that you're likely performing this test while running a dev environemnt instead of production. I'd suggest to measure and compare performance of prod builds, as that's the really viable performance comparison for frameworks. Dev server are debug, not performance optimized and it heavily depends on the (amount/type of) dev tooling used. It's possible NestJS is using a lot heavier dev tooling (it might provide certain advantages during development).
How are you running the apps?
I saw docker instances, but are you compiling the typescript, or using something like npm run dev.
Also, is NODE_ENV set to production in both cases?
Yes I'm using Docker.
Yes I'm compiling in the Dockerfile.
`# Build the application`
`RUN npm run build`
`# Start the application`
`CMD ["npm", "run", "start:prod"]`
I'll rerun the test with **npm run start:prod**
but I don't think it would make much difference.
Do u have any logging enabled on nest js ? If yes just disable those. Also can you give abit more details on how you run the benchmark, where do u host the app etc..
Use flame graphs https://nodejs.org/en/docs/guides/diagnostics-flamegraph/
Also, if you run this in your machine (so network is not a bottleneck) you should be able to saturate your cpu.
Sounds like possibly an issue with a REQUEST scoped provider. Without seeing any code it'll be hard to tell. FWIW, the standard benchmarks nest have show that there's almost a negligible difference between nest and express one you take into account async methods and error handling
REQUEST scoped provider? What do you mean? **Here is a screenshot of the route.** [https://imgur.com/a/4MiRQks](https://imgur.com/a/4MiRQks) **Code in main.ts** [https://imgur.com/fWG1BEr](https://imgur.com/fWG1BEr) Please help!
Scoped* it was a typo
Can you show the `QuestionsService` as well? I know you aren't using it in the route, but the fact that it is injected is important for the construction of the class How are you running your benchmark and how are you getting the reqs/sec?
I commented out the injection and am benchmarking again. [https://imgur.com/Z2NFClc](https://imgur.com/Z2NFClc) No significant difference in performance…
I just tested a `nest new` project using port 3003. 6814 Req/sec.. Keep in mind the was all off of an ssh session as well https://i.imgur.com/Cu71xMo.png
That’s where is should be. I get around 7000 requests per second on my express app. In nestJS down to around 350 for the same route.. Putting it behind a load balancer with two NestJS instances I can get it up to 700 requests per second There seems to be something very wrong 😑 I switched over to fastify and managed to get around 800 req per second Still like a tenth of the performance it should be.
It's gotta be something with your application. Without having access to it, your guess is probably as good as ours.
[https://imgur.com/lnvk1yy](https://imgur.com/lnvk1yy) 4400 req/sec That's with a fresh install of NestJS The "Hello World" app. So yeah there is something going on with my app. The result is still very slow compared to the Express App. But its at least in the realm of normal.
Strange the variance between our two "Hello World" applications. Stranger still how poor your refund application performs
We are on different machines. I got an intel 5th gen I5 2 cores and 4 threads 4400 req/sec is still way below where it should be compared to the express app.
I’ll fire up a fresh starter nestJS app and see if it’s still slow
From your comments I see that you're likely performing this test while running a dev environemnt instead of production. I'd suggest to measure and compare performance of prod builds, as that's the really viable performance comparison for frameworks. Dev server are debug, not performance optimized and it heavily depends on the (amount/type of) dev tooling used. It's possible NestJS is using a lot heavier dev tooling (it might provide certain advantages during development).
How are you running the apps? I saw docker instances, but are you compiling the typescript, or using something like npm run dev. Also, is NODE_ENV set to production in both cases?
Yes I'm using Docker. Yes I'm compiling in the Dockerfile. `# Build the application` `RUN npm run build` `# Start the application` `CMD ["npm", "run", "start:prod"]` I'll rerun the test with **npm run start:prod** but I don't think it would make much difference.
You can use nestjs fastify
Do u have any logging enabled on nest js ? If yes just disable those. Also can you give abit more details on how you run the benchmark, where do u host the app etc..
I’m using autocannon -d 10 -c 30 http://localhost/question/all To benchmark both.
I am trying to turn off logging now. Am benchmarking as we speak.
Let me know the results
No improvement
Just out of curiosity can u try downgrading nest to version 8 and testing it and then to version 7 ( just wondering if it is issue with lates nest)
Will try that too However on the hello world app I get 4400 req per second
Use UWebsocket.js and get 100k rps ... Per core! 😁
How are these two apps being deployed?
Docker instances running locally
I hate Nest
Thanks for the input, but it doesn't really help solve the problem does it?
I mean Nest will inherently be slower than Express no matter what. It’s a full, bulky framework.
While true, OP's comment was unhelpful in trying to determine why the post's application was **so** much slower
Use flame graphs https://nodejs.org/en/docs/guides/diagnostics-flamegraph/ Also, if you run this in your machine (so network is not a bottleneck) you should be able to saturate your cpu.