Skip to content

Add a api_platform.metadata_cache parameter #1725

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

Merged

Conversation

dunglas
Copy link
Member

@dunglas dunglas commented Feb 22, 2018

Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets n/a
License MIT
Doc PR todo

TLDR:

Add the following in config/packages/test/framework.yaml to dramatically improve the speed of Behat tests:

parameters:
   api_platform.metadata_cache: true

Follows #1724 (comment)

TODO: fix tests

It's significant on my computer:

Before

Behat: 2m18.08s (2.16Gb)
PHPUnit: Time: 21.17 seconds, Memory: 104.25MB

After

Behat: 0m42.23s (498.70Mb)
Time: 25.72 seconds, Memory: 102.25MB

Can you try with your code base @jdeniau?


services:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you remove this line :P

@@ -457,7 +457,11 @@ private function registerBundlesConfiguration(array $bundles, array $config, Xml
private function registerCacheConfiguration(ContainerBuilder $container)
{
// Don't use system cache pool in dev
if (!$container->getParameter('kernel.debug')) {
if ($container->hasParameter('api_platform.metadata_cache')) {
if (!$container->getParameter('api_platform.metadata_cache')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we merge these?

@dunglas dunglas force-pushed the add-api_platform.metadata_cache branch from 16cfb89 to 8d3c291 Compare February 22, 2018 21:07
@jdeniau
Copy link
Contributor

jdeniau commented Feb 22, 2018

@dunglas I'm running test at this very moment, but I think it will do the trick for us as that was the return; in registerCacheConfiguration that was very long.

There are two things that I see that is a little "blocking":

👍 for api-platform DX, 👎 for the others (ok "=" for the others, but there are no emoji for that 😃)

The fact that the user need to set the api_platform.metadata_cache parameter to true.
Of course, it's set for api-platorm, so 👍 for it, but even if documented, there may be a lot of user not setting it.
I'm wondering why not auto-activate it if kernel env is "test" ? wich does lead to the second code snippet in #1724 (comment) and to the following point

cache invalidation

If I remember correctly, the second code snippet in FeatureContext is done because Symfony's cache is written only when the cache is cleared, not between two different behat runs
I think that my issue was because I deactivated kernel.debug, but with the metadata_cache parameter, it seems to work file ! 🥇

After reading your code and making some test, I'm now wondering why you register all the caches as ArrayAdapter in debug mode instead of letting the cache.pool do it's job ? (I do not know this part of Symfony very well though)

@jdeniau
Copy link
Contributor

jdeniau commented Feb 22, 2018

The tests finished to run on our server and I'm a little disappointed by the results
For the record I ran the tests on our CI server, which is very busy at night with database replication and stuff like that. I will re-run the test, tomorrow or monday to give you "real day-to-day" data

(I obfuscated the tests name for confidentiality reason)

Without optimization:

- 69 shuffled test classes into the queue.
- Will be consumed by 8 parallel Processes.
1	1/69	✔	1 s 250 ms	features/v.feature
7	2/69	✔	4 s 288 ms	features/w.feature
1	3/69	✔	2 min 27 s 196 ms	features/c.feature
7	4/69	✔	3 min 37 s 344 ms	features/o.feature
8	5/69	✔	4 min 18 s 4 ms	features/t.feature
6	6/69	✔	8 min 23 s 357 ms	features/p.feature

And then jenkins crashed 😉

With the metadata_cache set to true

(I ran only the 6 tests)

- 6 shuffled test classes into the queue.
- Will be consumed by 8 parallel Processes.
3	1/6	✔	1 s 232 ms	features/v.feature
2	2/6	✔	2 s 920 ms	features/w.feature
1	3/6	✔	1 min 9 s 706 ms	features/c.feature
5	4/6	✔	1 min 46 s 215 ms	features/o.feature
4	5/6	✔	2 min 2 s 674 ms	features/t.feature
6	6/6	✔	3 min 34 s 540 ms	features/p.feature

The win is about 50%, which is not bad

With kernel.debug set to false

- 6 shuffled test classes into the queue.
- Will be consumed by 8 parallel Processes.
6	1/6	✔	1 s 66 ms	features/v.feature
3	2/6	✔	2 s 783 ms	features/w.feature
1	3/6	✔	1 min 14 s 787 ms	features/c.feature
5	4/6	✔	1 min 52 s 721 ms	features/o.feature
4	5/6	✔	2 min 10 s 269 ms	features/t.feature
2	6/6	✔	3 min 47 s 400 ms	features/p.feature

Nearly the same time that with metadata_cache set to true

For the record, the "p.feature" file usually take 40 seconds to run, that's why I was disappointed ;)

I ran the o.feature test only on ouy development server and it took ~ 15 sec / 500 Mb with kernel.debug false or metadata_cache true and ~ 85 sec / 1.5 Gb without optimizations so big 👍 no matter what on the config point

if (!$container->getParameter('kernel.debug')) {
return;
if ($container->hasParameter('api_platform.metadata_cache') ? $container->getParameter('api_platform.metadata_cache') : !$container->getParameter('kernel.debug')) {
return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent fail on the return?

@dunglas dunglas force-pushed the add-api_platform.metadata_cache branch from 7b2585f to 54ef999 Compare February 23, 2018 11:06
@dunglas dunglas force-pushed the add-api_platform.metadata_cache branch from 54ef999 to b4c4023 Compare March 5, 2018 08:57
@@ -44,6 +44,7 @@
use Prophecy\Argument;
use Prophecy\Exception\Doubler\MethodNotFoundException;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless.

@dunglas dunglas force-pushed the add-api_platform.metadata_cache branch from b4c4023 to 52a3a32 Compare March 15, 2018 12:58
@dunglas dunglas merged commit 97616e2 into api-platform:master Mar 15, 2018
@dunglas dunglas deleted the add-api_platform.metadata_cache branch March 15, 2018 13:43
@teohhanhui
Copy link
Contributor

Not sure this is the right way to do it, or that the naming is obvious enough...

@bendavies
Copy link
Contributor

just a hint that this extremely useful parameter does not seem to be documented, and this comes up on slack at least a few times a week.

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.

6 participants