[CONJ-297] Useless memory consumption when using Statement.setQueryTimeout Created: 2016-05-17  Updated: 2016-05-23  Resolved: 2016-05-18

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4
Fix Version/s: 1.4.5

Type: Task Priority: Major
Reporter: Diego Dupin Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

Since commit https://github.com/MariaDB/mariadb-connector-j/commit/efc6405.
When using Statement.setQueryTimeout, and execution is done before timeout, the cancel task will not be executed, but stay on memory until timeout is excedded.

If timeout is set to a very big amount of time (like one hour), all those cancel task will consume memory needlessly.



 Comments   
Comment by Diego Dupin [ 2016-05-23 ]

The initial commit version permits better thread handling when there is a lot of Statement.setQueryTimeout but create another problem:
Every query with queryTimeout (even finished before the timeout) will have 40 bytes in memory until the task is removed from queue.

The problem is for very long timeout (like 1 hour), this will lead to memory consumption, and CPU (due to garbage).

Immediate solution was to use java 1.7 ScheduledThreadPoolExecutor.setRemoveOnCancelPolicy(true), that remove immediately the task from queue when cancelled, but testing performance, the queue dynamic resizing lead to even more memory consumption (a lot more).

Correction is done using java 1.5 Timer :
commit 1 : https://github.com/MariaDB/mariadb-connector-j/commit/5a2a4e572dd00713add39a28b1006fda226c3693
commit 2 after contributor remarks : https://github.com/MariaDB/mariadb-connector-j/commit/ffe9527c7bdc0860d550589df25d9830926329ef

Generated at Thu Feb 08 03:14:38 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.