Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations#18533

Closed
tgalopin wants to merge 2 commits into
symfony:masterfrom
tgalopin:annotations-opcache
Closed

[FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations#18533
tgalopin wants to merge 2 commits into
symfony:masterfrom
tgalopin:annotations-opcache

Conversation

@tgalopin
Copy link
Copy Markdown
Contributor

@tgalopin tgalopin commented Apr 13, 2016

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? WIP
Fixed tickets -
License MIT
Doc PR -

Depends on #18825 and #18823

This PR implements the usage of the new OpCacheAdapter in the annotations caching system. The idea to use this adapter as much as possible in Symfony (validator, serializer, ...). These other implementations will be the object of different PRs.

*/
protected function doFetch(array $ids)
{
$this->loadFile();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Given calling a method is an heavy process, you can save CPU by calling loadFile only when needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@nicolas-grekas just told me that :)

// Validates that the dumped code is valid (ie. no __set_state())
$this->values = eval($dump);

$dump = "<?php\n\n" . $dump;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

missing \n at the end

@stof
Copy link
Copy Markdown
Member

stof commented Apr 13, 2016

Deprecate configuration keys for annotations caching in all concerned services (validator, serializer, Doctrine ORM)

As your adapter is read-only, this cannot work unless you rewrite most logic. There is nothing ensuring that all the cache is of these services is warmed up by the cache warmer, and services using them are not writing all their cache in a single batch (the ORM does not for instance)

@stof
Copy link
Copy Markdown
Member

stof commented Apr 13, 2016

Introduce a unified configuration key to enable/disable annotations cache everywhere

We already have a single annotation cache.

I'm quite sure you are confusing the annotation cache and the cache for metadata of each of these services (which must be separate as they store unrelated data, and which can be built from other sources that annotations)

@mkdir($directory, 0777, true);
}

if (!file_exists($directory)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should move this condition block after the mkdir

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's a good point, I'll do that tomorrow

@tgalopin tgalopin force-pushed the annotations-opcache branch from fe237f0 to b732ff6 Compare May 19, 2016 08:55
@nicolas-grekas
Copy link
Copy Markdown
Member

Given than keys validation is slow (from my benchmarks), I suggest we remove all keys validation from OpCache and Null adapters (and skip any related failing tests):

  • for OpCacheAdapter, either the key exists or the validation is done by the fallback adapter in a good enough way,
  • for NullAdapter, let's make it really fast instead of perfectly correct.

@tgalopin
Copy link
Copy Markdown
Contributor Author

I did the changes

<argument /> <!-- default lifetime -->
</service>

<service id="cache.adapter.redis" class="Symfony\Component\Cache\Adapter\RedisAdapter" abstract="true">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Lazy should be removed

@nicolas-grekas
Copy link
Copy Markdown
Member

👍 Hurray

@tgalopin
Copy link
Copy Markdown
Contributor Author

I splited this PR in three different one for better review. To review with ease, start by #18825, then #18823 and finally this PR.

@tgalopin
Copy link
Copy Markdown
Contributor Author

I updated this PR following the changes in #18825 and #18823

->addDefaultsIfNotSet()
->children()
->scalarNode('cache')->defaultValue('file')->end()
->scalarNode('cache')->defaultValue('opcache')->end()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

How should we name this? opcache is misleading IMO as we won't use the OpCacheAdapter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

php_array

@fabpot
Copy link
Copy Markdown
Member

fabpot commented Jun 15, 2016

Any performance profiles?

<service id="annotations.cache" class="Symfony\Component\Cache\DoctrineProvider" public="false">
<argument type="service">
<service class="Symfony\Component\Cache\Adapter\PhpArrayAdapter">
<factory class="Symfony\Component\Cache\Adapter\PhpArrayAdapter" method="createOnPhp7" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

createOnPHP7 should be create

@tgalopin
Copy link
Copy Markdown
Contributor Author

With Blackfire it's really hard to highlight the performance gain because it's small. With ab -n 1000 -c 100 against a php -S on the standard edition, I get a median of 280ms per request with the patch and 285ms with Doctrine APCu.

To sum up, the benefit provided by this PR are:

  • annotations can be warmed up offline
  • on PHP 7, there is no need for user extension to get maximum performances
  • on PHP 7 again, we are not sensitive to APCu memory fragmentation
  • last but not least, global performance is the same if not slightly better

@nicolas-grekas
Copy link
Copy Markdown
Member

Status: reviewed

@fabpot
Copy link
Copy Markdown
Member

fabpot commented Jul 30, 2016

Thank you @tgalopin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.