This is a read-only copy of the MariaDB Knowledgebase generated on 2024-11-21. For the latest, interactive version please visit https://mariadb.com/kb/.

mariadb-slap

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

Prior to MariaDB 10.5, the client was called mysqlslap. It can still be accessed under this name, via a symlink in Linux, or an alternate binary in Windows.

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

Using mariadb-slap

The command to use mariadb-slap and the general syntax is:

mariadb-slap [options]

Options

mariadb-slap supports the following options:

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/mariadb-slap.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, mariadb-slap --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.
--sslEnables TLS. TLS is also enabled even without setting this option when certain other TLS options are set. The --ssl option will not enable verifying the server certificate by default. In order to verify the server certificate, the user must specify the --ssl-verify-server-cert option.
--ssl-ca=nameDefines a path to a PEM file that should contain one or more X509 certificates for trusted Certificate Authorities (CAs) to use for TLS. This option requires that you use the absolute path, not a relative path. See Secure Connections Overview: Certificate Authorities (CAs) for more information. This option implies the --ssl option.
--ssl-capath=nameDefines a path to a directory that contains one or more PEM files that should each contain one X509 certificate for a trusted Certificate Authority (CA) to use for TLS. This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See Secure Connections Overview: Certificate Authorities (CAs) for more information. This option is only supported if the client was built with OpenSSL or yaSSL. If the client was built with GnuTLS or Schannel, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms. This option implies the --ssl option.
--ssl-cert=nameDefines a path to the X509 certificate file to use for TLS. This option requires that you use the absolute path, not a relative path. This option implies the --ssl option.
--ssl-cipher=nameList of permitted ciphers or cipher suites to use for TLS. This option implies the --ssl option.
--ssl-crl=nameDefines a path to a PEM file that should contain one or more revoked X509 certificates to use for TLS. This option requires that you use the absolute path, not a relative path. See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information. This option is only supported if the client was built with OpenSSL or Schannel. If the client was built with yaSSL or GnuTLS, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
--ssl-crlpath=nameDefines a path to a directory that contains one or more PEM files that should each contain one revoked X509 certificate to use for TLS. This option requires that you use the absolute path, not a relative path. The directory specified by this option needs to be run through the openssl rehash command. See Secure Connections Overview: Certificate Revocation Lists (CRLs) for more information. This option is only supported if the client was built with OpenSSL. If the client was built with yaSSL, GnuTLS, or Schannel, then this option is not supported. See TLS and Cryptography Libraries Used by MariaDB for more information about which libraries are used on which platforms.
--ssl-key=nameDefines a path to a private key file to use for TLS. This option requires that you use the absolute path, not a relative path. This option implies the --ssl option.
--ssl-verify-server-certEnables server certificate verification. 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.

Option Files

In addition to reading options from the command-line, mariadb-slap can also read options from option files. If an unknown option is provided to mariadb-slap in an option file, then it is ignored.

The following options relate to how MariaDB command-line tools handles option files. They must be given as the first argument on the command-line:

OptionDescription
--print-defaultsPrint the program argument list and exit.
--no-defaultsDon't read default options from any option file.
--defaults-file=# Only read default options from the given file #.
--defaults-extra-file=# Read this file after the global files are read.
--defaults-group-suffix=# In addition to the default option groups, also read option groups with this suffix.

mariadb-slap is linked with MariaDB Connector/C. However, MariaDB Connector/C does not yet handle the parsing of option files for this client. That is still performed by the server option file parsing code. See MDEV-19035 for more information.

Option Groups

mariadb-slap reads options from the following option groups from option files:

GroupDescription
[mysqlslap] Options read by mariadb-slap, which includes both MariaDB Server and MySQL Server.
[mariadb-slap]Options read by mariadb-slap. Available starting with MariaDB 10.4.6.
[client] Options read by all MariaDB and MySQL client programs, which includes both MariaDB and MySQL clients. For example, mysqldump.
[client-server]Options read by all MariaDB client programs and the MariaDB Server. This is useful for options like socket and port, which is common between the server and the clients.
[client-mariadb]Options read by all MariaDB client programs.

Examples

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

mariadb-slap 
 --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.

mariadb-slap
 --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
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.