Skip to content
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

Add option to use compression #1084

Closed
candrews opened this issue May 30, 2018 · 10 comments
Closed

Add option to use compression #1084

candrews opened this issue May 30, 2018 · 10 comments
Assignees
Labels
status: declined A suggestion or change that we don't feel we should currently apply

Comments

@candrews
Copy link
Contributor

Spring Session uses Java serialization to convert objects to bytes which are then persisted. Java's serialization format is quite verbose and it compresses very well - it would be nice to offer optional compression for the serialized byte data. Doing so would use less persistent storage and transfer less data over the network, and in at least some situations result in an overall performance improvement.

Using Java's GZIPInputStream/GZIPOutputStream seems like a great option, as it would introduce no new dependencies and work everywhere.

@candrews
Copy link
Contributor Author

@vpavic if you think this would be acceptable, I can prepare a PR.

@vpavic
Copy link
Contributor

vpavic commented May 31, 2018

Thanks @candrews. From the description, it's not clear whether you are suggesting this for a specific SessionRepository implementation or in general. However having in mind you previous reports/PRs, I suspect this is about JdbcOperationsSessionRepository?

Flexibility in choice of serialization mechanism should be provided, since the serialization itself can have a significant impact on performance. Rather than changing our defaults, I think we should look into providing configuration facilities for customizing serialization mechanism in JdbcOperationsSessionRepository and HazelcastSessionRepository. PRs are definitely welcome! 🙂

@candrews
Copy link
Contributor Author

There are ways to do this today, but they're far from intuitive/simple and they're different for each repository implementation.

JdbcOperationsSessionRepository (see the serialize and deserialize methods) uses a ConversionService to convert Objects to byte[] (which can be set to a custom implementation using the setConversionService method). The ConversionService can therefore do the compression.

RedisOperationsSessionRepository doesn't use a ConversionService. Instead, it uses RedisSerializer<Object> to serialize/deserialize, and this can be set using setDefaultSerializer. Providing a custom implementation of RedisSerializer<Object>.

So those two are completely different.

Which way should we go? Options include:

  • Change all repositories to do Object<->byte[] conversion using ConversionService and all use the same springSessionConversionService bean by default (like JdbcOperationsSessionRepository and it's configuration in JdbcHttpSessionConfiguration), then provide a configuration option that, when enabled, wraps that ConversionService with compression when doing Object<->byte[] conversion
  • Introduce a new interface specifically for compression, SpringSessionCompressionService with two methods: byte[] compress(@Nullable byte[] data) and byte[] decompress(@Nullable byte[] data) (Instead of byte[], InputStream and OutputStream may be better?). Repository implementations gain a setter so they can get access to this service, and they use it whenever reading/writing to their backing stores. Include a NoOpSpringSessionCompressionService (which does nothing) implementation which is used by default, and also a GZIPSpringSessionCompressionService implementation (which uses GZIPInputStream/GZIPOutputStream).
  • Combination of these two. Make the changes from the first option, and use SpringSessionCompressionService to perform the compression in the ConversionService.

Thoughts? I'd like some feedback before I go spending a bunch of time going down this particular rabbit hole. :) Thanks!

@candrews
Copy link
Contributor Author

@vpavic thoughts?

@candrews
Copy link
Contributor Author

@vpavic @rwinch bump

@rwinch
Copy link
Member

rwinch commented Aug 23, 2018

I think the first step would be to ensure custom serialization mechanisms are in place for each repository type. Then providing a serialization mechanism that performs the compression.

@candrews
Copy link
Contributor Author

I think the first step would be to ensure custom serialization mechanisms are in place for each repository type.

👍

Then providing a serialization mechanism that performs the compression.

👎 I think serialization and compression as related, but not one in the same (they shouldn't be linked). My choice of compression shouldn't be dependent on my choice of serialization. I should be able to use Java serialization with bzip, for example, without having to write my own JavaSerializationWithBzipCompression class.

@vpavic
Copy link
Contributor

vpavic commented Aug 24, 2018

Regarding the support for custom serialization in JdbcOperationsSessionRepository, you can track #1166.

I think serialization and compression as related, but not one in the same (they shouldn't be linked). My choice of compression shouldn't be dependent on my choice of serialization.

This is one of those things that adds complexity for a very specific use case - to my knowledge you're the only one who requested compression. Let's start with #1166 as that will provide you a way to meet your requirement.

@vpavic
Copy link
Contributor

vpavic commented Sep 3, 2018

Note that I've just closed #1166 as we already support custom serialization via JdbcHttpSessionConfiguration#setConversionService. Having this in mind @candrews, you should already be able to meet your requirement with a custom ConversionService.

@vpavic vpavic self-assigned this Nov 27, 2018
@vpavic
Copy link
Contributor

vpavic commented Nov 27, 2018

Closing as we're not keen to add this ATM, and JdbcHttpSessionConfiguration already offers a way to customize serialization.

@vpavic vpavic closed this as completed Nov 27, 2018
@vpavic vpavic added the status: declined A suggestion or change that we don't feel we should currently apply label Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply
Projects
None yet
Development

No branches or pull requests

3 participants