8000 [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations by tgalopin · Pull Request #18533 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

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

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 2 commits into from

Conversation

tgalopin
Copy link
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
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
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
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
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
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
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
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 2 times, most recently from d8de715 to 088afb1 Compare June 30, 2016 11:55
@tgalopin tgalopin force-pushed the annotations-opcache branch from 088afb1 to 9768dfe Compare July 28, 2016 12:48
@tgalopin tgalopin force-pushed the annotations-opcache branch 2 times, most recently from 4f2d5c2 to 91d992d Compare July 29, 2016 07:47
@tgalopin tgalopin force-pushed the annotations-opcache branch from 91d992d to 86a9938 Compare July 29, 2016 09:42
@tgalopin
Copy link
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
Member

Status: reviewed

@fabpot
Copy link
Member
fabpot commented Jul 30, 2016

Thank you @tgalopin.

@fabpot fabpot closed this in 35b0ab9 Jul 30, 2016
fabpot added a commit that referenced this pull request Jul 30, 2016
…tated classes to compile using patterns (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[HttpKernel] Allow bundles to declare classes and annotated classes to compile using patterns

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

This PR introduces a simple system of patterns based on wildcards for classes to cache in the HttpKernel dependency injections extensions. This system started to be implemented in #18533 but I split it up here to use it also in the classes to compile.

Commits
-------

1be7424 [HttpKernel] Allow usage of patterns in classes and annotations to cache
tgalopin pushed a commit to tgalopin/symfony that referenced this pull request Aug 1, 2016
…nd annotated classes to compile using patterns (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[HttpKernel] Allow bundles to declare classes and annotated classes to compile using patterns

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

This PR introduces a simple system of patterns based on wildcards for classes to cache in the HttpKernel dependency injections extensions. This system started to be implemented in symfony#18533 but I split it up here to use it also in the classes to compile.

Commits
-------

1be7424 [HttpKernel] Allow usage of patterns in classes and annotations to cache
tgalopin pushed a commit to tgalopin/symfony that referenced this pull request Aug 2, 2016
…nd annotated classes to compile using patterns (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[HttpKernel] Allow bundles to declare classes and annotated classes to compile using patterns

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

This PR introduces a simple system of patterns based on wildcards for classes to cache in the HttpKernel dependency injections extensions. This system started to be implemented in symfony#18533 but I split it up here to use it also in the classes to compile.

Commits
-------

1be7424 [HttpKernel] Allow usage of patterns in classes and annotations to cache
fabpot added a commit that referenced this pull request Sep 14, 2016
…zer based on PhpArrayAdapter (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter

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

Following the cache warmer for annotations (#18533) and for the validator (#19485), this PR introduces a cache warmer for the Serializer YAML and XML metadata configuration (mainly groups).

Based on the PhpArrayAdapter, it uses the naming conventions (Resources/config/serialization) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7.

The benefit of this PR are the same than the ones of the previous PR:

- serialization metadata cache can be warmed up offline
- on PHP 7, there is no need for user extension to get maximum performances (ie. if you use this PR and the other one, you probably won't need to enable APCu to have great performances)
- on PHP 7 again, we are not sensitive to APCu memory fragmentation
last but not least, global performance is slightly better (I get 30us per class gain in Blackfire)

As previous work on the Serializer cache system introduced issues (see 96e418a), it would be interesting to pay careful attention to the backward compatibility during the review (ping @Ener-Getick).

Commits
-------

810f469 [FrameworkBundle] Introduce a cache warmer for Serializer based on PhpArrayAdapter
fabpot added a commit that referenced this pull request Sep 14, 2016
…or based on PhpArrayAdapter (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter

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

Following the cache warmer for annotations PR (#18533), this PR introduces a cache warmer for YAML and XML Validator configuration.

Based on the PhpArrayAdapter, it uses the naming conventions (`Resources/config/validation`) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7.

The benefit of this PR are the same than the ones of the annotations PR:

- validation configuration can be warmed up offline
- on PHP 7, there is no need for user extension to get maximum performances (ie. if you use this PR and the other one, you probably won't need to enable APCu to have great performances)
- on PHP 7 again, we are not sensitive to APCu memory fragmentation
- last but not least, global performance is slightly better (I get 30us per class gain in Blackfire)

This PR also deprecates the framework.validator.cache key in favor of the cache pool introduced in #18544.

Commits
-------

6bdaf0b [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter
symfony-splitter pushed a commit to symfony/validator that referenced this pull request Sep 14, 2016
…or based on PhpArrayAdapter (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter

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

Following the cache warmer for annotations PR (symfony/symfony#18533), this PR introduces a cache warmer for YAML and XML Validator configuration.

Based on the PhpArrayAdapter, it uses the naming conventions (`Resources/config/validation`) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7.

The benefit of this PR are the same than the ones of the annotations PR:

- validation configuration can be warmed up offline
- on PHP 7, there is no need for user extension to get maximum performances (ie. if you use this PR and the other one, you probably won't need to enable APCu to have great performances)
- on PHP 7 again, we are not sensitive to APCu memory fragmentation
- last but not least, global performance is slightly better (I get 30us per class gain in Blackfire)

This PR also deprecates the framework.validator.cache key in favor of the cache pool introduced in symfony/symfony#18544.

Commits
-------

6bdaf0b [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Sep 14, 2016
…or based on PhpArrayAdapter (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter

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

Following the cache warmer for annotations PR (symfony/symfony#18533), this PR introduces a cache warmer for YAML and XML Validator configuration.

Based on the PhpArrayAdapter, it uses the naming conventions (`Resources/config/validation`) to find the files and compile them into a single PHP file stored in the cache directory. This file uses shared memory on PHP 7.

The benefit of this PR are the same than the ones of the annotations PR:

- validation configuration can be warmed up offline
- on PHP 7, there is no need for user extension to get maximum performances (ie. if you use this PR and the other one, you probably won't need to enable APCu to have great performances)
- on PHP 7 again, we are not sensitive to APCu memory fragmentation
- last but not least, global performance is slightly better (I get 30us per class gain in Blackfire)

This PR also deprecates the framework.validator.cache key in favor of the cache pool introduced in symfony/symfony#18544.

Commits
-------

6bdaf0b [FrameworkBundle] Introduce a cache warmer for Validator based on PhpArrayAdapter
@fabpot fabpot mentioned this pull request Oct 27, 2016
@tgalopin tgalopin deleted the annotations-opcache branch October 27, 2016 09:39
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.

0