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

Memory Leak in hypersistence-optimizer itself? #143

Closed
MichaelZett opened this issue Jul 8, 2021 · 12 comments
Closed

Memory Leak in hypersistence-optimizer itself? #143

MichaelZett opened this issue Jul 8, 2021 · 12 comments
Labels
question Further information is requested

Comments

@MichaelZett
Copy link

Hi Vlad,

we're using the optimizer for a few weeks now and encountered a memory leak in our load-test-area.
Bildschirmfoto 2021-07-08 um 13 20 10
Before 09:30 we run with optimizer enabled, after 09:30 without.
optimizer-version: 2.3.1
Our Bean:
@Bean public HypersistenceOptimizer hypersistenceOptimizer(EntityManagerFactory entityManagerFactory, Set<Class<? extends Event>> knownAcceptedEvents, Set<AcceptedEvent> acceptedEvents) { return new HypersistenceOptimizer( new JpaConfig(entityManagerFactory) .setEventFilter(event -> applyFilters(event, knownAcceptedEvents, acceptedEvents)) ); }

The optimizer seems to collect a lot of events but does not drop them - is there a config that we missed for that?

@vladmihalcea
Copy link
Owner

The Optimizer collects all events and never clears them as it doesn't know if the client application consumed them.

However, you can call clear on the events after you consumed them and exported somewhere else:

hypersistenceOptimizer.getEvents().clear(); 

@vladmihalcea vladmihalcea added the question Further information is requested label Jul 8, 2021
@MichaelZett
Copy link
Author

Ok, thanks, we will try something with that clear-method.

@vladmihalcea
Copy link
Owner

That's a good idea, and the List is also thread-safe, so you can clear it from a worker Thread:

private List<Event> events = new CopyOnWriteArrayList<Event>();

By the way, are those runtime events that capture long-running queries and Sessions?

@MichaelZett
Copy link
Author

Nice, thanks.
We do not have long-running queries but long-running sessions. Have to look into it soon.

@vladmihalcea
Copy link
Owner

If you can provide me with more info, I'd gladly look into it. Normally, it shouldn't be any leak as other than the Event objects all temporary objects are bound to the Session and get cleaned up when the Session is closed.

@MichaelZett
Copy link
Author

We'll look into it and put some data together for you. Perhaps tomorrow. Than you for your quick response.

@vladmihalcea
Copy link
Owner

Looking forward to it.

@MichaelZett
Copy link
Author

Hi Vlad,

the mass of events seems to consist of these:
{ "connectionUsageTimeNanos": 163244, "transactionStatus": "COMMITTED", "connectionUsageTimeMillis": 0, "description": "The JDBC Connection was borrowed for [163] μs for management purposes while the transaction status was [COMMITTED].", "priority": "MAJOR", "infoUrl": "https://vladmihalcea.com/hypersistence-optimizer/docs/user-guide/#TransactionReconnectionEvent" },
.
Perhaps it would be better to sum up the count and overall borrow time instead of adding each single event?

Is there a way to see the context of this event? We are using spring-boot (2.5.2), spring-data, hibernate, hikari and postgresql. We use your suggestions for hikari.auto-commit: false and provider_disables_autocommit: true.

@vladmihalcea
Copy link
Owner

You can filter the TransactionReconnectionEvent out using an EventFilter if your setup cannot be changed to avoid acquiring the DB connection multiple times per transaction.

@MichaelZett
Copy link
Author

Hi,
yes we will do that for this event and SessionFlushTimeoutEvent and FlushModeAutoEvent. Perhaps you could think about adding a feature for such events, so that they are counted and not re-added every time that happens.
Another feature request would be for these events and SessionTimeoutEvent as well to get more context information where/why it happens or which queries ran. If that is possible.

For now we look at the other many proposals, your nice tool made for our hibernate usage. Thank you for that.

@vladmihalcea
Copy link
Owner

I created the #144 issue for the runtime event aggregation.

The query events contain the query info, but the session events don't contain such info. One solution would be to store a Session summary, containing the queries that were executed and the flush time info.

Thanks for using it and for giving me feedback about it.

@vladmihalcea
Copy link
Owner

Should have been fixed by #146. If it wasn't, then I'll reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants