Created
December 17, 2011 06:31
-
-
Save xupeng/1489479 to your computer and use it in GitHub Desktop.
Utility script for setting access pattern of MySQL log files to recycle buffer cache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Utility script for setting access pattern of MySQL log files to recycle | |
buffer cache | |
""" | |
import os | |
import sys | |
import glob | |
import ctypes | |
import ctypes.util | |
POSIX_FADV_DONTNEED = 4 | |
libc = ctypes.CDLL(ctypes.util.find_library('c')) | |
def posix_fadvise(fd, offset, length, advice): | |
return libc.posix_fadvise(fd, | |
ctypes.c_uint64(offset), | |
ctypes.c_uint64(length), | |
advice) | |
LOG_PATTERNS = ( | |
'/log/mysql-*/*logs/*', | |
'/data/mysql-*/*logs/*', | |
'/backup/mysql-*/*logs/*', | |
'/backup/mysql-*/*/*ibd', | |
'/backup/mysql-*/*/*MY*', | |
) | |
for pattern in LOG_PATTERNS: | |
for log in glob.glob(pattern): | |
try: | |
fd = os.open(log, os.O_RDONLY) | |
except OSError, err: | |
print >> sys.stderr, err | |
continue | |
if posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED) != 0: | |
print >> sys.stderr, 'Failed to posix_fadvise for', log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment