Skip to content

Instantly share code, notes, and snippets.

@xupeng
Created December 17, 2011 06:31
Show Gist options
  • Save xupeng/1489479 to your computer and use it in GitHub Desktop.
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
#!/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