-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
YAML routing loader should be cached in production. #7368
Comments
Normally the yaml route definitions should not be loaded every request because the generator and matcher are dumped. See PhpGeneratorDumper and PhpMatcherDumper. Did you change some configs or made customizations to the default setup? |
Or are you calling |
Thanks for quick reply @Tobion and @stof I don't think we've made any significant configuration changes. I did a grep over our code base and outside of Symfony core We did implement a custom router (for subdomains) but it does not alter the behavior of |
@stof what is the alternative to |
Try to use ConfigCache to cache what you built from the RouteCollection, if that is possible. So you don't need to fetch the collection once your cache is primed. |
@bendavies you should not access the RouteCollection at runtime. If you have some code doing it, you should refactor it as it would be a flawed implementation of your feature. |
@stof thanks, but say i wanted a list of all routes at runtime, how would i go about it? |
Grab it and use ConfigCache to Cache it. The list of Resources you need is available on the collection. |
@bendavies why do you want the list of all routes ? |
i don't. does it matter why? |
Ok. I'll close this now. I'll reopen if I find more proof of Symfony misbehaving. At this point it seems too probable it's an issue in our setup. |
I think indeed this is either a bug or a failure in the documentation. Without this bug I would not know that this is a "flawed" way of implementation. I think the behaviour should be clearly documented on the RouterInterface or the Router should use the configured caches in production. |
The current implementation uses the `Router::getRouteCollection` method, which loads all routes. If you use yaml to define your routes, it will parse all route files, which has a pretty big performance impact on a large application with many routes. This method is actually intended to be used to warm up the cache and nothing else (the result is cached in memory, but every request will read the configuration with no cache involved). See symfony/symfony#7368 (comment) for a discussion on this topic. We could implement a router that can do what we need efficiently, but given that we don't use the `method` attribute, let's just remove it completely. Note : Blackfire says that this change leads to a -200ms improvement in an app with 260 routes.
While we were recently creating a high-traffic website on Symfony 2.0.x we found out a quite severe performance problem in production. We use YAML config in all of our bundles and it seems that YAML routes are parsed on every request even when using APC cache in production. We did some performance analysis and this really is a major performance issue.
A code example below shows how we worked around the problem in our project but due to the fact that cache key is prefixed with a hard-coded value
routes_
we understand this example is not mergeable to Routing component as is. So that's why no PR.In my opinion YAML routes should be APC cached by default if ApcUniversalClassLoader is used as autoloader. Other option might be to somehow convert all YAML configs to PHP arrays and store them to
app/cache
during cache warmup for prod use.I'd really like to see something like this before 2.3 LTS because I really think these kind of performance issues really cripple any LTS even if the framework is otherwise very good.
ps. This issue is only about YAML routes but naturally all (YAML) configs should be somehow cached to gain maximum performance.
The text was updated successfully, but these errors were encountered: