Mysql压力测试shell脚本_MySQL
bitsCN.com
Mysql压力测试shell脚本
Mysql自带了压力测试工具mysqlslap,所以我们可以不用自己编写程序来测试Mysql读取的压力。压力测试shell脚本如下: www.bitsCN.com
[plain]
#!/bin/sh
while true
do
mysqlslap --concurrency=100 --iterations=10 --create-schema='test' --query="insert into test(c1,c2,c3,c4) values(1,1,1,'a')" --number-of-queries=200 --debug-info -uroot -p123456
usleep 100
done
上面脚本的意思是每隔100ms循环做这样的事:模拟100个mysql客户端,对数据库test的表test执行200次插入(number-of-queries = concurrency * 每个mysql客户端的查询次数,所以这里的每个mysql客户端的查询次数是2次),迭代10次。--debug-info是打印内存和CPU的相关信息。
接着我们可以编写shell脚本来输出指定时间间隔(比如1秒)内的mysql操作次数,shell脚本如下:
[plain]
#!/bin/sh
lastTimes="0"
while true
do
currentTimes=$(mysql -uroot -p'123456' -e "show global status like 'Com_insert'" | sed '1d' | awk '{print $2}')
times=$(expr ${currentTimes} - ${lastTimes})
lastTimes="${currentTimes}"
echo "${times}"
sleep 1
done
查看mysql各种操作的次数,可以通过查看global status里的'Com_'开头的变量,它们就是mysql的操作命令,比如Com_insert就是插入命令、Com_update就是更新命令,等等,具体可以查看文档说明。将相邻两次的次数相减,就得到这个时间间隔内执行的次数。
PS:除了iostat等命令外,也可以通过top命令来查看io的负载(看wait的百分比,如果大于等于 1 / cpu核数,则说明硬盘IO有问题)。请参考英文文章:Understanding Disk I/O - when should you be worried?
来源 http://blog.csdn.net/skyman_2001
bitsCN.com
Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use Docker for container performance testing and stress testing requires specific code examples. Introduction The rise of container virtualization technology has made the deployment and operation of applications more flexible and efficient. One of the most popular tools is Docker. As a lightweight containerization platform, Docker provides a convenient way to package, distribute and run applications, but how to test and evaluate the performance of containers, especially stress testing under high load conditions, It is a question that many people are concerned about. This article will introduce

Title: Steps and techniques for using Golang programming on Mac In the current field of software development, Golang (also known as Go), as an efficient, concise, and highly concurrency programming language, has attracted the attention of more and more developers. use. When programming Golang on the Mac platform, you can use some tools and techniques to improve development efficiency. This article will introduce the steps and techniques of using Golang programming on Mac, and provide specific code examples to help readers better understand and apply. Step 1: Install Gol

Use PHP to write programs to connect to Baidu Cloud Disk API. Baidu Cloud Disk is a powerful cloud storage service. Through the API, many automated operations can be realized, such as uploading files, downloading files, creating folders, etc. This article will introduce how to use PHP to write a program to connect to Baidu Cloud Disk API, and give corresponding code examples. Obtain Baidu Cloud's developer account and APIKey. Before using Baidu Cloud Disk API, we need to apply for a developer account and obtain the corresponding APIKey. Can log in to Baidu

Linux is an open source operating system that provides a wealth of network testing and stress testing tools, so Linux is a very good choice when conducting network testing and stress testing. In this article, we'll cover how to use Linux for network testing and stress testing. 1. Network testing Network testing is the process of testing network performance, which usually includes the following tests: Bandwidth test When performing network bandwidth testing, we need to measure the transmission speed of data in the network. One of the commonly used tools is iperf, which is available on Linux

Software stress testing is a basic quality assurance activity that is part of every important software testing effort. Therefore, stress testing is very important, so how to conduct stress testing? In this article, I will share with you a super practical stress testing tool - ab tool (apache bench). I hope it will be helpful to you!

PHP is a scripting language widely used in web development. It is used to develop many large-scale websites and applications. Performance optimization and stress testing are very critical during PHP application development, as this will help you ensure that the application can withstand high loads of user traffic during actual operation without performance issues or system issues. collapse. This article mainly introduces some common stress testing tools used in PHP. ApacheBenchApacheBench(ab) is a basic

How to use MTR for MySQL database stress testing? Overview: MySQLTestRun (MTR) is a testing tool officially provided by MySQL for testing the functionality and performance of MySQL databases. In addition to functional testing, MTR can also be used for database stress testing. This article will introduce how to use MTR for MySQL database stress testing and provide some code examples. Step 1: Install MTR First, we need to install the MTR tool. MTR is in the MySQL source code

The split() method of String class. Split the current string into matches of the given regular expression. The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or terminates at the end of the string. The replaceAll() method of String class accepts two strings representing regular expressions and a replacement string and replaces the matching value with the given string. Replace all characters in the file except specific words with "#" (one way) - read the contents of the file into a string. Create an empty StringBuffer object. Use the split() method to split the obtained string into a String array. all over
