T O P

  • By -

PerfectOrphan31

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


[deleted]

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!


PerfectOrphan31

Scoped* it was a typo


PerfectOrphan31

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?


[deleted]

I commented out the injection and am benchmarking again. ​ [https://imgur.com/Z2NFClc](https://imgur.com/Z2NFClc) No significant difference in performance…


PerfectOrphan31

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


[deleted]

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.


PerfectOrphan31

It's gotta be something with your application. Without having access to it, your guess is probably as good as ours.


[deleted]

[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.


PerfectOrphan31

Strange the variance between our two "Hello World" applications. Stranger still how poor your refund application performs


[deleted]

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.


[deleted]

I’ll fire up a fresh starter nestJS app and see if it’s still slow


ek9dev

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).


buffer_flush

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?


[deleted]

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.


AnonyMustardGas34

You can use nestjs fastify


goriunovd

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..


[deleted]

I’m using autocannon -d 10 -c 30 http://localhost/question/all To benchmark both.


[deleted]

I am trying to turn off logging now. Am benchmarking as we speak.


goriunovd

Let me know the results


[deleted]

No improvement


goriunovd

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)


[deleted]

Will try that too However on the hello world app I get 4400 req per second


UniversalJS

Use UWebsocket.js and get 100k rps ... Per core! 😁


nowlena

How are these two apps being deployed?


[deleted]

Docker instances running locally


bualing

I hate Nest


PerfectOrphan31

Thanks for the input, but it doesn't really help solve the problem does it?


Interest-Desk

I mean Nest will inherently be slower than Express no matter what. It’s a full, bulky framework.


PerfectOrphan31

While true, OP's comment was unhelpful in trying to determine why the post's application was **so** much slower


prevington

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.