Skip to content

[Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0 #18823

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
merged 1 commit into from
Jun 28, 2016

Conversation

tgalopin
Copy link
Contributor

@tgalopin tgalopin commented May 20, 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

This PR aims to implement a Symfony Cache adapter able to build files optimized for OPCache memory storage. Any kind of static data that can be warmed up is a candidate for OPcache storage.

This PR is limited to the implementation of the Adapter. It's usage in the annotations caching system is implemented in the PR #18533. The aim is also to use this adapter in other contexts (validator, serializer, ...).


if ('N;' === $value) {
$value = null;
} elseif (isset($value[2]) && is_string($value) && ':' === $value[1]) {
Copy link
Member

Choose a reason for hiding this comment

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

is_string should come before isset($value[2]) IMO

}
}

$dump = <<<EOF
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be enclosed with nowdoc instead of heredoc.

*/
class NullAdapter implements AdapterInterface
{
private $createCacheItem;
Copy link
Contributor

Choose a reason for hiding this comment

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

phpdoc missing

@tgalopin tgalopin force-pushed the opcache-adapter branch 2 times, most recently from 928dc61 to c6e08fc Compare May 25, 2016 11:43
@tgalopin
Copy link
Contributor Author

I did the changes

EOF;

foreach ($values as $key => $value) {
CacheItem::validateKey($key);
Copy link
Member

Choose a reason for hiding this comment

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

because PHP casts numeric string keys to ints, we should cast ints to string here:
`is_int($key) ? (string) $key : $key);

$fallbackKeys = array();

foreach ($keys as $key) {
if (!is_string($key)) {
Copy link
Member

Choose a reason for hiding this comment

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

this check should be done before calling generateItems

Copy link
Member

Choose a reason for hiding this comment

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

indeed. Doing it in the generator will throw the exception too late (the iterator will throw it during iteration, while it must be throw by getItems)

@nicolas-grekas
Copy link
Member

I suggest renaming this adapter to Php7Adapter (ans use the OpcacheAdapter name in #18894)

@tgalopin tgalopin changed the title [Cache] Add OpCacheAdapter to use shared memory on PHP 7.0+ [Cache] Add Php7Adapter to use shared memory on PHP 7.0+ May 26, 2016
@tgalopin
Copy link
Contributor Author

I did some benchmarks to check the PHP 5.6 support in this PR.

I used three Docker containers with only PHP/HHVM installed, on the same host. I used Apache Benchmark with 1000 requests at a concurrency of 100 (ab -n 1000 -c 100).

The results are the following:

Engine Context Time per request
PHP 5.6 Empty array 0.953 ms/req
PHP 5.6 Array with 15 000 keys 4.671 ms/req
PHP 7.0 Empty array 0.688 ms/req
PHP 7.0 Array with 15 000 keys 0.709 ms/req
HHVM 3.12 Empty array 0.869 ms/req
HHVM 3.12 Array with 15 000 keys 0.875 ms/req

This seems to indicate that having an array filled with data in PHP 5.6 is significantly slower than having an empty array. Therefore, I removed the PHP 5.6 support for this PhpArrayAdapter in the create factory method (and I added the HHVM support).

@nicolas-grekas
Copy link
Member

👍

@tgalopin tgalopin force-pushed the opcache-adapter branch 6 times, most recently from bb8e068 to c507cc0 Compare June 27, 2016 13:05
@dunglas
Copy link
Member

dunglas commented Jun 27, 2016

👍

try {
$value = serialize($value);
} catch (\Exception $e) {
throw new InvalidArgumentException(sprintf('Cache key "%s has non-serializable %s value', $key, get_class($value)), 0, $e);
Copy link
Member

Choose a reason for hiding this comment

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

Missing closing double quote.

Copy link
Member

Choose a reason for hiding this comment

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

Also missing a dot at the end.

@tgalopin
Copy link
Contributor Author

I did the changes.

private $fallbackPool;

/**
* @param string $file The PHP file were values are cached.
Copy link
Member

Choose a reason for hiding this comment

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

dots at the end of @param (@return, @throws, ... as well) should be removed

@tgalopin
Copy link
Contributor Author

I did the change

@fabpot
Copy link
Member

fabpot commented Jun 28, 2016

Thank you @tgalopin.

@fabpot fabpot merged commit 28a40d2 into symfony:master Jun 28, 2016
fabpot added a commit that referenced this pull request Jun 28, 2016
…P 7.0 (tgalopin)

This PR was merged into the 3.2-dev branch.

Discussion
----------

[Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0

| 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

This PR aims to implement a Symfony Cache adapter able to build files optimized for OPCache memory storage. Any kind of static data that can be warmed up is a candidate for OPcache storage.

This PR is limited to the implementation of the Adapter. It's usage in the annotations caching system is implemented in the PR #18533. The aim is also to use this adapter in other contexts (validator, serializer, ...).

Commits
-------

28a40d2 [Cache] Add PhpArrayAdapter to use shared memory on PHP 7.0+
@tgalopin tgalopin deleted the opcache-adapter branch June 28, 2016 10:06
fabpot added a commit that referenced this pull request Jul 30, 2016
…e warmer for annotations (tgalopin)

This PR was squashed before being merged into the 3.2-dev branch (closes #18533).

Discussion
----------

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

| 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.

Commits
-------

f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
symfony-splitter pushed a commit to symfony/cache that referenced this pull request Jul 30, 2016
…e warmer for annotations (tgalopin)

This PR was squashed before being merged into the 3.2-dev branch (closes #18533).

Discussion
----------

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

| 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 symfony/symfony#18825 and symfony/symfony#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.

Commits
-------

f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
symfony-splitter pushed a commit to symfony/http-kernel that referenced this pull request Jul 30, 2016
…e warmer for annotations (tgalopin)

This PR was squashed before being merged into the 3.2-dev branch (closes #18533).

Discussion
----------

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

| 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 symfony/symfony#18825 and symfony/symfony#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.

Commits
-------

f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
symfony-splitter pushed a commit to symfony/framework-bundle that referenced this pull request Jul 30, 2016
…e warmer for annotations (tgalopin)

This PR was squashed before being merged into the 3.2-dev branch (closes #18533).

Discussion
----------

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

| 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 symfony/symfony#18825 and symfony/symfony#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.

Commits
-------

f950a2b [FrameworkBundle] Wire PhpArrayAdapter with a new cache warmer for annotations
@fabpot fabpot mentioned this pull request Oct 27, 2016
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Jan 28, 2017
…weaverryan)

This PR was merged into the 3.2 branch.

Discussion
----------

Covering two missing Cache adapters introduced in 3.2

Hi guys!

These are 2 missing adapters that were introduced in 3.2! symfony/symfony#18894 and symfony/symfony#18823

Cheers!

Commits
-------

a3e69e2 Tweaks based on feedback!
1b6cb69 Covering two missing adapters introduced in 3.2
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.

10 participants