duel-redis 0.1.8 → 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: 45efac2222121eaab68097eb7417f757d7ccd9c15fb0515ae69ae439d875f3ec
4
- data.tar.gz: c3441c2a292cc613babc14506f85d9aadc93bbe227ea650be4a8255920251034
3
+ metadata.gz: 9606b74c616673883b586ee4c096ce110f94445c100f2c6424b427f4d564c180
4
+ data.tar.gz: 24f8da4b28337f3f052b11a0e670248ad1488ca654812b2274f042fb15e721a0
5
5
  SHA512:
6
- metadata.gz: d30322adb4c52f965983d870d6618d75e4f9a18a8002369e2f4e74a1ade0bf1507d19b29d2698e466b448153b7c5a530efcb32d9928aef873be3e3a44641e9cd
7
- data.tar.gz: '09fef03403ebedb023a7f28dcb48e0d8335f8c2484ca1de69182eaac7fa63b133886d712172e0b2dcaf77def6b0e097a889a0e218afc22561941427a4ab44d56'
6
+ metadata.gz: fb04e8ad719a5f6a53a4493fb1726e2ecc8e00ab58c1027054f988b6558bd98e2fda321d113ad63c1ca5bed49e1f4c34fb4d422093bddac9598f8977301d3cfc
7
+ data.tar.gz: 3dcecccd76c73783531e1c0d8a3d2ef112889e8a95b5c3d29116d0bbde232e4723ec676218a565c77ce03edd2c8642ad494fd9fa98d894cdb7542afae3f240f5
data/CHANGELOG.md CHANGED
@@ -7,6 +7,47 @@ 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
+
35
+ ## [0.2.0] - 2026-11-16
36
+
37
+ ### Added
38
+
39
+ - `tcp: true` starts each worker's server on a port of 127.0.0.1's
40
+ alone, its URL `redis://127.0.0.1:PORT`, rather than a Unix socket:
41
+ the default on Windows, whose builds of Redis (Cygwin's, MSYS2's)
42
+ have Unix sockets of their own, which Windows's Ruby can't reach.
43
+
44
+ ### Fixed
45
+
46
+ - On JRuby, a worker that found its server's Unix socket before the
47
+ server listened on it failed, rather than waiting: JRuby's refusal
48
+ there is an `IOError` (CRuby's an `Errno::ECONNREFUSED`), which the
49
+ plugin now takes for a server not ready yet, as duel-memcached does.
50
+
10
51
  ## [0.1.8] - 2026-11-12
11
52
 
12
53
  No changes of its own: released in step with the other Duel gems.
@@ -77,7 +118,9 @@ license. It needs Ruby 3.4 or later, Duel 0.1, and `redis-server`
77
118
  read the next reply out of step.
78
119
 
79
120
 
80
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.8...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
123
+ [0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.8...duel-redis-v0.2.0
81
124
  [0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.7...duel-redis-v0.1.8
82
125
  [0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.6...duel-redis-v0.1.7
83
126
  [0.1.6]: https://github.com/sferik/duel-ruby/compare/duel-redis-v0.1.5...duel-redis-v0.1.6
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
 
@@ -37,15 +38,18 @@ Duel.configure { |c| c.use :redis }
37
38
  ```
38
39
 
39
40
  Each worker's server listens only on a Unix socket in the worker's own
40
- directory, with persistence off, and works in that directory too
41
- (`--dir`): if your `args:` turn persistence on, its snapshots and
41
+ directory (or with `tcp: true`, on a port of 127.0.0.1's alone, as it
42
+ does by default on Windows, whose builds of Redis have Unix sockets
43
+ Windows's Ruby can't reach), with persistence off, and works in that
44
+ directory too
45
+ (`--dir`): if your `settings:` turn persistence on, its snapshots and
42
46
  append-only files go there, never in your project. Its URL is in
43
47
  `DUEL_REDIS_URL`, and in `REDIS_URL` too, so a client that reads that
44
48
  finds it and nothing reaches another Redis. Benchmarks can call
45
- `Duel::Redis.url` and `Duel::Redis.flush`.
49
+ `Duel::Redis.url` and `Duel::Redis.reset`.
46
50
 
47
51
  > [!IMPORTANT]
48
- > `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
49
53
  > a `once` or `untimed` block. While a benchmark is measured (`Duel.measuring?`), it
50
54
  > raises `Duel::Error` rather than have its `FLUSHALL` counted.
51
55
 
@@ -53,7 +57,7 @@ finds it and nothing reaches another Redis. Benchmarks can call
53
57
  # duel/cache_duel.rb
54
58
  duel "cache: a hit" do
55
59
  once do
56
- 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)
57
61
  @cache = MyCache.new(url: Duel::Redis.url) # its URL
58
62
  @cache.write("k", "v")
59
63
  end
@@ -66,8 +70,9 @@ Options:
66
70
  ```ruby
67
71
  c.use :redis,
68
72
  server: "valkey-server", # the program (default: DUEL_REDIS_SERVER, or redis-server)
69
- args: ["--maxmemory", "64mb"], # more of its options
70
- env: %w[CACHE_URL] # variables given its URL besides DUEL_REDIS_URL (default: REDIS_URL)
73
+ settings: {maxmemory: "64mb"}, # more of its directives, as --maxmemory 64mb (they win)
74
+ env: %w[CACHE_URL], # variables given its URL besides DUEL_REDIS_URL (default: REDIS_URL)
75
+ tcp: true # on a port of 127.0.0.1's, its URL redis://127.0.0.1:PORT (default: on Windows only)
71
76
  ```
72
77
 
73
78
  The metrics come from the server's `INFO` (command statistics and
@@ -78,3 +83,13 @@ too (`connection.value`, in a worker only). Each reading is a command and a
78
83
  reply itself, so Duel learns what readings add, and takes it away. Reports
79
84
  count them: `redis_commands 4→6`, `redis_round_trips: 1 round trip → 2
80
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.1.8"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/lib/duel/redis.rb CHANGED
@@ -16,11 +16,15 @@ 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
- # The server listens only on a Unix socket in the worker's directory,
22
- # and works there too (--dir): what its options make it write, a
23
- # snapshot or an append-only file, goes there, never in the project.
22
+ # The server listens only on a Unix socket in the worker's directory
23
+ # (or with +tcp+, on a port of 127.0.0.1's alone: by default on Windows,
24
+ # whose builds of Redis, Cygwin's or MSYS2's, have Unix sockets of their
25
+ # own, which Windows's Ruby can't reach), and works there too (--dir):
26
+ # what its options make it write, a snapshot or an append-only file,
27
+ # goes there, never in the project.
24
28
  # Its URL is in DUEL_REDIS_URL, and in REDIS_URL too (unless +env+
25
29
  # names others), so a client that reads that finds it.
26
30
  module Redis
@@ -32,15 +36,29 @@ module Duel
32
36
  OPTIONS = ["--port", "0", "--save", "", "--appendonly", "no"].freeze
33
37
 
34
38
  # Configures Duel for the plugin (c.use :redis): the server
35
- # (+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
36
41
  # metrics. Returns the plugin's own connection to it, a worker's
37
42
  # (see Config#in_worker, and in tests, Duel::Testing.in_worker).
38
- 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],
44
+ tcp: !Duel.unix_sockets?)
39
45
  config.prepare(:worker) do |w|
40
- socket = w.path("redis.sock")
41
- w.spawn(*[server, "--unixsocket", socket, "--dir", w.dir, *OPTIONS] + args)
42
- w.wait_until { Connection.ping(socket) }
43
- url = "unix://#{socket}"
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)")
48
+ if tcp
49
+ port = w.free_port
50
+ listen = ["--port", port.to_s, "--bind", "127.0.0.1"]
51
+ url = "redis://127.0.0.1:#{port}"
52
+ else
53
+ socket = w.path("redis.sock")
54
+ listen = ["--unixsocket", socket]
55
+ url = "unix://#{socket}"
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] })
61
+ w.wait_until { Connection.ping(url) }
44
62
  ([URL] + env).to_h { |name| [name, url] }
45
63
  end
46
64
  connection = config.in_worker { |w| Connection.new(url).tap { |redis| w.at_stop { redis.close } } }
@@ -48,8 +66,13 @@ module Duel
48
66
  connection
49
67
  end
50
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.
51
74
  METRICS = {
52
- "redis_cpu" => {kind: :ratio, unit: "µs", floor: 300},
75
+ "redis_cpu" => {kind: :timed, unit: "µs", floor: 300, across: false},
53
76
  "redis_commands" => {kind: :counted, unit: %w[command commands]},
54
77
  "redis_round_trips" => {kind: :counted, unit: ["round trip", "round trips"]}
55
78
  }
@@ -75,8 +98,8 @@ module Duel
75
98
  # socket's is cheap). For setup or untimed blocks only: while a
76
99
  # benchmark is measured (Duel.measuring?) it fails, as its FLUSHALL
77
100
  # would be counted.
78
- def self.flush
79
- Duel.unmeasured!("Duel::Redis.flush")
101
+ def self.reset
102
+ Duel.unmeasured!("Duel::Redis.reset")
80
103
 
81
104
  connection = Connection.new(url)
82
105
  begin
@@ -94,20 +117,39 @@ module Duel
94
117
  # The first byte of a reply: its type, one of RESP2's.
95
118
  STATUS, ERROR, INTEGER, BULK, ARRAY = "+-:$*".bytes
96
119
 
97
- def self.ping(path)
98
- socket = UNIXSocket.new(path)
120
+ # A socket to the server at +url+: unix://PATH (or PATH alone), or
121
+ # redis://HOST:PORT, without TCP's delay before a small write (a
122
+ # command), whose reply would wait for it.
123
+ def self.socket(url)
124
+ address = address(url)
125
+ return UNIXSocket.new(url.delete_prefix("unix://")) unless address
126
+
127
+ host, port = address
128
+ # (RBS's setsockopt takes an Integer for the value, but Ruby's
129
+ # takes true too.)
130
+ TCPSocket.new(host, port).tap { |socket| socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) } # steep:ignore ArgumentTypeMismatch
131
+ end
132
+
133
+ # The host and port of a redis:// URL, or nil (a Unix socket's).
134
+ def self.address(url)
135
+ match = %r{\Aredis://([^:/]+):(\d+)\z}.match(url) or return
136
+ [match[1], Integer(match[2])]
137
+ end
138
+
139
+ def self.ping(url)
140
+ connection = socket(url)
99
141
  begin
100
- socket.write("PING\r\n")
101
- socket.gets == "+PONG\r\n"
142
+ connection.write("PING\r\n")
143
+ connection.gets == "+PONG\r\n"
102
144
  ensure
103
- socket.close
145
+ connection.close
104
146
  end
105
- rescue SystemCallError
147
+ rescue SystemCallError, IOError # (JRuby's refusal on a Unix socket is an IOError)
106
148
  false
107
149
  end
108
150
 
109
151
  def initialize(url)
110
- @socket = UNIXSocket.new(url.delete_prefix("unix://"))
152
+ @socket = Connection.socket(url)
111
153
  end
112
154
 
113
155
  # Sends a command; returns its reply, read whole (every type RESP2
@@ -122,7 +164,12 @@ module Duel
122
164
  # closes the connection, as the rest of it can't be read, and raises
123
165
  # IOError.
124
166
  def call(*args)
125
- @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)
126
173
  reply = read
127
174
  raise reply if reply.is_a?(Exception)
128
175
 
data/sig/duel/redis.rbs CHANGED
@@ -12,10 +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
- def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String]) -> InWorker[Connection]
18
+ # +tcp+: on a port of 127.0.0.1's, not a Unix socket (by default on
19
+ # Windows).
20
+ def self.configure: (Config config, ?server: String, ?settings: Hash[String | Symbol, String | Integer], ?env: Array[String], ?tcp: bool) -> InWorker[Connection]
19
21
 
20
22
  # What the worker's server has done so far, read over +connection+.
21
23
  def self.stats: (Connection connection) -> Hash[String, Integer]
@@ -25,7 +27,7 @@ module Duel
25
27
 
26
28
  # Empties it, over a connection of its own: in setup or untimed blocks
27
29
  # only (it fails while a benchmark is measured).
28
- def self.flush: () -> String
30
+ def self.reset: () -> String
29
31
 
30
32
  # The least a connection needs to read a server's statistics.
31
33
  class Connection
@@ -42,9 +44,16 @@ module Duel
42
44
  BULK: Integer
43
45
  ARRAY: Integer
44
46
 
45
- @socket: UNIXSocket
47
+ @socket: UNIXSocket | TCPSocket
46
48
 
47
- def self.ping: (String path) -> bool
49
+ # A socket to the server at +url+ (unix://PATH, PATH, or
50
+ # redis://HOST:PORT).
51
+ def self.socket: (String url) -> (UNIXSocket | TCPSocket)
52
+
53
+ # The host and port of a redis:// URL, or nil.
54
+ def self.address: (String url) -> [String, Integer]?
55
+
56
+ def self.ping: (String url) -> bool
48
57
 
49
58
  def initialize: (String url) -> void
50
59
 
metadata CHANGED
@@ -1,65 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-redis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - Erik Berlin
7
+ - Erik Berlin
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: duel
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - "~>"
17
- - !ruby/object:Gem::Version
18
- version: '0.1'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - "~>"
24
- - !ruby/object:Gem::Version
25
- version: '0.1'
26
- description: 'A Duel plugin: each worker gets a Redis server of its own, and every
27
- benchmark is judged on the Redis CPU time, commands and round trips it took too.'
12
+ - !ruby/object:Gem::Dependency
13
+ name: duel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: 0.3.0
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."
28
29
  email:
29
- - sferik@gmail.com
30
+ - sferik@gmail.com
30
31
  executables: []
31
32
  extensions: []
32
33
  extra_rdoc_files: []
33
34
  files:
34
- - CHANGELOG.md
35
- - LICENSE
36
- - README.md
37
- - lib/duel/redis.rb
38
- - lib/duel/redis/version.rb
39
- - sig/duel/redis.rbs
40
- homepage: https://github.com/sferik/duel-ruby/tree/main/plugins/redis
35
+ - CHANGELOG.md
36
+ - LICENSE
37
+ - README.md
38
+ - lib/duel/redis.rb
39
+ - lib/duel/redis/version.rb
40
+ - sig/duel/redis.rbs
41
+ homepage: "https://github.com/sferik/duel-ruby/tree/main/plugins/redis"
41
42
  licenses:
42
- - MIT
43
+ - MIT
43
44
  metadata:
44
- source_code_uri: https://github.com/sferik/duel-ruby/tree/main/plugins/redis
45
- changelog_uri: https://github.com/sferik/duel-ruby/blob/main/plugins/redis/CHANGELOG.md
46
- bug_tracker_uri: https://github.com/sferik/duel-ruby/issues
47
- rubygems_mfa_required: 'true'
45
+ source_code_uri: "https://github.com/sferik/duel-ruby/tree/main/plugins/redis"
46
+ changelog_uri: "https://github.com/sferik/duel-ruby/blob/main/plugins/redis/CHANGELOG.md"
47
+ bug_tracker_uri: "https://github.com/sferik/duel-ruby/issues"
48
+ rubygems_mfa_required: "true"
48
49
  rdoc_options: []
49
50
  require_paths:
50
- - lib
51
+ - lib
51
52
  required_ruby_version: !ruby/object:Gem::Requirement
52
53
  requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '3.4'
54
+ -
55
+ - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "3.4"
56
58
  required_rubygems_version: !ruby/object:Gem::Requirement
57
59
  requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: '0'
60
+ -
61
+ - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
61
64
  requirements: []
62
- rubygems_version: 4.0.24
65
+ rubygems_version: 4.1.0
63
66
  specification_version: 4
64
- summary: A Redis server for each Duel worker, and what it did for each benchmark
67
+ summary: "A Redis server for each Duel worker, and what it did for each benchmark"
65
68
  test_files: []