-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enable serialization output / input stream customization #168
Comments
May I ask you why a custom implementation of |
With a custom |
I see. Anyway, perhaps there could be other good use cases for a custom TransientInjectableObjectOutputStream. |
Yes, I think referencing transient fields from lambdas is also recommended in the Vaadin documentation. If the custom serialization approach doesn't work, we'll try that instead. Additionally, a custom stream factory can be useful for passing another output stream to the ObjectOutputStream, such as a zstd compression stream. I believe Redis lacks built-in compression, and Hazelcast also does not support compression unless Hazelcast handles the serialization itself. |
The compression part could be interesting for us, as some of our pages add up to 4MB of data being serialized to the session. Is the compression overhead measurable or something not to worry about at all ? |
I believe that the additional time spent compressing sessions with zstd is well spent. In our project, session sizes range from 1 to 2 MB, and serialization itself takes about 50 to 100 ms on my system. I tested two approaches:
|
With the PR merged, the following would suffice to add session compression to your project: @Component
class CustomStreamFactory : SerializationStreamFactory {
override fun createOutputStream(
baseOutputStream: OutputStream,
transientHandler: TransientHandler,
injectableFilter: Predicate<Class<*>>
): SerializationOutputStream {
val zstdOutputStream = ZstdOutputStream(baseOutputStream)
return TransientInjectableObjectOutputStream.newInstance(zstdOutputStream, transientHandler, injectableFilter)
}
override fun createInputStream(`in`: InputStream, transientHandler: TransientHandler): SerializationInputStream {
val zstdInputStream = ZstdInputStream(`in`)
return TransientInjectableObjectInputStream(zstdInputStream, transientHandler)
}
} |
Another use-case for us is to add a |
We have recently considered using Kubernetes Kit for session replication in our project. To minimize changes to our Kotlin Spring Boot codebase, we would like to customize the
TransientInjectableObjectOutputStream
to exclude all referenced Spring beans from serialization without needing to annotate them with@Transient
.Currently, Kubernetes Kit does not support this because the
SessionSerializer
directly instantiates the output stream responsible for inspecting transient fields within a private method, preventing us from injecting a custom implementation.We propose introducing a
SerializationStreamFactory
bean to obtain output and input stream instances, allowing us to inject our custom implementation. This custom implementation will replace all Spring beans inreplaceObject
. In our prototype using a forked version of Kubernetes Kit, this approach works well.If you are open to this change, I will open a PR with the proposed modifications:
feature/serialization-stream-factory
The text was updated successfully, but these errors were encountered: