duel-memcached 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: 2d9e1b7247b20136bad2746f274600f4008625eb657f36356bea149596d12760
4
- data.tar.gz: 50b03080f96bea9b09bd6f27c3f5070f8b7160a7b33e9378ac0ed64ff9ea91d8
3
+ metadata.gz: ce5dfecc3d5c7d615414b312a878a995063d351cba8f3ce57a504fb8970dbf20
4
+ data.tar.gz: c35166c078cb15f32e855635b20f43d308949bab0d754e9188b9118f0645b92f
5
5
  SHA512:
6
- metadata.gz: 159c60fba77f9657fc64a70892fa1038ac19599a2e0403cfa05236ac143516b061b77b0e63a2fb40efe161a2623c7b0ae1b6d851b2b659af42b1762fd3d22724
7
- data.tar.gz: c7f7f71269263f3129618c32ffda0e6671d8cba7bee5910ca97569786baba8ea9292efce302ca3674e66b2ed9bac0b5bb713180ec09342bb191f083fb29eae8f
6
+ metadata.gz: c4e77fe34bdffaa2be4fb46399bd58838fdbfc9ec510a3ad84311bd0830902ceb5e72deb46689c6048d791adf6efc3f80bb4b113fc14d8363553b0a6dcfb0c55
7
+ data.tar.gz: 8821e8388af3dfc86298af454eab1a9b20fc4f3915fe30627fd60c17585bcb579ef1ef6584250fce18dacc1a53992beaa7ef35f6baa4a09e3367439af555701d
data/CHANGELOG.md CHANGED
@@ -7,6 +7,30 @@ 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
+ - `memcached_bytes`' slack is `per_iteration:`, as Duel 0.3.0 names it,
15
+ in place of `tolerance:`: `c.measure("memcached_bytes",
16
+ per_iteration: 8)`.
17
+ - `server:` is found by `Duel.find_program`, as every Duel plugin's
18
+ is: a path (`~` expanded) as it is, or a name on the `PATH`. With
19
+ none, the error says so (`no memcached on the PATH (give
20
+ memcached's path as server:, or DUEL_MEMCACHED_SERVER)`), as
21
+ duel-mysql's and duel-postgresql's do, where it was Ruby's
22
+ `Errno::ENOENT`.
23
+ - `settings:` gives each worker's server more of its options, by their
24
+ long names, as a Hash (`settings: {"memory-limit": 256}`, passed as
25
+ `--memory-limit=256`, and a flag's value is `true`:
26
+ `"disable-cas": true`), in place of `args:`, a list of them, as
27
+ duel-postgresql's and duel-mysql's `settings:` do. They come last, so
28
+ they win over the plugin's own.
29
+ - `Duel::Memcached.flush` is `Duel::Memcached.reset`, as MySQL's and
30
+ PostgreSQL's plugins name what empties a worker's server.
31
+ - It requires Duel 0.3.0 or later (`~> 0.3.0`), the release it's
32
+ tested with, as Duel 0.3.0 changes what plugins and benchmarks call.
33
+
10
34
  ## [0.2.0] - 2026-11-16
11
35
 
12
36
  ### Added
@@ -88,7 +112,8 @@ the MIT license. It needs Ruby 3.4 or later, Duel 0.1, and `memcached`
88
112
  `Duel::Memcached.sum` takes that reply.
89
113
 
90
114
 
