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

Skip to content

[Cache] Use igbinary when available #19895

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
nicolas-grekas opened this issue Sep 9, 2016 · 13 comments
Closed

[Cache] Use igbinary when available #19895

nicolas-grekas opened this issue Sep 9, 2016 · 13 comments

Comments

@nicolas-grekas
Copy link
Member

So that cached items take less space on the storage backend.

See igbinary/igbinary#76 also.

@fabpot
Copy link
Member

fabpot commented Sep 9, 2016

We need to be careful here the ability to read an existing cache will depend on the igbinary availability (think cache warming on a different machine than the one where it is installed).

@javiereguiluz
Copy link
Member

I agree with Fabien. Using "igbinary" automatically when it's available on the server feels too magic for Symfony. It'd be better to add a config option to enable this feature explicitly.

@salvocanna
Copy link

@javiereguiluz @fabpot 👍
Just giving my 2 cents here
Moving to php7 has been painful for me as this assumes that, if you have igbinary installed, means you wanna use it (it came together with the php redis extension, not really a choice)
Unfortunately it wasn't available in PHP7 back then - or just wasn't stable, so this caused massive headaches.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jul 21, 2017

I think it's possible to have autoadaptative behavior.
Yet, igbinary is one desirable enhancement, but compressing could also be another one (a native feat of the memcached extension btw.)
This means to me we'd ideally need a way to define a pluggable "serializer", that would have consistent behavior, and be able to handle the format (ie native or igbinary) + compression + whatever.
But this is a significant thing to achieve, and yet nobody complained - so the priority is not very high to me.
Therefore, I'm closing this issue. If anyone wants to take over, with the approach I described or any other one, please do :)

@palex-fpt
Copy link

I have pool of large generated object trees (over 1k trees). Each request uses only one tree from the pool, so using opcache is memory inefficient and using memcache/redis would increase network load. I using file-based cache with igbinary serialization. In attempt to migrate to Symfony's Cache component I finds it hard to extend Symfony's implementations to replace serialization parts.
Are any plans to add serialization extension points to cache implementations?

@nicolas-grekas
Copy link
Member Author

There are no plans, but there could be PRs :)

@palex-fpt
Copy link

I'm going to add MarshallerInterface.
Proof of concept: https://github.com/palex-fpt/symfony/commits/cache-marshaller

@nicolas-grekas nicolas-grekas reopened this Jun 1, 2018
@nicolas-grekas
Copy link
Member Author

I'd call it SerializeInterface I think, it would have the least surprise effect IMHO. But looks good already :)

@palex-fpt
Copy link

I renamed it to SerializerInterface and added some tests. Also I did heavy refactoring on opcache related caches.
I think opcache serializer should store data in serialized strings as few as possible to reduce deserialization performance hits on cache reads.
There is some friction between opcache caches (PhpArrayAdapter, PhpArrayCache) and SerializationInterface contract. Caches does not call SerializationInterface::unserialize on cache hits due to fact that deserialization is part of include file directive. And it is performed in cache classes.

@nicolas-grekas
Copy link
Member Author

If that could make your work easier, not all adapters should have a configurable serializer IMHO. The opcache ones don't need to especially.

@palex-fpt
Copy link

I'm done with refactoring. Should I submit it with new feature PR?

@nicolas-grekas
Copy link
Member Author

Yes please

@palex-fpt
Copy link

#27484

@fabpot fabpot closed this as completed Jul 9, 2018
fabpot added a commit that referenced this issue Jul 9, 2018
…he serializer, providing a default one that automatically uses igbinary when available (nicolas-grekas)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Cache] Add `MarshallerInterface` allowing to change the serializer, providing a default one that automatically uses igbinary when available

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

With this PR, when igbinary is available, it is automatically used to serialize values.
This provides faster and smaller cache payloads.
The unserializing logic is autoadaptative:
- when an igbinary-serialized value is unserialized but the extension is missing, a cache miss is triggered
- when a natively-serialized value is unserialized and the extension is available, the native `unserialize()` is used

Ping @palex-fpt since you provided very useful comments on the topic and might be interested in reviewing here also.

Commits
-------

9c328c4 [Cache] Add `MarshallerInterface` allowing to change the serializer, providing a default one that automatically uses igbinary when available
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants