mysqlslap is a tool for load-testing MariaDB. It allows you to emulate multiple concurrent connections, and run a set of queries multiple times.

It returns a benchmark including the following information:

  • Average number of seconds to run all queries
  • Minimum number of seconds to run all queries
  • Maximum number of seconds to run all queries
  • Number of clients running queries
  • Average number of queries per client

Syntax

mysqlslap [options]

Options

The following variables can be set while passed as commandline options to mysqlslap, or set in the [mysqlslap], [client], [client-server] or [client-mariadb] sections in your my.cnf file.

OptionDescription
-a, --auto-generate-sqlGenerate SQL statements automatically when they are not supplied in files or via command options.
--auto-generate-sql-add-autoincrementAdd an AUTO_INCREMENT column to auto-generated tables.
--auto-generate-sql-execute-number=numSpecify how many queries to generate automatically.
--auto-generate-sql-guid-primaryAdd GUID based primary keys to auto-generated tables.
--auto-generate-sql-load-type=name Specify the test load type. The allowable values are read (scan tables), write (insert into tables), key (read primary keys), update (update primary keys), or mixed (half inserts, half scanning selects). The default is mixed.
--auto-generate-sql-secondary-indexes=numNumber of secondary indexes to add to auto-generated tables. By default, none are added.
--auto-generate-sql-unique-query-number=numNumber of unique queries to generate for automatic tests. For example, if you run a key test that performs 1000 selects, you can use this option with a value of 1000 to run 1000 unique queries, or with a value of 50 to perform 50 different selects. The default is 10.
--auto-generate-sql-unique-write-number=numNumber of unique queries to generate for auto-generate-sql-write-number.
--auto-generate-sql-write-number=numNumber of row inserts to perform for each thread. The default is 100.
--commit=numNumber of statements to execute before committing. The default is 0.
-C, --compressUse compression in server/client protocol if both support it.
-c name, --concurrency=nameNumber of clients to simulate for query to run.
--create=nameFile or string containing the statement to use for creating the table.
--create-schema=nameSchema to run tests in.
--csv[=name]Generate comma-delimited output to named file or to standard output if no file is named.
-# , --debug[=options]For debug builds, write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/mysqlslap.trace.
--debug-checkCheck memory and open file usage at exit.
-T, --debug-infoPrint some debug info at exit.
--default-auth=nameDefault authentication client-side plugin to use.
--defaults-extra-file=nameRead this file after the global files are read. Must be given as the first option.
--defaults-file=nameOnly read default options from the given file name Must be given as the first option.
-F name, --delimiter=nameDelimiter to use in SQL statements supplied in file or command line.
--detach=numDetach (close and reopen) connections after the specified number of requests. The default is 0 (connections are not detached).
-e name, --engine=nameComma separated list of storage engines to use for creating the table. The test is run for each engine. You can also specify an option for an engine after a #:#, for example memory:max_row=2300.
-?, --helpDisplay help and exit.
-h name, --host=nameConnect to the MariaDB server on the given host.
--init-command=nameSQL Command to execute when connecting to the MariaDB server. Will automatically be re-executed when reconnecting. Added in MariaDB 5.5.34.
-i num, --iterations=numNumber of times to run the tests.
--no-defaultsDon't read default options from any option file. Must be given as the first option.
--no-dropDo not drop any schema created during the test after the test is complete.
-x name, --number-char-cols=nameNumber of VARCHAR columns to create in table if specifying --auto-generate-sql.
-y name, --number-int-cols=nameNumber of INT columns to create in table if specifying --auto-generate-sql.
--number-of-queries=numLimit each client to approximately this number of queries. Query counting takes into account the statement delimiter. For example, if you invoke as follows, mysqlslap --delimiter=";" --number-of-queries=10 --query="use test;insert into t values(null)", the #;# delimiter is recognized so that each instance of the query string counts as two queries. As a result, 5 rows (not 10) are inserted.
--only-printDo not connect to the databases, but instead print out what would have been done.
-p[password], --password[=password]Password to use when connecting to server. If password is not given it's asked from the command line. Specifying a password on the command line should be considered insecure. You can use an option file to avoid giving the password on the command line.
-W, --pipeOn Windows, connect to the server via a named pipe. This option applies only if the server supports named-pipe connections.
--plugin-dir=nameDirectory for client-side plugins.
-P num, --port=numPort number to use for connection.
--post-query=nameQuery to run or file containing query to execute after tests have completed. This execution is not counted for timing purposes.
--post-system=namesystem() string to execute after tests have completed. This execution is not counted for timing purposes.
--pre-query=nameQuery to run or file containing query to execute before running tests. This execution is not counted for timing purposes.
--pre-system=namesystem() string to execute before running tests. This execution is not counted for timing purposes.
--print-defaultsPrint the program argument list and exit. Must be given as the first option.
--protocol=nameThe protocol to use for connection (tcp, socket, pipe, memory).
-q name, --query=nameQuery to run or file containing query to run.
--shared-memory-base-nameShared-memory name to use for Windows connections using shared memory to a local server (started with the --shared-memory option). Case-sensitive.
-s, --silentRun program in silent mode - no output.
-S, --socket=nameFor connections to localhost, the Unix socket file to use, or, on Windows, the name of the named pipe to use.
--sslEnable TLS for connection (automatically enabled with other flags).
--ssl-ca=nameCA file in PEM format (check OpenSSL docs, implies --ssl).
--ssl-capath=nameCA directory (check OpenSSL docs, implies --ssl).
--ssl-cert=nameX509 cert in PEM format (implies --ssl).
--ssl-cipher=nameSSL cipher to use (implies --ssl).
--ssl-key=nameX509 key in PEM format (implies --ssl).
--ssl-crl=nameCertificate revocation list (implies --ssl).
--ssl-crlpath=nameCertificate revocation list path (implies --ssl).
--ssl-verify-server-certVerify server's "Common Name" in its cert against hostname used when connecting. This option is disabled by default.
-u, --user=nameUser for login if not current user.
-v, --verboseMore verbose output; you can use this multiple times to get even more verbose output.
-V, --versionOutput version information and exit.

Examples

Create a table with data, and then query it with 40 simultaneous connections 100 times each.

mysqlslap 
 --delimiter=";" 
 --create="CREATE TABLE t (a int);INSERT INTO t VALUES (5)"
 --query="SELECT * FROM t"
 --concurrency=40
 --iterations=100

Benchmark
	Average number of seconds to run all queries: 0.010 seconds
	Minimum number of seconds to run all queries: 0.009 seconds
	Maximum number of seconds to run all queries: 0.020 seconds
	Number of clients running queries: 40
	Average number of queries per client: 1

Using files to store the create and query SQL. Each file can contain multiple statements separated by the specified delimiter.

mysqlslap
 --create=define.sql
 --query=query.sql
 --concurrency=10
 --iterations=20
 --delimiter=";"

Benchmark
	Average number of seconds to run all queries: 0.002 seconds
	Minimum number of seconds to run all queries: 0.002 seconds
	Maximum number of seconds to run all queries: 0.004 seconds
	Number of clients running queries: 10
	Average number of queries per client: 1

Comments

Comments loading...