Vaadin Flow session memory keeps a low-traffic app on an oversized instance — is passivation viable?
0 reputation · 23 May 2020, 15:09 UTC
0 reputation · 23 May 2020, 15:09 UTC
A low-traffic Vaadin Flow application (assume Vaadin 24 on Spring Boot) costs more to host than its page-view count suggests. Because Flow holds each user's UI component tree in server memory tied to the HTTP session, instance sizing is driven by concurrent sessions and session timeout, not request volume. The goal is to move this workload to a smaller instance without breaking active user sessions.
The documented lever is session serialization/passivation: if the UI state is serializable, a servlet container or Spring Session (e.g., Redis or JDBC backend) can persist idle sessions externally, so memory only needs to cover genuinely active sessions. The uncertainty is that Vaadin views must not hold non-serializable fields (injected services, streams, lambdas capturing non-serializable state), and this application's views have not been audited. Silent failures here would force sessions to stay in memory anyway.
Secondary options under consideration: shortening the session timeout (at the risk of logging users out mid-task) and confirming that server push is not keeping idle WebSocket connections alive unnecessarily.
31775 reputation · 24 May 2020, 01:42 UTC
Yes, session passivation is a viable strategy to reduce the memory footprint of a low-traffic Vaadin Flow application. By moving idle session state to an external store (like Redis or JDBC via Spring Session), you can size your instance based on active concurrent users rather than the total number of sessions awaiting timeout.
Because Vaadin Flow stores the entire UI component tree in the session, any non-serializable field in a View—such as an injected Spring service, an open InputStream, or a lambda capturing non-serializable state—will cause passivation to fail. To verify this without relying on runtime NotSerializableException errors, use these methods:
ObjectOutputStream and ObjectInputStream. This forces the JVM to traverse the object graph and throw an exception immediately if a field is not serializable.com.vaadin.flow.component.Component (or your base View class) implement java.io.Serializable and that their fields are either serializable or marked transient.To size a smaller instance, you must determine the average memory cost of a single user session. Since Vaadin's memory usage scales with the complexity of the UI tree, follow this approach:
jmap or VisualVM with zero users.@RepeatedTest to create a fixed number of sessions (e.g., 50 or 100) that navigate through the most complex views in your app.Spring Session passivation does not override Vaadin's internal session management, but they must be aligned to avoid unexpected behavior:
Diagnostic Requirement: To refine this recommendation, please provide the average number of components per view. If views are exceptionally large (thousands of components), the CPU overhead of frequent serialization/deserialization may outweigh the memory savings of a smaller instance.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.