Project

General

Profile

Bug #11502

Recycle dirty share H2 session

Added by Teodor Gorghe about 2 months ago. Updated 14 days ago.

Status:
Internal Test
Priority:
Normal
Assignee:
Target version:
-
Start date:
Due date:
% Done:

100%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
production:
No
env_name:
topics:

before.png (991 KB) Teodor Gorghe, 05/29/2026 07:58 AM

11502.patch Magnifier (1.7 KB) Teodor Gorghe, 06/08/2026 06:00 AM

perf-dirty.p Magnifier (623 Bytes) Teodor Gorghe, 06/08/2026 06:06 AM


Related issues

Related to Database - Bug #11288: Check if c3p0 is required for in-memory databases Test

History

#1 Updated by Teodor Gorghe about 2 months ago

Currently, on DefaultDirtyShareManager, when we need the dirty-share session, we use new Session(dirtyDatabase) and close it when we finish the work.
This may not be the optimal approach because when we open and close the H2 session, we pay the price for H2 session creation and configuration.

Also, H2 supports SQL parsing and plan caching. When we destroy the session every time, H2 cache gets cleaned up.

I have starting to do a proof of concept and test it in #10172, and I saw a slight performance increase (not significant).

#4 Updated by Alexandru Lungu about 2 months ago

Teodor, mind the effort in #8388 of dropping dirty-share being stored in H2, but in persistence database.

#5 Updated by Teodor Gorghe about 1 month ago

Artur, can you explain your changes for #11288 regarding dirty database?

I think the easiest way to fix the performance issue is using connection pooling for H2 dirty connection. The performance issue might be related to #11288.

These are the measurements which I have made, doing 20k FIND + dirty FIND queries:
  • Before: Cold 3957 ms Hot 3457 ms
  • After (using attached changes): Cold 2176 ms Hot 1781 ms.

Can you test the performance on your own without #11288?

#6 Updated by Teodor Gorghe about 1 month ago

  • Related to Bug #11288: Check if c3p0 is required for in-memory databases added

#7 Updated by Artur Școlnic about 1 month ago

Connection pooling was removed for the Meta and Dirty databases to simplify configuration and improve maintainability. Customer testing showed no measurable performance impact, the observed benefits were limited to standalone Java test cases. If you have hard evidence that adding the pooling back is improving performance for a customer project, then we can consider rewriting some code from 11288, however, make sure it is the connection reuse that helps and not some other side effect of using a DataSource.

#8 Updated by Teodor Gorghe about 1 month ago

Artur Școlnic wrote:

Connection pooling was removed for the Meta and Dirty databases to simplify configuration and improve maintainability. Customer testing showed no measurable performance impact, the observed benefits were limited to standalone Java test cases. If you have hard evidence that adding the pooling back is improving performance for a customer project, then we can consider rewriting some code from 11288, however, make sure it is the connection reuse that helps and not some other side effect of using a DataSource.

Maybe there was not so many FIND queries with dirty share in the tests used on #11288, but in a project, I see a substantial performance difference when keeping the connection in place vs opening and closing the connection everytime. Evidence is in #11502-5.

Of course there are side-effects using a DataSource. Since we are using C3P0, PreparedStatements are being cached, etc. There are H2 equivalents for these, but most important, we don't pay the price for opening and closing the connection everytime.

#9 Updated by Artur Școlnic about 1 month ago

If it helps a customer application, I am ok with adding it back, just make sure to inherit the configuration of the dirty db from the tenant private db.

#10 Updated by Teodor Gorghe about 1 month ago

Can you take into the patch? Is a reasonable change?

#11 Updated by Artur Școlnic about 1 month ago

It is good, but the used config for the data sources is the default one, it needs to use the tenant specific one to avoid cases where the persistent db has 100 connections and the dirty db (which, as you found, can be just as heavily used) has 5, thus becoming a bottleneck.

#12 Updated by Teodor Gorghe about 1 month ago

There is a list of c3p0 parameters which should not be copied from primary database, like minPoolSize, initialPoolSize, maxConnectionAge, etc.
maxPoolSize is safe to be copied.

Constantin/Greg, what do you think? We should copy only the safe parameters from primary database, or we should make these configurable from directory?

#13 Updated by Teodor Gorghe about 1 month ago

A quick reminder about the question from #11502-12.

#11502 is not a critical issue, but the performance is a bit worse, about 100% more time spent on dirty share logic because of #11288.

#14 Updated by Artur Școlnic about 1 month ago

Teodor, the shared db has a directory config, it can be used for the dirty shared db. The tenant private databases have their config in the landlord database, it is not in the directory, that same config needs to be used for the dirty tenant databases. We don't need dirty specific configs, just use the corresponding primary db ones.

#15 Updated by Teodor Gorghe about 1 month ago

I don't think cloning shared primary db / tenant primary db config because of #11502-12.

Dirty DB connections is definitely less than the number of active connections for PRIMARY database (it can either be shared or tenant config).

On single tenant projects, the used configuration is the "shared" one, where often, the parameters are fine-tuned for the main database. These parameters don't always fit for dirty share database. Default C3P0 configuration seems a good start, but it is possible in production to reach to the default maxPoolSize value (which is 15).

#16 Updated by Artur Școlnic about 1 month ago

Generally speaking I would expect the dirty db to be less strained than the primary one due to the limited scope of the dirty db transactions, but dirty config still needs to reflect the workload expected by the primary db, maybe not a one-to-one copy of the config, like you mentioned. Anyway, limiting the amount of the config that must be provided by the client is always a good practice, I still think the dirty db config needs to be derived from the primary one rather than be explicitly set in directory or landlord db.

#17 Updated by Teodor Gorghe 26 days ago

  • Status changed from New to WIP
  • Assignee set to Teodor Gorghe
  • % Done changed from 0 to 100
  • reviewer Constantin Asofiei added
Committed revision 16600 on task branch 11502a:
  • Pool H2 dirty-share database connection.

Constantin, please review the changes.

#18 Updated by Teodor Gorghe 26 days ago

  • Status changed from WIP to Review

#19 Updated by Constantin Asofiei 26 days ago

  • Status changed from Review to Internal Test

Teodor, I'm OK with the changes. Please rebase and also test with #10614 app.

#20 Updated by Teodor Gorghe 14 days ago

Artur tested with this branch and he confirmed that the testing on #10614 app has passed.

Also available in: Atom PDF