91
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.2.0...HEAD
115
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.3.0...HEAD
116
+ [0.3.0]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.2.0...duel-memcached-v0.3.0
92
117
  [0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.8...duel-memcached-v0.2.0
93
118
  [0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.7...duel-memcached-v0.1.8
94
119
  [0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.6...duel-memcached-v0.1.7
data/README.md CHANGED
@@ -35,7 +35,8 @@ end
35
35
  ```
36
36
 
37
37
  > [!NOTE]
38
- > It needs `memcached` (1.6 or later) on the `PATH`.
38
+ > It needs `memcached` (1.6 or later) on the `PATH`, or its path as
39
+ > `server:`.
39
40
 
40
41
  ## Usage
41
42
 
@@ -52,13 +53,13 @@ socket), with 32 MB of memory and one thread. The socket's path (or
52
53
  `DUEL_MEMCACHED_SERVERS`, and in `MEMCACHE_SERVERS` too, so a client that
53
54
  reads that (Dalli does) finds it and nothing reaches another memcached.
54
55
  Benchmarks can call `Duel::Memcached.servers` and
55
- `Duel::Memcached.flush`:
56
+ `Duel::Memcached.reset`:
56
57
 
57
58
  ```ruby
58
59
  # duel/cache_duel.rb
59
60
  duel "cache: a hit" do
60
61
  once do
61
- Duel::Memcached.flush # empties the worker's server (over a connection of its own)
62
+ Duel::Memcached.reset # empties the worker's server (over a connection of its own)
62
63
  @cache = Dalli::Client.new(Duel::Memcached.servers) # its socket
63
64
  @cache.set("k", "v")
64
65
  end
@@ -67,16 +68,16 @@ end
67
68
  ```
68
69
 
69
70
  > [!IMPORTANT]
70
- > `Duel::Memcached.flush` is for setting up: call it in a `setup` hook,
71
+ > `Duel::Memcached.reset` is for setting up: call it in a `setup` hook,
71
72
  > or a `once` or `untimed` block. While a benchmark is measured (`Duel.measuring?`), it
72
- > raises `Duel::Error` rather than have the flush counted.
73
+ > raises `Duel::Error` rather than have its flush counted.
73
74
 
74
75
  Options:
75
76
 
76
77
  ```ruby
77
78
  c.use :memcached,
78
79
  server: "/opt/memcached/bin/memcached", # the program (default: DUEL_MEMCACHED_SERVER, or memcached)
79
- args: ["-m", "256"], # more of its options (they win)
80
+ settings: {"memory-limit": 256}, # more of its options, as --memory-limit=256 (they win: a flag's true)
80
81
  env: %w[CACHE_SERVERS], # variables given its socket besides DUEL_MEMCACHED_SERVERS (default: MEMCACHE_SERVERS)
81
82
  cpu: true, # judge memcached_cpu too
82
83
  tcp: true # on a port of 127.0.0.1's, its server 127.0.0.1:PORT (default: on Windows only)
@@ -86,7 +87,7 @@ The metrics come from the server's `stats`, read over a connection of
86
87
  the plugin's own, opened as each worker starts (Duel's `c.in_worker`)
87
88
  and closed as it ends. `c.use :memcached` returns it, for a `.duel.rb`
88
89
  that reads the server too (`connection.value`, in a worker only).
89
- `Duel::Memcached.flush` opens a connection of its own, from the worker's
90
+ `Duel::Memcached.reset` opens a connection of its own, from the worker's
90
91
  `DUEL_MEMCACHED_SERVERS`: a flush is an operation, and its bytes count
91
92
  as any client's (so it fails while a benchmark is measured).
92
93
  `memcached_operations` counts keys, not commands: a
@@ -113,6 +114,6 @@ too fine for it).
113
114
  Duel's `c.measure` changes any of their settings, or leaves one out:
114
115
 
115
116
  ```ruby
116
- c.measure("memcached_bytes", tolerance: 8) # values whose length varies more
117
+ c.measure("memcached_bytes", per_iteration: 8) # values whose length varies more
117
118
  c.measure("memcached_misses", skip: true)
118
119
  ```
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Memcached
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -20,7 +20,7 @@ module Duel
20
20
  # Duel.configure { |c| c.use :memcached }
21
21
  #
22
22
  # Benchmarks can call Duel::Memcached.servers, and
23
- # Duel::Memcached.flush in setup (or untimed blocks): while a benchmark
23
+ # Duel::Memcached.reset in setup (or untimed blocks): while a benchmark
24
24
  # is measured, it fails.
25
25
  #
26
26
  # The server listens only on a Unix socket in the worker's directory
@@ -36,22 +36,28 @@ module Duel
36
36
  SERVERS = "DUEL_MEMCACHED_SERVERS"
37
37
 
38
38
  # Configures Duel for the plugin (c.use :memcached): the server
39
- # (+server+ is the program, +args+ more of its options) and its
39
+ # (+server+ is the program, +settings+ more of its options, by their
40
+ # long names: "memory-limit": 256, as --memory-limit=256, and a
41
+ # flag's true: "disable-cas": true, as --disable-cas) and its
40
42
  # metrics, memcached_cpu too with +cpu+. Returns the plugin's own
41
43
  # connection to it, a worker's (see Config#in_worker, and in tests,
42
44
  # Duel::Testing.in_worker).
43
- def self.configure(config, server: ENV.fetch("DUEL_MEMCACHED_SERVER", "memcached"), args: [], env: %w[MEMCACHE_SERVERS], cpu: false,
45
+ def self.configure(config, server: ENV.fetch("DUEL_MEMCACHED_SERVER", "memcached"), settings: {}, env: %w[MEMCACHE_SERVERS], cpu: false,
44
46
  tcp: !Duel.unix_sockets?)
45
47
  config.prepare(:worker) do |w|
48
+ program = Duel.find_program(server) ||
49
+ w.fail!("no #{server}#{" on the PATH" unless Duel.path?(server)} (give memcached's path as server:, or DUEL_MEMCACHED_SERVER)")
46
50
  if tcp
47
- port = w.port
51
+ port = w.free_port
48
52
  listen = ["-l", "127.0.0.1", "-p", port.to_s]
49
53
  address = "127.0.0.1:#{port}"
50
54
  else
51
55
  address = w.path("memcached.sock")
52
56
  listen = ["-s", address]
53
57
  end
54
- w.spawn(*[server, *listen, "-m", "32", "-t", "1"] + args)
58
+ # (+settings+ last: of an option given twice, the server takes the
59
+ # last.)
60
+ w.spawn(program, *listen, "-m", "32", "-t", "1", *settings.map { |name, value| (value == true) ? "--#{name}" : "--#{name}=#{value}" })
55
61
  w.wait_until { Connection.ready?(address) }
56
62
  ([SERVERS] + env).to_h { |name| [name, address] }
57
63
  end
@@ -69,7 +75,7 @@ module Duel
69
75
  # Values the server makes up (CAS ids, say) grow a digit now and
70
76
  # then, and so may the code's own: a byte more an iteration isn't a
71
77
  # regression.
72
- "memcached_bytes" => {kind: :counted, unit: "B", tolerance: 1, calibrate: false}
78
+ "memcached_bytes" => {kind: :counted, unit: "B", per_iteration: 1, calibrate: false}
73
79
  }
74
80
 
75
81
  # memcached_cpu's settings. Its CPU time is the whole process's (its
@@ -77,9 +83,9 @@ module Duel
77
83
  # noisy, so judged only above 300µs, against a limit of its own, not
78
84
  # across the board (where the margin is a quarter of that), and only
79
85
  # when asked for. (A metric of its own: read around every sample, as a
80
- # ratio one is, where the counted ones are read only in counting
86
+ # timed one is, where the counted ones are read only in counting
81
87
  # samples.)
82
- CPU = {kind: :ratio, unit: "µs", floor: 300, limit: 1.05, across: false}
88
+ CPU = {kind: :timed, unit: "µs", floor: 300, limit: 1.05, across: false}
83
89
 
84
90
  # The statistics each is the sum of.
85
91
  OPERATIONS = %w[cmd_get cmd_set cmd_touch cmd_flush delete_hits delete_misses incr_hits incr_misses decr_hits decr_misses].freeze
@@ -135,8 +141,8 @@ module Duel
135
141
  # socket's is cheap). A flush is an operation, and its bytes count as
136
142
  # any client's: so it's for setup or untimed blocks only, and fails
137
143
  # while a benchmark is measured (Duel.measuring?).
138
- def self.flush
139
- Duel.unmeasured!("Duel::Memcached.flush")
144
+ def self.reset
145
+ Duel.unmeasured!("Duel::Memcached.reset")
140
146
 
141
147
  connection = Connection.new(servers)
142
148
  begin
@@ -21,12 +21,12 @@ module Duel
21
21
  NEEDLES: Hash[String, String]
22
22
 
23
23
  # Configures Duel for the plugin (c.use :memcached): the server
24
- # (+server+ is the program, +args+ more of its options, +env+ the
24
+ # (+server+ is the program, +settings+ more of its options, +env+ the
25
25
  # variables besides DUEL_MEMCACHED_SERVERS given its socket's path)
26
26
  # and its metrics, memcached_cpu too with +cpu+, on a port of
27
27
  # 127.0.0.1's with +tcp+ (by default on Windows). Returns the plugin's
28
28
  # own connection to it, a worker's.
29
- def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String], ?cpu: bool, ?tcp: bool) -> InWorker[Connection]
29
+ def self.configure: (Config config, ?server: String, ?settings: Hash[String | Symbol, String | Integer | true], ?env: Array[String], ?cpu: bool, ?tcp: bool) -> InWorker[Connection]
30
30
 
31
31
  # What the worker's server has done so far (but memcached_cpu), read
32
32
  # over +connection+ (the plugin's own). It allocates only its Hash.
@@ -47,7 +47,7 @@ module Duel
47
47
 
48
48
  # Empties it, over a connection of its own: in setup or untimed
49
49
  # blocks only (it fails while a benchmark is measured).
50
- def self.flush: () -> String
50
+ def self.reset: () -> String
51
51
 
52
52
  # The least a connection needs to read a server's statistics.
53
53
  class Connection
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-memcached
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 memcached server of its own, and every benchmark is judged on the memcached operations, misses and bytes it took too."
29
29
  email:
30
30
  - sferik@gmail.com