Skip to content

Preload services #24

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

Closed
wants to merge 1 commit into from
Closed

Conversation

gnugat
Copy link

@gnugat gnugat commented Mar 18, 2016

Instantiate all services in the Dependency Injection Container.

Stateless (shared) services in the Dependency Injection Container will be instantiated once by the first Request that require them, and then their instance will be reused in all other Requests.

This also allows to "warm up" part of autoloading.

@gnugat gnugat force-pushed the preloaded-services branch from e6f17c6 to 8e22844 Compare March 18, 2016 09:30
@marcj
Copy link
Member

marcj commented Mar 18, 2016

To be honest, I'm not a friend of instantiating all services. Some heavy instances I need only in few requests or even in commands only and shouldn't be instantiated on every request. If this brings a heavy perf boost in first connections we should think about an option to triggers this. What gain did you get with this?

@gnugat
Copy link
Author

gnugat commented Mar 18, 2016

I get your point: without this "preloading", most services will be eventually "loaded" anyway (apart from command specific services), so it might not seem like a big improvement.

I'll come up with some PHP-PM benchmarks soon, but for PHPFastCGI I got the following results (around 6% faster):

  • Requests per second: from 1115.87#/sec to 1185.59#/sec
  • Time per request: from 8.962ms to 8.435ms ()
  • Time per request (across all concurrent requests): from 0.896ms to 0.843ms

@marcj
Copy link
Member

marcj commented Mar 18, 2016

Alright, then let us wait for benchmarks in php-pm and if it's worth we should enable it with an option to disable it (for example if you have an application with heavy services and too many)

Instantiate all services in the Dependency Injection Container.

Stateless (shared) services in the Dependency Injection Container will be
instantiated once by the first Request that require them, and then their
instance will be reused in all other Requests.

This also allows to "warm up" part of autoloading.
@gnugat gnugat force-pushed the preloaded-services branch from 8e22844 to 968c96e Compare March 20, 2016 14:58
@gnugat
Copy link
Author

gnugat commented Apr 2, 2016

Hey, I've done some benchmarking and there a no noticeable differences. That's probably because PHP PM runs a preliminary request when starting the kernel so autoloading and services for the homepage are already loaded.

After some though, I agree with you: autoloading and services would be loaded eventually and kept alive so it wouldn't impact much performances of a live application. Regarding benchmarks, where the first request might be slower and impact the average result, since we run a preliminary request we get rid of this risk.

I'll close this PR. It's been interesting to investigate, at least now we have an answer for future similar questions.

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

Successfully merging this pull request may close these issues.

2 participants