Skip to content

[Cache] add TagAwareMarshaller to optimize data storage when using AbstractTagAwareAdapter #33939

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
Oct 11, 2019

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 4.4
Bug fix? no
New feature? no
Deprecations? no
Tickets #33924
License MIT
Doc PR -

This is the final touch in my series of PR that fixes the linked issue.

Remarkably, the solutions I implemented for this issue are completely different than the one I described there. Fortunately, the issues themselves were correctly identified.

Plannification of implementation is gambling :)

/cc @andrerom

@andrerom
Copy link
Contributor

andrerom commented Oct 10, 2019

What does this actually do (is there now double serialization of value for instance?), and why does it do it?

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 10, 2019

  • right now, the data is stored as: serialize([$value, $tags])
  • this PR stores it as serialize([serialize($value), serialize($tags))

This allows unserializing only the tags when only them are needed, in doDelete especially. The value is still downloaded but not unserialized anymore in this method.

@andrerom
Copy link
Contributor

this PR stores it as serialize([serialize($value), serialize($tags))

ok, that's what I thought. Anyway we can avoid the double serialization?
As in, could be two chunks of serialized blobs with a predictable separator between them for instance.

@nicolas-grekas
Copy link
Member Author

As in, could be two chunks of serialized blobs with a predictable separator between them for instance.

I suppose yes, I'll have a look.

@nicolas-grekas
Copy link
Member Author

@andrerom updated, please have a look at TagAwareMarshaller.

@nicolas-grekas nicolas-grekas force-pushed the cache-late-unser branch 2 times, most recently from a60d466 to b2269ca Compare October 10, 2019 10:27
Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

Looks to add quite a bit of complexity. Sure you don't want to solve this by just storing tags separately in adapters where that makes sense and for now treat indeed serialization on delete as know issue for file system? (until we have a reliable way to do parallel and/or async file reading)

Anyway, added several review comments here, some might be missing the point though.

@nicolas-grekas
Copy link
Member Author

@andrerom comments addressed hopefully.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 10, 2019 via email

@andrerom
Copy link
Contributor

andrerom commented Oct 10, 2019

E.g. we'd want values and tags to be stored on the same Redis node

That would be the simple part I guess using key like {cache-key}-tags or similar.

first needed step that fixes the unserialization issue in a generic way.

ok 👍 If we find time afterwards we can see if we can approach this using non blocking streams for Filesystem or something to contemplate splitting tags in separate files.

@nicolas-grekas
Copy link
Member Author

Actually for filesystem another approach would work better: we read the first bytes of the file and stop before reading the value. The data format provided by this PR allows that.

@nicolas-grekas nicolas-grekas force-pushed the cache-late-unser branch 3 times, most recently from 005b90b to 74296cd Compare October 11, 2019 07:57
Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

+1 besides nitpick

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 11, 2019

Good news: I managed to remove over fetching for both Redis and Filesystem adapters! Once again, the solution is completely different than we originally anticipated :)

@nicolas-grekas nicolas-grekas force-pushed the cache-late-unser branch 3 times, most recently from b666d2e to b029f52 Compare October 11, 2019 09:57
Copy link
Contributor

@andrerom andrerom left a comment

Choose a reason for hiding this comment

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

Even better :)

@nicolas-grekas nicolas-grekas changed the title [Cache] serialize tags separately from values in AbstractTagAwareAdapter [Cache] add TagAwareMarshaller to optimize data storage when using AbstractTagAwareAdapter Oct 11, 2019
nicolas-grekas added a commit that referenced this pull request Oct 11, 2019
…e when using AbstractTagAwareAdapter (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] add TagAwareMarshaller to optimize data storage when using AbstractTagAwareAdapter

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #33924
| License       | MIT
| Doc PR        | -

This is the final touch in my series of PR that fixes the linked issue.

Remarkably, the solutions I implemented for this issue are completely different than the one I described there. Fortunately, the issues themselves were correctly identified.

Plannification of implementation is gambling :)

/cc @andrerom

Commits
-------

5a4a30c [Cache] add TagAwareMarshaller to optimize data storage when using AbstractTagAwareAdapter
@nicolas-grekas nicolas-grekas merged commit 5a4a30c into symfony:4.4 Oct 11, 2019
@nicolas-grekas nicolas-grekas deleted the cache-late-unser branch October 14, 2019 20:54
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
nicolas-grekas added a commit that referenced this pull request Oct 30, 2019
…ssion (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] add DeflateMarshaller - remove phpredis compression

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | yes
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

phpredis compression doesn't play well with lua scripting as used in #33939
Let's remove it and provide a `DeflateMarshaller` instead.

Ppl can use it via decoration:
```yaml
services:
    Symfony\Component\Cache\Marshaller\DeflateMarshaller:
        decorates: cache.default_marshaller
        arguments: ['@symfony\Component\Cache\Marshaller\DeflateMarshaller.inner']
```

It's not enabled by default because that might break pools that are shared between different apps.

/cc @andrerom FYI

Commits
-------

452c863 [Cache] add DeflateMarshaller - remove phpredis compression
This was referenced Nov 12, 2019
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.

4 participants