Databases 4 min read

Impact of Adjusting System Time on MySQL Runtime Behavior

The article investigates how changing the operating system clock while MySQL is running influences functions such as SLEEP, metadata lock (MDL) wait calculations, and other timing‑related mechanisms, demonstrating that forward or backward adjustments can cause premature exits or inaccurate wait measurements.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Impact of Adjusting System Time on MySQL Runtime Behavior

When the system time is altered during MySQL execution, various internal timers and wait‑time calculations can be affected.

Experiment 1: After creating a test database, a session runs SLEEP . While the session is sleeping, the server clock is moved forward by 10 seconds. The SLEEP call returns immediately after only about 0.82 seconds, showing that the sleep duration is based on the system clock.

Experiment 2: One session locks a table. In a second session, a timestamp is printed, lock_wait_timeout is adjusted, and the locked table is accessed. The system clock is then moved backward by 10 seconds. When the request finally times out, the measured lock duration is 17 seconds, indicating that MySQL’s MDL wait‑time calculation is directly influenced by the system clock.

Tip: The method used to obtain the system time in the article reads from /proc/timer_list , which reflects a monotonic clock that is not affected by manual time changes. Using a monotonic clock (e.g., via clock_gettime(CLOCK_MONOTONIC) ) provides an objective measurement of actual wait time.

Beyond MDL, adjusting the system time can also impact semi‑synchronous replication wait times, delayed replication lag calculations, and other time‑sensitive operations. The recommended practice is to avoid changing the system clock while MySQL is running; if a change is necessary, restart MySQL promptly.

Thought question: Design an experiment to measure InnoDB lock wait times and compare the results with those observed for MDL, exploring why the differences occur.

MySQLdatabase performancemetadata locklock_wait_timeoutmonotonic clocksystem time
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.