duel-mysql 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +34 -1
- data/README.md +12 -8
- data/lib/duel/mysql/version.rb +1 -1
- data/lib/duel/mysql.rb +33 -27
- data/sig/duel/mysql.rbs +10 -9
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2c584095f7d338193a078423e5bfb28b9a13875782eb70d319c54c5914325a87
|
|
4
|
+
data.tar.gz: ed5184bb16077a96fb533e4d929ad912c3da70c415f40f7749cfbe76e5b220a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d59b5925afa3ae9159940305ed665168427a39afe0e4f1765e55b317e88ec62d71327df2fc3d53ab94585bdd0619c73b203d89b0778142fe9cd2bf7d2cd52ac1
|
|
7
|
+
data.tar.gz: cfca73f43a632757029a4aa0e8b07d2fb1cc8204b4f690f9d6e633beaefba3e4557e3bd29af8ad17135319d67a85b93136e666fcea6e5fea8a3c16d4c43f94b8
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-11-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- libmysqlclient's `MYSQL_UNIX_PORT` (but on Windows) and, with `tcp`,
|
|
15
|
+
`MYSQL_TCP_PORT` point at each worker's server, as duel-postgresql's
|
|
16
|
+
`PGHOST` and `PGPORT` do, so a mysql2 client given no socket or port
|
|
17
|
+
connects to it, not to the machine's MySQL.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- `sql:` is what each worker's database runs once its server starts
|
|
22
|
+
(a schema, say), in place of `setup:`, which is a hook's name
|
|
23
|
+
everywhere else in Duel.
|
|
24
|
+
- `settings:` gives each worker's server more of its system variables,
|
|
25
|
+
as a Hash (`settings: {sort_buffer_size: "4M"}`, passed as
|
|
26
|
+
`--sort_buffer_size=4M`), as duel-postgresql's `settings:` does, in
|
|
27
|
+
place of `args:`, a list of mysqld's options, as duel-redis's and
|
|
28
|
+
duel-memcached's `settings:` do too. They come last, so they win over
|
|
29
|
+
the plugin's own.
|
|
30
|
+
- `server:` is found by Duel's `Duel.find_program`, as duel-postgresql's
|
|
31
|
+
is: a path is expanded (`~/mysql/bin/mysqld`, say), and a directory
|
|
32
|
+
named `mysqld` on the `PATH` isn't taken for the program.
|
|
33
|
+
- It requires Duel 0.3.0 or later (`~> 0.3.0`), the release it's
|
|
34
|
+
tested with, as Duel 0.3.0 changes what plugins and benchmarks call.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- With a `server:` path that isn't there, the error no longer says
|
|
39
|
+
it's not on the PATH, and it asks for mysqld's path, as
|
|
40
|
+
duel-postgresql's does for postgres's.
|
|
41
|
+
|
|
10
42
|
## [0.2.0] - 2026-11-16
|
|
11
43
|
|
|
12
44
|
### Added
|
|
@@ -139,7 +171,8 @@ or later (not MariaDB).
|
|
|
139
171
|
CI.
|
|
140
172
|
- RBS signatures in sig/, checked with Steep.
|
|
141
173
|
|
|
142
|
-
[Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.
|
|
174
|
+
[Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.3.0...HEAD
|
|
175
|
+
[0.3.0]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.2.0...duel-mysql-v0.3.0
|
|
143
176
|
[0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.1.8...duel-mysql-v0.2.0
|
|
144
177
|
[0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.1.7...duel-mysql-v0.1.8
|
|
145
178
|
[0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-mysql-v0.1.6...duel-mysql-v0.1.7
|
data/README.md
CHANGED
|
@@ -67,9 +67,13 @@ does by default on Windows, whose MySQL has no Unix socket). No
|
|
|
67
67
|
nothing written to disk that needn't be, and InnoDB's statistics left as
|
|
68
68
|
they are (recalculated on their own, they'd change a query's plan while
|
|
69
69
|
it's measured: `ANALYZE TABLE` in a setup if you need them). Its URL is
|
|
70
|
-
in `DUEL_MYSQL_URL`, and in `DATABASE_URL` too,
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
in `DUEL_MYSQL_URL`, and in `DATABASE_URL` too, and libmysqlclient's
|
|
71
|
+
`MYSQL_UNIX_PORT` (but on Windows) and, with `tcp`, `MYSQL_TCP_PORT`
|
|
72
|
+
point at it, so a client that reads any of them finds it and nothing
|
|
73
|
+
reaches another database. (mysql2 reads the last two when it's given no
|
|
74
|
+
socket or port, though not its user, `root`. Trilogy reads none of
|
|
75
|
+
them.) The socket's path is in `DUEL_MYSQL_SOCKET` (with `tcp`, there's
|
|
76
|
+
none). Benchmarks can call `Duel::MySQL.url`,
|
|
73
77
|
`Duel::MySQL.socket`, `Duel::MySQL.execute` and `Duel::MySQL.reset`
|
|
74
78
|
(each of these two opens a connection of its own to the worker's
|
|
75
79
|
server, and closes it).
|
|
@@ -96,9 +100,9 @@ Options:
|
|
|
96
100
|
```ruby
|
|
97
101
|
c.use :mysql,
|
|
98
102
|
server: "/usr/local/mysql/bin/mysqld", # the program (default: DUEL_MYSQL_SERVER, or mysqld)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
env: %w[DATABASE_URL PRIMARY_URL], # variables given its URL besides DUEL_MYSQL_URL
|
|
103
|
+
settings: {sort_buffer_size: "4M"}, # more of its system variables, as --sort_buffer_size=4M (they win)
|
|
104
|
+
sql: File.read("db/structure.sql"), # SQL each worker's database runs first
|
|
105
|
+
env: %w[DATABASE_URL PRIMARY_URL], # variables given its URL besides DUEL_MYSQL_URL (default: DATABASE_URL)
|
|
102
106
|
scheme: "trilogy", # the URL's (Rails takes it for the adapter, mysql2 by default)
|
|
103
107
|
tcp: true # on a port of 127.0.0.1's, its URL mysql2://root@127.0.0.1:PORT/duel (default: on Windows only)
|
|
104
108
|
```
|
|
@@ -114,8 +118,8 @@ Initializing a data directory takes seconds, so it's done once (Duel's
|
|
|
114
118
|
database created in it, in your project's `tmp/duel/cache`, and every
|
|
115
119
|
worker (in that run and the next ones) starts with a copy. One is made
|
|
116
120
|
for each server program (and version of the plugin): another MySQL gets
|
|
117
|
-
its own. `duel
|
|
118
|
-
not its initialization's.)
|
|
121
|
+
its own. `duel clean` deletes them. (`settings` are the running
|
|
122
|
+
server's, not its initialization's.)
|
|
119
123
|
|
|
120
124
|
The metrics come from the server's status (`Questions`) and
|
|
121
125
|
`performance_schema` (its statement summaries), which MySQL updates as
|
data/lib/duel/mysql/version.rb
CHANGED
data/lib/duel/mysql.rb
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
require "duel"
|
|
4
4
|
require "digest"
|
|
5
5
|
require "fileutils"
|
|
6
|
-
require "rbconfig"
|
|
7
6
|
require "socket"
|
|
8
7
|
require_relative "mysql/version"
|
|
9
8
|
|
|
@@ -31,13 +30,21 @@ module Duel
|
|
|
31
30
|
# (or with +tcp+, on a port of 127.0.0.1's alone: by default on Windows,
|
|
32
31
|
# whose MySQL has none); its URL is in DUEL_MYSQL_URL, and in
|
|
33
32
|
# DATABASE_URL too (unless +env+ names others), and the socket's path
|
|
34
|
-
# in DUEL_MYSQL_SOCKET (with +tcp+, none).
|
|
35
|
-
#
|
|
33
|
+
# in DUEL_MYSQL_SOCKET (with +tcp+, none). libmysqlclient's
|
|
34
|
+
# MYSQL_UNIX_PORT (where there are Unix sockets) and MYSQL_TCP_PORT
|
|
35
|
+
# (with +tcp+) point at it too. The plugin's connections are a client
|
|
36
|
+
# of its own (see Connection): no gem's.
|
|
36
37
|
module MySQL
|
|
37
38
|
Duel.plugin(:mysql, self)
|
|
38
39
|
|
|
39
40
|
URL = "DUEL_MYSQL_URL"
|
|
40
41
|
SOCKET = "DUEL_MYSQL_SOCKET"
|
|
42
|
+
|
|
43
|
+
# Where libmysqlclient (mysql2's, the mysql command's) connects when
|
|
44
|
+
# it's given no socket or port.
|
|
45
|
+
UNIX_PORT = "MYSQL_UNIX_PORT"
|
|
46
|
+
TCP_PORT = "MYSQL_TCP_PORT"
|
|
47
|
+
|
|
41
48
|
DATABASE = "duel"
|
|
42
49
|
USER = "root"
|
|
43
50
|
|
|
@@ -64,29 +71,30 @@ module Duel
|
|
|
64
71
|
def self.worker_memory = 450 << 20
|
|
65
72
|
|
|
66
73
|
# Configures Duel for the plugin (c.use :mysql): the server and its
|
|
67
|
-
# metrics. +server+ is the program, +
|
|
68
|
-
# +
|
|
74
|
+
# metrics. +server+ is the program, +settings+ more of its system
|
|
75
|
+
# variables (sort_buffer_size: "4M", as --sort_buffer_size=4M), +sql+ what each worker's database runs when it's started (a
|
|
69
76
|
# schema, say), +env+ the variables given its URL besides
|
|
70
77
|
# DUEL_MYSQL_URL, and +scheme+ the URL's (Rails takes it for the
|
|
71
78
|
# adapter). A data directory is initialized once (Resource#cached),
|
|
72
79
|
# and each worker's is a copy. Returns the plugin's own connection
|
|
73
80
|
# to it, a worker's (see Config#in_worker, and in tests,
|
|
74
81
|
# Duel::Testing.in_worker).
|
|
75
|
-
def self.configure(config, server: ENV.fetch("DUEL_MYSQL_SERVER", "mysqld"),
|
|
82
|
+
def self.configure(config, server: ENV.fetch("DUEL_MYSQL_SERVER", "mysqld"), settings: {}, sql: nil, env: %w[DATABASE_URL],
|
|
76
83
|
scheme: "mysql2", tcp: !Duel.unix_sockets?)
|
|
77
84
|
config.prepare(:worker) do |w|
|
|
78
|
-
program =
|
|
85
|
+
program = Duel.find_program(server) ||
|
|
86
|
+
w.fail!("no #{server}#{" on the PATH" unless Duel.path?(server)} (give mysqld's path as server:, or DUEL_MYSQL_SERVER)")
|
|
79
87
|
data = w.path("data")
|
|
80
88
|
DataDir.new(w, program).create(data)
|
|
81
89
|
# (A Unix socket even with +tcp+, which MySQL can't do without:
|
|
82
90
|
# its own default's in a directory of the system's.)
|
|
83
91
|
socket = w.path("mysqld.sock")
|
|
84
92
|
if tcp
|
|
85
|
-
port = w.
|
|
93
|
+
port = w.free_port
|
|
86
94
|
listen = ["--port=#{port}", "--bind-address=127.0.0.1", "--socket=#{socket}"]
|
|
87
95
|
address = "127.0.0.1:#{port}"
|
|
88
|
-
url = "#{scheme}://#{USER}
|
|
89
|
-
vars = {URL => url}
|
|
96
|
+
url = "#{scheme}://#{USER}@#{address}/#{DATABASE}"
|
|
97
|
+
vars = {URL => url, TCP_PORT => port.to_s}
|
|
90
98
|
else
|
|
91
99
|
# (No network at all.)
|
|
92
100
|
address = socket
|
|
@@ -94,13 +102,20 @@ module Duel
|
|
|
94
102
|
url = "#{scheme}://#{USER}@localhost/#{DATABASE}?socket=#{address}"
|
|
95
103
|
vars = {URL => url, SOCKET => address}
|
|
96
104
|
end
|
|
97
|
-
|
|
105
|
+
# (libmysqlclient's defaults, for a client given no socket or port:
|
|
106
|
+
# its port, for 127.0.0.1, and its socket, which it takes for
|
|
107
|
+
# localhost, wherever there's one, even with +tcp+.)
|
|
108
|
+
vars[UNIX_PORT] = socket if Duel.unix_sockets?
|
|
109
|
+
# (+settings+' last: of an option given twice, mysqld takes the
|
|
110
|
+
# last.)
|
|
111
|
+
w.spawn(program, *(DataDir.options(data) + listen), "--pid-file=#{w.path("mysqld.pid")}", "--tmpdir=#{w.dir}", *RUNNING,
|
|
112
|
+
*settings.map { |name, value| "--#{name}=#{value}" })
|
|
98
113
|
# (Stopped with SHUTDOWN, before it's killed: on Windows, mysqld is
|
|
99
114
|
# a monitor, the server its child, which killing it would leave
|
|
100
115
|
# running.)
|
|
101
116
|
w.at_stop { shutdown(address) }
|
|
102
117
|
w.wait_until { Connection.ping(address) }
|
|
103
|
-
run(address,
|
|
118
|
+
run(address, sql) if sql
|
|
104
119
|
vars.merge(env.to_h { |name| [name, url] })
|
|
105
120
|
end
|
|
106
121
|
connection = config.in_worker { |w| Connection.new(address).tap { |mysql| w.at_stop { mysql.close } } }
|
|
@@ -136,7 +151,7 @@ module Duel
|
|
|
136
151
|
"mysql_queries" => {kind: :counted, unit: %w[query queries], calibrate: false},
|
|
137
152
|
"mysql_rows" => {kind: :counted, unit: %w[row rows], calibrate: false},
|
|
138
153
|
"mysql_rows_examined" => {kind: :counted, unit: %w[row rows], calibrate: false},
|
|
139
|
-
"mysql_time" => {kind: :
|
|
154
|
+
"mysql_time" => {kind: :timed, unit: "µs", floor: 300, across: false}
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
# What the worker's server has done so far, but for this connection
|
|
@@ -218,7 +233,7 @@ module Duel
|
|
|
218
233
|
# the +own+ digests, each one's [queries, rows, rows examined, time
|
|
219
234
|
# (ps), digest].
|
|
220
235
|
def self.digests(connection, since, own)
|
|
221
|
-
connection.query(format(DIGESTS, since,
|
|
236
|
+
connection.query(format(DIGESTS, since, connection.quote_all(own))).rows
|
|
222
237
|
end
|
|
223
238
|
|
|
224
239
|
# The digest of each of +statements+, read over +connection+.
|
|
@@ -227,7 +242,7 @@ module Duel
|
|
|
227
242
|
# The texts of the statements with these digests, by digest, read
|
|
228
243
|
# over +connection+.
|
|
229
244
|
def self.texts(connection, digests)
|
|
230
|
-
connection.query(format(TEXTS,
|
|
245
|
+
connection.query(format(TEXTS, connection.quote_all(digests))).to_h
|
|
231
246
|
end
|
|
232
247
|
|
|
233
248
|
# For benchmarks: the worker's server.
|
|
@@ -558,6 +573,9 @@ module Duel
|
|
|
558
573
|
# +text+ as a string literal.
|
|
559
574
|
def quote(text) = "'#{text.gsub(/[\0\n\r\\'"\x1a]/, ESCAPES)}'"
|
|
560
575
|
|
|
576
|
+
# +texts+ as a list of string literals, for IN (...).
|
|
577
|
+
def quote_all(texts) = texts.map { |text| quote(text) }.join(", ")
|
|
578
|
+
|
|
561
579
|
ESCAPES = {"\0" => "\\0", "\n" => "\\n", "\r" => "\\r", "\\" => "\\\\", "'" => "\\'", "\"" => "\\\"", "\x1a" => "\\Z"}.freeze
|
|
562
580
|
|
|
563
581
|
# Closes it without telling the server (no QUIT, which the server
|
|
@@ -776,18 +794,6 @@ module Duel
|
|
|
776
794
|
# A worker's data directory: a copy of one initialized once, with the
|
|
777
795
|
# database created in it.
|
|
778
796
|
class DataDir
|
|
779
|
-
# A program's file ends with +EXE+: on Windows, .exe.
|
|
780
|
-
EXE = RbConfig::CONFIG["EXEEXT"]
|
|
781
|
-
|
|
782
|
-
# The server program: +server+ if it's a path (a / or, on Windows, a
|
|
783
|
-
# \ in it), or the one by that name on +path+; nil if there's none.
|
|
784
|
-
# Either may end with +exe+ too (on Windows, .exe: mysqld.exe, for
|
|
785
|
-
# mysqld).
|
|
786
|
-
def self.find_server(server, path = ENV.fetch("PATH", ""), exe: EXE)
|
|
787
|
-
files = server.match?(%r{[/\\]}) ? [server] : path.split(File::PATH_SEPARATOR).map { |dir| File.join(dir, server) }
|
|
788
|
-
files.flat_map { |file| [file, "#{file}#{exe}"] }.find { |file| File.executable?(file) }
|
|
789
|
-
end
|
|
790
|
-
|
|
791
797
|
# The options the server's run with, initializing +data+ or not.
|
|
792
798
|
# (They come first: mysqld takes --no-defaults only there.)
|
|
793
799
|
def self.options(data) = ["--no-defaults", "--datadir=#{data}", *OPTIONS]
|
data/sig/duel/mysql.rbs
CHANGED
|
@@ -7,6 +7,10 @@ module Duel
|
|
|
7
7
|
|
|
8
8
|
URL: String
|
|
9
9
|
SOCKET: String
|
|
10
|
+
|
|
11
|
+
# Where libmysqlclient connects when it's given no socket or port.
|
|
12
|
+
UNIX_PORT: String
|
|
13
|
+
TCP_PORT: String
|
|
10
14
|
DATABASE: String
|
|
11
15
|
USER: String
|
|
12
16
|
|
|
@@ -42,12 +46,12 @@ module Duel
|
|
|
42
46
|
type row = Array[untyped]
|
|
43
47
|
|
|
44
48
|
# Configures Duel for the plugin (c.use :mysql): the server (+server+
|
|
45
|
-
# the program, +
|
|
46
|
-
# database runs when it's started, +env+ the variables besides
|
|
49
|
+
# the program, +settings+ more of its system variables, +sql+ what each
|
|
50
|
+
# worker's database runs when it's started, +env+ the variables besides
|
|
47
51
|
# DUEL_MYSQL_URL given its URL, +scheme+ the URL's, +tcp+ on a port
|
|
48
52
|
# of 127.0.0.1's: by default on Windows) and its metrics. Returns the
|
|
49
53
|
# plugin's own connection to it, a worker's.
|
|
50
|
-
def self.configure: (Config config, ?server: String, ?
|
|
54
|
+
def self.configure: (Config config, ?server: String, ?settings: Hash[String | Symbol, String | Integer], ?sql: String?, ?env: Array[String],
|
|
51
55
|
?scheme: String, ?tcp: bool) -> InWorker[Connection]
|
|
52
56
|
|
|
53
57
|
# The most memory a worker's server takes.
|
|
@@ -257,6 +261,9 @@ module Duel
|
|
|
257
261
|
# +text+ as a string literal.
|
|
258
262
|
def quote: (String text) -> String
|
|
259
263
|
|
|
264
|
+
# +texts+ as a list of string literals, for IN (...).
|
|
265
|
+
def quote_all: (Array[String] texts) -> String
|
|
266
|
+
|
|
260
267
|
# Closes it without telling the server (no QUIT); true.
|
|
261
268
|
def close: () -> bool
|
|
262
269
|
|
|
@@ -296,15 +303,9 @@ module Duel
|
|
|
296
303
|
|
|
297
304
|
# A worker's data directory: a copy of one initialized once.
|
|
298
305
|
class DataDir
|
|
299
|
-
EXE: String
|
|
300
|
-
|
|
301
306
|
@resource: Resource
|
|
302
307
|
@server: String
|
|
303
308
|
|
|
304
|
-
# The server program: +server+ if it's a path, or the one by that
|
|
305
|
-
# name on +path+ (either may end with +exe+ too); nil if there's none.
|
|
306
|
-
def self.find_server: (String server, ?String path, ?exe: String) -> String?
|
|
307
|
-
|
|
308
309
|
# The options the server's run with, initializing a data directory
|
|
309
310
|
# or not.
|
|
310
311
|
def self.options: (String data) -> Array[String]
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: duel-mysql
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Erik Berlin
|
|
@@ -16,7 +16,7 @@ dependencies:
|
|
|
16
16
|
-
|
|
17
17
|
- ~>
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 0.3.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -24,7 +24,7 @@ dependencies:
|
|
|
24
24
|
-
|
|
25
25
|
- ~>
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 0.3.0
|
|
28
28
|
description: "A Duel plugin: each worker gets a MySQL server of its own, and every benchmark is judged on the statements it sent, the rows they read and their time too."
|
|
29
29
|
email:
|
|
30
30
|
- sferik@gmail.com
|