[MDEV-3624] LP:643463 - slow XtraDB shutdown due to 10 second sleep in purge thread Created: 2010-09-20  Updated: 2015-02-02  Resolved: 2012-10-04

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Trivial
Reporter: Kristian Nielsen Assignee: Kristian Nielsen
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug643463.xml     File LPexportBug643463_COPYING.innodb_fast_shutdown     Text File LPexportBug643463_mbug643463-2.patch     Text File LPexportBug643463_mbug643463.patch     Text File LPexportBug643463_mbug643463.patch    

 Description   

Shutting down XtraDB can take up to 10 seconds, even when there is no actual
work to do during shutdown.

An easy way to see this is to run a quick innodb test in the mysql-test-run.pl
test suite:

./mtr innodb-consistent

This takes >10 seconds, even though the actual test runs instantaneous.

The problem is this code in srv/srv0srv.c:

srv_purge_thread(...)
{
ulint sleep_ms= 10000; /* initial: 10 sec. */
...

loop:
if (srv_shutdown_state > 0)

{ ... }

os_thread_sleep( sleep_ms * 1000 );
...
goto loop;

So right after startup, the purge thread sleeps for 10 seconds, so server
cannot shut down for at least 10 seconds after startup.

Of course, in a production server, the purge thread sleep could have adjusted
itself to less than 10 seconds, and a busy server anyway will probably need
much more than 10 seconds to shut down cleanly.

But for development and testing, it is annoying to have to wait for 10 seconds
for shutdown.

Suggested fix:

Change the os_thread_sleep() into a sleep that can be interrupted by
shutdown. For example a wait with os_event_wait_time() on an event created
specifically for this. (Note that currently os_event_wait_time() waits
infinitely on non-windows, but it looks easy to fix this using
pthread_cond_timedwait()). Then signal the purge thread sleep to wakeup early
during server shutdown.



 Comments   
Comment by Kristian Nielsen [ 2010-09-20 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
Work-around: --innodb-fast-shutdown=2, if that is acceptable (which it probably often is during test/development).

Comment by Kristian Nielsen [ 2010-09-30 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
Just tested running the full test suite on my laptop (release build):

(cd mysql-test && time ./mtr --mem --parallel=3 --force)
-> 18:16.60elapsed

(cd mysql-test && time ./mtr -mem --parallel=3 --force --mysqld=-loose-innodb-fast-shutdown=2)
-> 11:14.47elapsed

So that's 38% faster ... so fixing this does seem rather worth-while.

Comment by Kristian Nielsen [ 2010-10-29 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
Here is a patch for this.

It greatly speeds up server shutdown for tests (though --innodb-fast-shutdown=2 is still a couple seconds faster).

Comment by Kristian Nielsen [ 2010-10-29 ]

Here is a patch for this.

It greatly speeds up server shutdown for tests (though --innodb-fast-shutdown=2 is still a couple seconds faster).
Patch with suggested fix
LPexportBug643463_mbug643463.patch

Comment by Kristian Nielsen [ 2010-11-03 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
I updated the patch, attached. I will push this patch into MariaDB, hopefully it can be included
upstream in XtraDB.

Comment by Kristian Nielsen [ 2010-11-03 ]

I updated the patch, attached. I will push this patch into MariaDB, hopefully it can be included
upstream in XtraDB.
Revised patch
LPexportBug643463_mbug643463-2.patch

Comment by Kristian Nielsen [ 2010-11-09 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
I used PMP to find some more sleeps in the XtraDB shutdown code. This additional
patch, which goes on top of the one attached before, fixes the remaining cases.

With this, server shutdown during mtr tests is very close to --innodb-fast-shutdown-2.

Comment by Kristian Nielsen [ 2010-11-09 ]

I used PMP to find some more sleeps in the XtraDB shutdown code. This additional
patch, which goes on top of the one attached before, fixes the remaining cases.

With this, server shutdown during mtr tests is very close to --innodb-fast-shutdown-2.
Additional patch fixing more sleeps during shutdown
LPexportBug643463_mbug643463.patch

Comment by Kristian Nielsen [ 2010-11-16 ]

Re: slow XtraDB shutdown due to 10 second sleep in purge thread
Attaching BSD copyright license for the patches submitted to this bug report.

Comment by Kristian Nielsen [ 2010-11-16 ]

Attaching BSD copyright license for the patches submitted to this bug report.
BSD copyright license for attached patches
LPexportBug643463_COPYING.innodb_fast_shutdown

Comment by Rasmus Johansson (Inactive) [ 2011-12-13 ]

Launchpad bug id: 643463

Generated at Thu Feb 08 06:50:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.