Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues with lb4 services #10616

Open
u3ih opened this issue Jul 24, 2024 · 3 comments
Open

Performance issues with lb4 services #10616

u3ih opened this issue Jul 24, 2024 · 3 comments
Labels

Comments

@u3ih
Copy link

u3ih commented Jul 24, 2024

Describe the bug

Using @service or @Inject to inject services can lead to performance issues when calling api (although not using them).

i used autocannon for benchmarking
Full command: autocannon -t12 -c1000 -d30 http://localhost:3000/ping

I tried to inject services into the controller (ping.controller). The more services I import and the larger the project, the more req in seconds decreases

Logs

No response

Additional information

I ran the project on 8 CPUs and tried it multiple times. These are the average results I got.

- Without Injection

I ran the autocannon test and got around 680k requests in 30 seconds. image

- With `@service` (around 37 `@service` with the same service file)

I got around 420k requests in 30 seconds. image

- With `@inject` (around 37 `@inject` with the same service file)

I got around 600k requests in 30 seconds. image

Reproduction

https://github.com/u3ih/loopback-benchmarking

@u3ih u3ih added the bug label Jul 24, 2024
@mathieuBP
Copy link

mathieuBP commented Aug 2, 2024

For me, this is to be expected.... Using DI indeed runs more code than not using it. So it is normal that it can slow down a bit. What I find very interesting tough is the fact that @Inject seems way faster than @service which is simply a sugar coated inject...

@u3ih
Copy link
Author

u3ih commented Aug 19, 2024

I dont think its just 'a bit' with this example its around 30%. And with a big project, it slows down even more 😢

@gopiuma
Copy link

gopiuma commented Nov 26, 2024

Pre initializing services during application startup and apply correct scope to services could reduce the api response delays as each api request will try to initialize all services that are injected which is not of global scope

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants