Skip to content

Improve handling of VaadinSession to minimize memory usage #24172

@AB-xdev

Description

@AB-xdev

Describe your motivation

We are currently running a application that is mostly used by mobile devices. The app has a rather large session lifetime (a bit more than 1h) due to authentication and caching purposes.

During peak load we noticed that the app requires a ton of memory - caused by contents inside the VaadinSession that might not actually needed anymore:

  1. Vaadin UIs (inside the session) are only closed when requests happen. The problem with e.g. mobile devices is that they might stop sending request after some time - due to lost network connectivity or because the task manager suspended the browser to preserve battery. MDN has another good example. This causes inactive UIs to never be closed after the heartbeatTimeout (hearbeatInterval[default=5min] * 3.1) is reached and basically "hang" forever inside the session - with the entire UI state.
  2. UIInternals#lastRequestResponse contains the last response for a request during the entire lifetime of the session. During heapdump analysis I found sessions that consumed 2x the memory because of this:
    Image

Describe the solution you'd like

Regarding the problems:

  1. Keep checking the sessions in the background and cleanup any inactive UIs
    • It would be nice if heartbeatTimeout could be configured by the user like is the case for hearbeatInterval
  2. UIInternals#lastRequestResponse: Delete this after a certain time without any real requests.

Describe alternatives you've considered

For now we worked around the problems by running a scheduled background thread that cleans up the sessions.
The corresponding code was ported to/is available at our SSE framework.

Here is the memory usage without the cleaner:

Image

and here when it's enabled:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions