duel-redis 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d76de3bfdeda533e73e809a0ea72f4d1fbd57057de54235f1608d0cc139b2b0
4
- data.tar.gz: 70518ca16c1ce0832d4f9d09538ce3d64fcec7ac8f36b0f007f945eb98e61051
3
+ metadata.gz: 9606b74c616673883b586ee4c096ce110f94445c100f2c6424b427f4d564c180
4
+ data.tar.gz: 24f8da4b28337f3f052b11a0e670248ad1488ca654812b2274f042fb15e721a0
5
5
  SHA512:
6
- metadata.gz: c5104bbaa0634bfa797df55cd01c817d3238cc73689f9f9a5eea7d9b4fdf98003ec0d648180728e01253311f2f5ad93aa1b359450f6b4b597aa161a77932a5d0
7
- data.tar.gz: 2b1f9110e428afae36778b84ccabcb810feed7d8487d4bb2a0f0cb8b8aee108c63cc88688586ff71004d1a1f8c18968712aef8a7072a85903ba07d93c0b9238d
6
+ metadata.gz: fb04e8ad719a5f6a53a4493fb1726e2ecc8e00ab58c1027054f988b6558bd98e2fda321d113ad63c1ca5bed49e1f4c34fb4d422093bddac9598f8977301d3cfc
7
+ data.tar.gz: 3dcecccd76c73783531e1c0d8a3d2ef112889e8a95b5c3d29116d0bbde232e4723ec676218a565c77ce03edd2c8642ad494fd9fa98d894cdb7542afae3f240f5
data/CHANGELOG.md CHANGED
@@ -7,6 +7,31 @@ 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
+ ### Changed
13
+
14
+ - `redis_cpu` is left out of Duel's across-the-board check
15
+ (`across: false`), as duel-mysql's and duel-postgresql's server time
16
+ is: it's the server's time on the clock, another process's, so what
17
+ else the machine does shows in it, too much for that check's margin.
18
+ It's still judged on each benchmark.
19
+ - `server:` is found by `Duel.find_program`, as every Duel plugin's
20
+ is: a path (`~` expanded) as it is, or a name on the `PATH`. With
21
+ none, the error says so (`no redis-server on the PATH (give
22
+ redis-server's path as server:, or DUEL_REDIS_SERVER)`), as
23
+ duel-mysql's and duel-postgresql's do, where it was Ruby's
24
+ `Errno::ENOENT`.
25
+ - `settings:` gives each worker's server more of its configuration's
26
+ directives, as a Hash (`settings: {maxmemory: "64mb"}`, passed as
27
+ `--maxmemory 64mb`), in place of `args:`, a list of its options, as
28
+ duel-postgresql's and duel-mysql's `settings:` do. They come last, so
29
+ they win over the plugin's own.
30
+ - `Duel::Redis.flush` is `Duel::Redis.reset`, as MySQL's and
31
+ PostgreSQL's plugins name what empties a worker's server.
32
+ - It requires Duel 0.3.0 or later (`~> 0.3.0`), the release it's
33
+ tested with, as Duel 0.3.0 changes what plugins and benchmarks call.
34
+
10
35
  ## [0.2.0] - 2026-11-16
11
36
 
12
37
  ### Added
@@ -93,7 +118,8 @@ license. It needs Ruby 3.4 or later, Duel 0.1, and `redis-server`
93
118
  read the next reply out of step.
94
119
 
95
120
 
96
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.2.0...HEAD
121
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.3.0...HEAD
122
+ [0.3.0]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.2.0...duel-redis-v0.3.0
97
123
  [0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.8...duel-redis-v0.2.0
98
124
  [0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.7...duel-redis-v0.1.8
99
125
  [0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.6...duel-redis-v0.1.7
data/README.md CHANGED
@@ -27,7 +27,8 @@ end
27
27
  ```
28
28
 
29
29
  > [!NOTE]
30
- > It needs `redis-server` (Redis 6.2 or later, or Valkey) on the `PATH`.
30
+ > It needs `redis-server` (Redis 6.2 or later, or Valkey) on the `PATH`,
31
+ > or its path as `server:`.
31
32
 
32
33
  ## Usage
33
34
 
@@ -41,14 +42,14 @@ directory (or with `tcp: true`, on a port of 127.0.0.1's alone, as it
41
42
  does by default on Windows, whose builds of Redis have Unix sockets
42
43
  Windows's Ruby can't reach), with persistence off, and works in that
43
44
  directory too
44
- (`--dir`): if your `args:` turn persistence on, its snapshots and
45
+ (`--dir`): if your `settings:` turn persistence on, its snapshots and
45
46
  append-only files go there, never in your project. Its URL is in
46
47
  `DUEL_REDIS_URL`, and in `REDIS_URL` too, so a client that reads that
47
48
  finds it and nothing reaches another Redis. Benchmarks can call
48
- `Duel::Redis.url` and `Duel::Redis.flush`.
49
+ `Duel::Redis.url` and `Duel::Redis.reset`.
49
50
 
50
51
  > [!IMPORTANT]
51
- > `Duel::Redis.flush` is for setting up: call it in a `setup` hook, or
52
+ > `Duel::Redis.reset` is for setting up: call it in a `setup` hook, or
52
53
  > a `once` or `untimed` block. While a benchmark is measured (`Duel.measuring?`), it
53
54
  > raises `Duel::Error` rather than have its `FLUSHALL` counted.
54
55
 
@@ -56,7 +57,7 @@ finds it and nothing reaches another Redis. Benchmarks can call
56
57
  # duel/cache_duel.rb
57
58
  duel "cache: a hit" do
58
59
  once do
59
- Duel::Redis.flush # empties the worker's server (over a connection of its own)
60
+ Duel::Redis.reset # empties the worker's server (over a connection of its own)
60
61
  @cache = MyCache.new(url: Duel::Redis.url) # its URL
61
62
  @cache.write("k", "v")
62
63
  end
@@ -69,7 +70,7 @@ Options:
69
70
  ```ruby
70
71
  c.use :redis,
71
72
  server: "valkey-server", # the program (default: DUEL_REDIS_SERVER, or redis-server)
72
- args: ["--maxmemory", "64mb"], # more of its options
73
+ settings: {maxmemory: "64mb"}, # more of its directives, as --maxmemory 64mb (they win)
73
74
  env: %w[CACHE_URL], # variables given its URL besides DUEL_REDIS_URL (default: REDIS_URL)
74
75
  tcp: true # on a port of 127.0.0.1's, its URL redis://127.0.0.1:PORT (default: on Windows only)
75
76
  ```
@@ -82,3 +83,13 @@ too (`connection.value`, in a worker only). Each reading is a command and a
82
83
  reply itself, so Duel learns what readings add, and takes it away. Reports
83
84
  count them: `redis_commands 4→6`, `redis_round_trips: 1 round trip → 2
84
85
  round trips an iteration`.
86
+
87
+ `redis_cpu` is the server's time on the clock (Redis times each command
88
+ so, though it calls it CPU time), and another process's, so what else
89
+ the machine does shows in it: it's judged for each benchmark, but left
90
+ out of Duel's across-the-board check (`across: false`), whose margin is
91
+ a quarter of its limit.
92
+
93
+ Like any measure, each can be tuned or left out in `.duel.rb`:
94
+ `c.measure("redis_cpu", limit: 1.1)`,
95
+ `c.measure("redis_round_trips", skip: true)`.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Redis
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/lib/duel/redis.rb CHANGED
@@ -16,7 +16,8 @@ module Duel
16
16
  # # .duel.rb
17
17
  # Duel.configure { |c| c.use :redis }
18
18
  #
19
- # Benchmarks can call Duel::Redis.url and Duel::Redis.flush.
19
+ # Benchmarks can call Duel::Redis.url, and Duel::Redis.reset in setup
20
+ # (or untimed blocks): while a benchmark is measured, it fails.
20
21
  #
21
22
  # The server listens only on a Unix socket in the worker's directory
22
23
  # (or with +tcp+, on a port of 127.0.0.1's alone: by default on Windows,
@@ -35,22 +36,28 @@ module Duel
35
36
  OPTIONS = ["--port", "0", "--save", "", "--appendonly", "no"].freeze
36
37
 
37
38
  # Configures Duel for the plugin (c.use :redis): the server
38
- # (+server+ is the program, +args+ more of its options) and its
39
+ # (+server+ is the program, +settings+ more of its configuration's
40
+ # directives: maxmemory: "64mb", as --maxmemory 64mb) and its
39
41
  # metrics. Returns the plugin's own connection to it, a worker's
40
42
  # (see Config#in_worker, and in tests, Duel::Testing.in_worker).
41
- def self.configure(config, server: ENV.fetch("DUEL_REDIS_SERVER", "redis-server"), args: [], env: %w[REDIS_URL],
43
+ def self.configure(config, server: ENV.fetch("DUEL_REDIS_SERVER", "redis-server"), settings: {}, env: %w[REDIS_URL],
42
44
  tcp: !Duel.unix_sockets?)
43
45
  config.prepare(:worker) do |w|
46
+ program = Duel.find_program(server) ||
47
+ w.fail!("no #{server}#{" on the PATH" unless Duel.path?(server)} (give redis-server's path as server:, or DUEL_REDIS_SERVER)")
44
48
  if tcp
45
- # (Its port after OPTIONS' 0, which it takes the place of.)
46
- port = w.port
47
- w.spawn(*[server, "--dir", w.dir, *OPTIONS, "--port", port.to_s, "--bind", "127.0.0.1"] + args)
49
+ port = w.free_port
50
+ listen = ["--port", port.to_s, "--bind", "127.0.0.1"]
48
51
  url = "redis://127.0.0.1:#{port}"
49
52
  else
50
53
  socket = w.path("redis.sock")
51
- w.spawn(*[server, "--unixsocket", socket, "--dir", w.dir, *OPTIONS] + args)
54
+ listen = ["--unixsocket", socket]
52
55
  url = "unix://#{socket}"
53
56
  end
57
+ # (Where it listens after OPTIONS, whose port of 0 a port takes the
58
+ # place of, and +settings+ last: of a directive given twice, the
59
+ # server takes the last.)
60
+ w.spawn(program, "--dir", w.dir, *OPTIONS, *listen, *settings.flat_map { |name, value| ["--#{name}", value.to_s] })
54
61
  w.wait_until { Connection.ping(url) }
55
62
  ([URL] + env).to_h { |name| [name, url] }
56
63
  end
@@ -59,8 +66,13 @@ module Duel
59
66
  connection
60
67
  end
61
68
 
69
+ # redis_cpu is the server's time on the clock (Redis times each
70
+ # command so), and another process's, so what else the machine does
71
+ # shows in it: it's judged on each benchmark, but left out across the
72
+ # board, where the margin is too small for it, as duel-mysql's and
73
+ # duel-postgresql's time are.
62
74
  METRICS = {
63
- "redis_cpu" => {kind: :ratio, unit: "µs", floor: 300},
75
+ "redis_cpu" => {kind: :timed, unit: "µs", floor: 300, across: false},
64
76
  "redis_commands" => {kind: :counted, unit: %w[command commands]},
65
77
  "redis_round_trips" => {kind: :counted, unit: ["round trip", "round trips"]}
66
78
  }
@@ -86,8 +98,8 @@ module Duel
86
98
  # socket's is cheap). For setup or untimed blocks only: while a
87
99
  # benchmark is measured (Duel.measuring?) it fails, as its FLUSHALL
88
100
  # would be counted.
89
- def self.flush
90
- Duel.unmeasured!("Duel::Redis.flush")
101
+ def self.reset
102
+ Duel.unmeasured!("Duel::Redis.reset")
91
103
 
92
104
  connection = Connection.new(url)
93
105
  begin
@@ -152,7 +164,12 @@ module Duel
152
164
  # closes the connection, as the rest of it can't be read, and raises
153
165
  # IOError.
154
166
  def call(*args)
155
- @socket.write(args.map(&:to_s).reduce("*#{args.size}\r\n") { |out, arg| out << "$#{arg.bytesize}\r\n#{arg}\r\n" })
167
+ command = "*#{args.size}\r\n"
168
+ args.each do |arg|
169
+ arg = arg.to_s
170
+ command << "$#{arg.bytesize}\r\n#{arg}\r\n"
171
+ end
172
+ @socket.write(command)
156
173
  reply = read
157
174
  raise reply if reply.is_a?(Exception)
158
175
 
data/sig/duel/redis.rbs CHANGED
@@ -12,12 +12,12 @@ module Duel
12
12
  METRICS: Hash[String, Metric::settings]
13
13
 
14
14
  # Configures Duel for the plugin (c.use :redis): the server (+server+
15
- # is the program, +args+ more of its options, +env+ the variables
15
+ # is the program, +settings+ more of its directives, +env+ the variables
16
16
  # besides DUEL_REDIS_URL given its URL) and its metrics. Returns the
17
17
  # plugin's own connection to it, a worker's.
18
18
  # +tcp+: on a port of 127.0.0.1's, not a Unix socket (by default on
19
19
  # Windows).
20
- def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String], ?tcp: bool) -> InWorker[Connection]
20
+ def self.configure: (Config config, ?server: String, ?settings: Hash[String | Symbol, String | Integer], ?env: Array[String], ?tcp: bool) -> InWorker[Connection]
21
21
 
22
22
  # What the worker's server has done so far, read over +connection+.
23
23
  def self.stats: (Connection connection) -> Hash[String, Integer]
@@ -27,7 +27,7 @@ module Duel
27
27
 
28
28
  # Empties it, over a connection of its own: in setup or untimed blocks
29
29
  # only (it fails while a benchmark is measured).
30
- def self.flush: () -> String
30
+ def self.reset: () -> String
31
31
 
32
32
  # The least a connection needs to read a server's statistics.
33
33
  class Connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.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: "0.2"
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: "0.2"
27
+ version: 0.3.0
28
28
  description: "A Duel plugin: each worker gets a Redis server of its own, and every benchmark is judged on the Redis CPU time, commands and round trips it took too."
29
29
  email:
30
30
  - sferik@gmail.com