Skip to content

Commit

Permalink
Merge pull request #404 from percona/ps-9461
Browse files Browse the repository at this point in the history
PS-9461 [DOCS] - Update kill idle transactions in 8.4
  • Loading branch information
patrickbirch authored Dec 10, 2024
2 parents 327da09 + 5086f65 commit 615114f
Showing 1 changed file with 59 additions and 7 deletions.
66 changes: 59 additions & 7 deletions docs/kill-idle-trx.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,60 @@
# Kill idle transactions
# Kill idle transaction

This feature limits the age of idle transactions, for all transactional storage
engines. If a transaction is idle for more seconds than the threshold
specified, it will be killed. This prevents users from blocking *InnoDB* purge
by mistake.
Database servers face a constant challenge: managing resources efficiently while maintaining system stability. The kill idle transactions timeout option is a strategic tool to address this challenge. When you set a time limit, any transaction that stays inactive beyond this limit is automatically stopped. This action prevents forgotten or stuck transactions from slowing down your database by blocking critical cleanup processes.

The option has the following benefits:

* Automatically terminates long-running, inactive database connections

* Prevents resource hogging by abandoned or forgotten transactions

* Frees up database connection pools

* Reduces unnecessary memory consumption

* Protects against potential connection leaks

* Prevents unnecessary server load from dormant sessions

You must also be consider the following:

* May interrupt legitimate long-running queries

* Requires careful configuration to avoid disrupting critical processes

* Can cause unexpected application behavior if timeout is too aggressive

* Might create additional overhead in monitoring and logging

* Requires precise tuning for different application requirements


We recommend that you start with conservative timeout settings and review the logs frequently to track terminated transactions.

This feature works with all types of database storage that support transactions.

## Determine the idle transaction threshold

When setting up a database, you must decide how long to let inactive transactions sit before ending them. This decision affects the database's performance.

| Items to consider | Description |
|---------------------------------|------------------------------------------------------------------------------------------------------|
| How your database is used | Look at how long transactions usually take and how often they happen. If most transactions finish quickly, you should end idle ones sooner. |
| How many things happen at once | Count how many transactions your system handles simultaneously. If it's a lot, you might need to end idle transactions faster to free up space for new ones. |
| How it affects speed | Watch how idle transactions change your database's speed. If they slow things down a lot, ending them sooner can help keep everything running smoothly. |
| What your business needs | Consider what's important for your work. Some important transactions might need more time, so you shouldn't end them too quickly. |

## InnoDB purge

The InnoDB purge process in MySQL removes outdated row versions (undo logs) from the system. When a transaction modifies data, InnoDB keeps old row versions for rollback and to support transactions running with multi-version concurrency control (MVCC). Once these versions are no longer needed, the purge process deletes them to free up space and improve performance.

Blocking the InnoDB purge can lead to increased disk space usage and potential performance degradation. This feature helps prevent issues such by:

* Limiting idle transactions: It kills any idle transaction after a specified threshold, ensuring transactions don’t remain idle for too long.

* Preventing mistakes: Users can’t accidentally block the InnoDB purge by leaving transactions idle.

* Improving performance: Keeping the purge process running smoothly helps maintain optimal database performance.

## System variables

Expand All @@ -16,6 +67,7 @@ by mistake.
| Dynamic: | Yes |
| Data type | Integer |
| Default value | 0 (disabled) |
| Units | Seconds |
| Unit | Seconds |

If set to a non-zero value, the server kills any idle transaction after it stays idle for this number of seconds.

If non-zero, any idle transaction will be killed after being idle for this many seconds.

0 comments on commit 615114f

Please sign in to comment.