-
Notifications
You must be signed in to change notification settings - Fork 5
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
Disable cache #32
Comments
can you please be more specific when saying "cache is not useful anymore" ?
I'm asking it because some of the cache logic in the kernel is to "warmup" (prepare) some files that the environment will be able to deal with later on. (as explained here). |
@nivpenso sure!
So, what if we want to preload everything before we start listening to HTTP socket? Like something loaded from our database, or a file content, or a configuration file to avoid file reading each time we handle a request... then we can rely on this new kernel event named You can see a bit more about this So yes. Cache is not useful, and only adds some troubles when working on development (if you don't remember to delete the cache after some configuration changes). The main goal of this PR is to find a way of, literally, do not generate this cache. |
Here is where I got so far in my investigation after digging into
It is a little bit tricky to remove the cache from the file system because it used by the kernel to load the compiled container (from the file system). I'm now investigating 2 approaches:
A different approach can be: just leave the cache directory as it is now, and make sure to delete it (if it exists) on kernel |
@nivpenso I like the container compilation into PHP streams. Basically because as soon as the kernel shuts down, this data is lost (expected behavior). About the second option, I don't understand this approach. Can you explain a bit more? Finally, take in account that this cache is not only used by the container, but as well by Twig, Doctrine... so the last option would solve them all. |
I agree with you that working with streams sounds like a good solution but unfortunately, the kernel code for building the container and especially writing it into the filesystem is scattered across 2-4 different places and requires many code changes. As of the 2nd approach, the compiled container is basically a group of PHP files that include things like configuration and other optimizations embedded within these files. So instead of dumping these files into the filesystem and load the files using As more I think about it the more I agree with you. The 3rd approach of removing the cache directory on the server's preload state is the easiest idea to implement and will require the least changes and code duplication. |
Just to update it seems that the |
Merged! Well done! |
Disabling the cache in general has a big impact on tests based on KernelTestCase. The kernel is rebooted for each individual test and the container is now rebuilt each time, which takes a long time in total. As we can see, the cache is not useless and should not be disabled, or disabling it should be optional. |
@raebbar you're. totally. right. My appologies for that. I was completely focused on production, but in testing, working with the kernel cache, is something very useful. We have 2 options here
WDYT? |
@nivpenso each test should be isolated, so working with different kernels would have sense. The same happens when you have functional tests with a running Drift server, Several isolated servers would work with the same kernel definition, and rebuilding the same kernel once and again would result a dramatic decrease of performance. |
@nivpenso Just as mmoreram has already described, tests should be isolated in order to have a clear state at the beginning and not influence each other. The question I am asking is whether we even need this logic for deleting the cache in the kernel. |
@raebbar yes, you're right. Cache is something that is useful. But is only useful when you need velocity in terms of building and shutting up kernel instances. And this only happens in tests. So, the question is. In Symfony is something that you cannot bypass, basically because ALL requests re-build the same Kernel, and need this cache to do it efficiently. But in Drift, the cache is never reused across requests. So. |
@mmoreram I understand your point ... ok let's make it convenient :-) "Disabling the cache only on prod (which makes sense)" - doesn't solve the problem completely because I don't want to have a cache when developing locally (for example) "Adding a --no-cache flag in the server" - With this option, I first have to look at the server package myself to decide whether it is the right way or not. You know that better. |
@raebbar what about working with cache ONLY in test environment? |
I think we can start with that. Another possibility would be an environment variable to keep it flexible for all cases. By default, we would deactivate the cache unless the DRIFT_CACHE_ENABLED variable is not empty. |
I like this idea as well. That makes it completely configurable, no matter the environment. |
Just wanted to go deeper into that isolation thing - I totally understand and agree that each test should not be affected by another. With that said, it doesn't mean that they can not share resources. An isolated environment for testing can also be done without restarting the server or rebooting the kernel each time. Before trying to provide an in-framework solution. I think we need to understand better the problem we are facing here. The It is still not very clear to me why it is so important to reboot the kernel and load it again from cache instead of just working with the existing one? can you give an example of two tests that use the same kernel which one affects the other? |
Functional tests check the integration of the different layers of an application (from the routing to the response). Most of the application's services are used as they are. Only a few special ones may be mocked. |
Just a thing here. Drift can ONLY work with stateless services. |
@mmoreram Just for clarification. I meant services in the sense of Symfony Container. And of course they can have a state. |
@raebbar nopes. In Drift (neither in any ReactPHP application) you can not use stateful services. Basically because you cannot guess the order of requests accesses. The only state that a service can have in an emulation of a stack, like a list of logs, a repository or something similar. |
You have just given simple examples yourself. Would you say the Redis server implementation in ReactPHP by clue (https://github.com/clue/php-redis-server) has a state? Write your Varnish clone in reactphp, imaginable - state. Configs that are loaded at startup and can be changed at runtime - state. Statistics, metrics - state. DNS-Resolver mit Cache - state. Connections to external resources - state. And so on ... I guess I know what your point was now, but saying "Drift can ONLY work with stateless services" is wrong in my opinion. But our discussion is now a bit offtopic for this issue :-) |
@raebbar whan I talk about services, I mean this, state per request. So yes, can have state, but this state change will be shared per all request at any order. Said that, I would go for an environment variable for this cache usage. |
Looks good. Thank you for the implementation. |
Cache is not useful anymore. In fact, it produces a lot of invalid and non expected behaviors (like having to work with dev or cleaning cache by hand each time we reload the server.
This task should be
var/
folder for log files.The text was updated successfully, but these errors were encountered: