Documentation
¶
Overview ¶
Package mysql implements the "mysql" protocol.Protocol driver, for load testing a MySQL or MariaDB server (or a database that speaks the same wire protocol, such as TiDB). It uses a pure Go client.
Each call to Do runs one SQL text, read from -body, and reads every row it returns. The connections are kept in a pool that all users share, as an application's connection pool is. Waiting for a free connection counts as part of the measured time, so give -opt pool at least as many connections as users when you want to measure the server and not the queue.
Options (set with -opt key=value):
username The database user. It can also be given in the URL.
password_env The name of an environment variable that holds the
password. It needs a user. The password is never put on
the command line, and it is refused in the URL.
database The database. It can also be given as the path of the URL.
tls preferred (default), false, true, or skip-verify.
true checks the certificate and the host name. With
-insecure, true does not check the certificate.
preferred uses TLS when the server offers it, and plain
text when it does not. With ca_file, preferred checks
the certificate and still falls back to plain text.
ca_file PEM CAs. They replace the system roots. See tlsconf.
cert_file PEM client certificate. It needs key_file.
key_file PEM private key for cert_file. Encrypted keys are refused.
tls_server_name Name to send as SNI and to check on the certificate.
pool The most connections the run opens (default 10).
allow_writes true to let the SQL change data. The default is read-only:
every new connection runs SET SESSION TRANSACTION READ ONLY,
so a load test cannot change data by mistake. A statement
that writes then fails, and the error says how to allow it.
This is a safety net, not a lock: the SQL can still ask for
a read-write transaction itself (START TRANSACTION READ WRITE).
"set session transaction read write; insert ..." in one text
works. The next call is blocked, because SET discards the
connection.
query_mode simple (default) or prepared. simple sends the SQL as one
text, so it can hold several statements such as
"begin; update ... where id = ?; select ...; commit",
with or without args. VegaLoad puts the args into the text
as quoted values. prepared prepares the statement once and
reuses it, as most applications do. It runs one statement
and does not keep a connection for the call, so it cannot
run set, use, lock, xa, unlock, begin, or start.
args A JSON array of values for the ? placeholders, such as
'[42, "abc"]'.
min_rows The result must have at least this many rows.
expect Some value in the result must contain this text. Only the
first max_rows rows are checked.
max_rows How many rows a scenario script gets back (default 1000).
Every row is read and counted either way.
The target is mysql://host[:port][/database] (or mariadb://), with port 3306 by default. The URL may end with ?tls=.... Any other setting after the "?" is refused.
A text of several statements reports rowsAffected as 0. The client library skips a result that has no columns, so the affected-row count of an update that shares the text with a select is not available. A single insert or update does report rowsAffected and lastInsertId.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Options = append([]string{ "username", "password_env", "database", "tls", "pool", "allow_writes", "query_mode", "args", "min_rows", "expect", "max_rows", }, tlsconf.Keys...)
Options are the -opt keys this driver accepts. The command's protocol table uses the same list, so the two cannot differ.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is a MySQL protocol.Protocol.
func New ¶
New returns a ready-to-use Driver for target. target.URL is mysql://host[:port][/database]. The SQL is target.Body.
New returns an error only for a configuration problem, never for the server being unreachable, which Do reports per call. Creating the pool does not connect.
func NewConn ¶
NewConn is New for a scenario script. It makes only the connection pool: the server, the login and the connection options. It needs no SQL. The job of each call is then set with Call. password is the password, which the script already holds, so password_env is not used with it.
func (*Driver) Call ¶
Call returns a Driver for one call of a script: the same pool as d, with the job that opts and body describe. opts must hold the same connection options d was made with. The result shares d's pool, so closing it is d's job, not the caller's.
func (*Driver) Close ¶
Close implements protocol.Protocol. It closes the pool and any prepared statements. A Driver made with Call shares the pool, so Close on it does nothing.
type Reply ¶
type Reply struct {
// Columns are the column names of the result.
Columns []string
// Rows are the first max_rows rows, each as plain values in column order.
Rows [][]any
// RowCount is how many rows the result had, including rows past max_rows.
RowCount int
// RowsAffected is how many rows a single insert, update or delete
// changed. It is 0 when the text holds several statements: that count
// is not available then.
RowsAffected int64
// LastInsertID is the id a single insert produced. It is 0 when the
// text holds several statements.
LastInsertID int64
}
Reply is what a call read, besides the result.