Last active
May 24, 2018 08:30
-
-
Save esolitos/542d69182f70f71dd1aa04b5d662eaf5 to your computer and use it in GitHub Desktop.
Test the creation
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
#!/bin/bash | |
if [ $# -ne 1 ]; then | |
echo "Usage: $(basename $0) NUM_TABLES" | |
echo "(Test with 2500 or more tables and up to get real reference)" | |
exit 1; | |
fi | |
if [ $(id -u) -ne 0 ]; then | |
echo "Please run this command as root or via sudo" | |
exit 1; | |
fi | |
mysqld_print_open_files() { | |
mysqld_user="$(ps aux | grep "mysqld " | cut -d' ' -f1 | head -n1)" | |
printf "mysqld open files:\t..." | |
printf "\b\b\b%3d" "$(lsof -u"$mysqld_user" | wc -l)" | |
} | |
printf "System Max Files limit:\n%s\n" "$(launchctl limit maxfiles)" | |
mysqld_print_open_files | |
printf "\n\n" | |
DB_NAME="mysql_descriptors_test" | |
read -p "mysql host (localhost):" my_host | |
if [[ -z "$my_host" ]]; then | |
my_host='localhost' | |
fi | |
read -p "mysql user ($(whoami)):" my_user | |
if [[ -z "$my_user" ]]; then | |
my_user=$(whoami) | |
fi | |
# setup local login for mysq | |
printf "mysql " | |
mysql_config_editor set --login-path=mysqltest --warn --host="$my_host" --user="$my_user" --password | |
mysql="$(which mysql) --login-path=mysqltest" | |
printf "\n" | |
$mysql -e "DROP DATABASE IF EXISTS $DB_NAME" | |
$mysql -e "CREATE DATABASE $DB_NAME" | |
open_files_limit="$($mysql -sse "SELECT @@open_files_limit")" | |
for i in $(seq 1 $1); do | |
$mysql $DB_NAME -e "CREATE TABLE tmp_$i (id INT UNSIGNED)" | |
if [ $? -ne 0 ]; then | |
echo "Failed creating table #$i" | |
exit 1 | |
fi | |
if [ $(expr $i % 100) -eq 0 ]; then | |
printf "## Iteration:\t%3d\nmysqld files limit\t%s\n%s\n\n" "$i" "$open_files_limit" "$(mysqld_print_open_files)" | |
fi | |
done | |
echo "Cleanup leftovers..." | |
$mysql -e "DROP DATABASE IF EXISTS $DB_NAME" | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment