duel-memcached 0.1.7 → 0.2.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: ad8bed2168381bdcd21549a4db93a762fb2061fe5295750489f9344a889f17a3
4
- data.tar.gz: 38d7d58ed0f42e98065d2fd02935c2f376ea4d0887fd71b2b7175621a9063ce0
3
+ metadata.gz: 2d9e1b7247b20136bad2746f274600f4008625eb657f36356bea149596d12760
4
+ data.tar.gz: 50b03080f96bea9b09bd6f27c3f5070f8b7160a7b33e9378ac0ed64ff9ea91d8
5
5
  SHA512:
6
- metadata.gz: 981f7a36e9dc1481a012f10b4a3d6597f7eb3b06f5c7db8a3751ef23d8947ff59f5ab64e006010e3b07fad64e44e03084f35fa0559a0abd85e9805eef54a7f51
7
- data.tar.gz: 7766c57a7e443b927466e8132b8771ae70867b4d50163f8612f41a3ea0c1bb3f601536b6c8bbd9530fbca3e1a91a80e8573d01f3e9f0dc5a18f7801388f42ae7
6
+ metadata.gz: 159c60fba77f9657fc64a70892fa1038ac19599a2e0403cfa05236ac143516b061b77b0e63a2fb40efe161a2623c7b0ae1b6d851b2b659af42b1762fd3d22724
7
+ data.tar.gz: c7f7f71269263f3129618c32ffda0e6671d8cba7bee5910ca97569786baba8ea9292efce302ca3674e66b2ed9bac0b5bb713180ec09342bb191f083fb29eae8f
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.0] - 2026-11-16
11
+
12
+ ### Added
13
+
14
+ - `tcp: true` starts each worker's server on a port of 127.0.0.1's
15
+ alone, its server `127.0.0.1:PORT`, rather than a Unix socket: the
16
+ default on Windows, whose builds of memcached have no Unix socket.
17
+
18
+ ## [0.1.8] - 2026-11-12
19
+
20
+ No changes of its own: released in step with the other Duel gems.
21
+
10
22
  ## [0.1.7] - 2026-11-10
11
23
 
12
24
  No changes of its own: released in step with the other Duel gems.
@@ -76,7 +88,9 @@ the MIT license. It needs Ruby 3.4 or later, Duel 0.1, and `memcached`
76
88
  `Duel::Memcached.sum` takes that reply.
77
89
 
78
90
 
79
- [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.7...HEAD
91
+ [Unreleased]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.2.0...HEAD
92
+ [0.2.0]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.8...duel-memcached-v0.2.0
93
+ [0.1.8]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.7...duel-memcached-v0.1.8
80
94
  [0.1.7]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.6...duel-memcached-v0.1.7
81
95
  [0.1.6]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.5...duel-memcached-v0.1.6
82
96
  [0.1.5]: https://github.com/sferik/duel-ruby/compare/duel-memcached-v0.1.4...duel-memcached-v0.1.5
data/README.md CHANGED
@@ -45,7 +45,10 @@ Duel.configure { |c| c.use :memcached }
45
45
  ```
46
46
 
47
47
  Each worker's server listens only on a Unix socket in the worker's own
48
- directory, with 32 MB of memory and one thread. The socket's path is in
48
+ directory (or with `tcp: true`, on a port of 127.0.0.1's alone, as it
49
+ does by default on Windows, whose builds of memcached have no Unix
50
+ socket), with 32 MB of memory and one thread. The socket's path (or
51
+ `127.0.0.1:PORT`) is in
49
52
  `DUEL_MEMCACHED_SERVERS`, and in `MEMCACHE_SERVERS` too, so a client that
50
53
  reads that (Dalli does) finds it and nothing reaches another memcached.
51
54
  Benchmarks can call `Duel::Memcached.servers` and
@@ -75,7 +78,8 @@ c.use :memcached,
75
78
  server: "/opt/memcached/bin/memcached", # the program (default: DUEL_MEMCACHED_SERVER, or memcached)
76
79
  args: ["-m", "256"], # more of its options (they win)
77
80
  env: %w[CACHE_SERVERS], # variables given its socket besides DUEL_MEMCACHED_SERVERS (default: MEMCACHE_SERVERS)
78
- cpu: true # judge memcached_cpu too
81
+ cpu: true, # judge memcached_cpu too
82
+ tcp: true # on a port of 127.0.0.1's, its server 127.0.0.1:PORT (default: on Windows only)
79
83
  ```
80
84
 
81
85
  The metrics come from the server's `stats`, read over a connection of
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Duel
4
4
  module Memcached
5
- VERSION = "0.1.7"
5
+ VERSION = "0.2.0"
6
6
  end
7
7
  end
@@ -23,9 +23,11 @@ module Duel
23
23
  # Duel::Memcached.flush in setup (or untimed blocks): while a benchmark
24
24
  # is measured, it fails.
25
25
  #
26
- # The server listens only on a Unix socket in the worker's directory,
27
- # with one thread (so its statistics are up to date when they're read);
28
- # the socket's path is in DUEL_MEMCACHED_SERVERS, and in
26
+ # The server listens only on a Unix socket in the worker's directory
27
+ # (or with +tcp+, on a port of 127.0.0.1's alone: by default on Windows,
28
+ # whose builds of memcached have no Unix socket), with one thread (so
29
+ # its statistics are up to date when they're read); the socket's path
30
+ # (or 127.0.0.1:PORT) is in DUEL_MEMCACHED_SERVERS, and in
29
31
  # MEMCACHE_SERVERS too (unless +env+ names others), so a client that
30
32
  # reads that (Dalli does) finds it.
31
33
  module Memcached
@@ -38,12 +40,20 @@ module Duel
38
40
  # metrics, memcached_cpu too with +cpu+. Returns the plugin's own
39
41
  # connection to it, a worker's (see Config#in_worker, and in tests,
40
42
  # Duel::Testing.in_worker).
41
- def self.configure(config, server: ENV.fetch("DUEL_MEMCACHED_SERVER", "memcached"), args: [], env: %w[MEMCACHE_SERVERS], cpu: false)
43
+ def self.configure(config, server: ENV.fetch("DUEL_MEMCACHED_SERVER", "memcached"), args: [], env: %w[MEMCACHE_SERVERS], cpu: false,
44
+ tcp: !Duel.unix_sockets?)
42
45
  config.prepare(:worker) do |w|
43
- socket = w.path("memcached.sock")
44
- w.spawn(*[server, "-s", socket, "-m", "32", "-t", "1"] + args)
45
- w.wait_until { Connection.ready?(socket) }
46
- ([SERVERS] + env).to_h { |name| [name, socket] }
46
+ if tcp
47
+ port = w.port
48
+ listen = ["-l", "127.0.0.1", "-p", port.to_s]
49
+ address = "127.0.0.1:#{port}"
50
+ else
51
+ address = w.path("memcached.sock")
52
+ listen = ["-s", address]
53
+ end
54
+ w.spawn(*[server, *listen, "-m", "32", "-t", "1"] + args)
55
+ w.wait_until { Connection.ready?(address) }
56
+ ([SERVERS] + env).to_h { |name| [name, address] }
47
57
  end
48
58
  connection = config.in_worker { |w| Connection.new(servers).tap { |memcached| w.at_stop { memcached.close } } }
49
59
  config.metric(METRICS) { stats(connection.value) }.costly
@@ -117,7 +127,8 @@ module Duel
117
127
  value
118
128
  end
119
129
 
120
- # For benchmarks: the worker's server (its socket's path).
130
+ # For benchmarks: the worker's server (its socket's path, or
131
+ # 127.0.0.1:PORT).
121
132
  def self.servers = ENV.fetch(SERVERS)
122
133
 
123
134
  # Empties it, over a connection of its own (opened and closed: a Unix
@@ -147,20 +158,40 @@ module Duel
147
158
  # The most read at a time: a whole stats reply (some 2.5KB) at once.
148
159
  READ = 65_536
149
160
 
150
- def self.ready?(path)
151
- socket = UNIXSocket.new(path)
161
+ # A socket to the server at +server+: a Unix socket's path, or
162
+ # HOST:PORT, without TCP's delay before a small write (a command),
163
+ # whose reply would wait for it.
164
+ def self.socket(server)
165
+ address = address(server)
166
+ return UNIXSocket.new(server) unless address
167
+
168
+ host, port = address
169
+ # (RBS's setsockopt takes an Integer for the value, but Ruby's
170
+ # takes true too.)
171
+ TCPSocket.new(host, port).tap { |socket| socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true) } # steep:ignore ArgumentTypeMismatch
172
+ end
173
+
174
+ # The host and port of a HOST:PORT server, or nil (a Unix socket's
175
+ # path).
176
+ def self.address(server)
177
+ match = %r{\A([^:/]+):(\d+)\z}.match(server) or return
178
+ [match[1], Integer(match[2])]
179
+ end
180
+
181
+ def self.ready?(server)
182
+ connection = socket(server)
152
183
  begin
153
- socket.write("version\r\n")
154
- socket.gets.to_s.start_with?("VERSION ")
184
+ connection.write("version\r\n")
185
+ connection.gets.to_s.start_with?("VERSION ")
155
186
  ensure
156
- socket.close
187
+ connection.close
157
188
  end
158
- rescue SystemCallError, IOError # (JRuby's refusal is an IOError)
189
+ rescue SystemCallError, IOError # (JRuby's refusal on a Unix socket is an IOError)
159
190
  false
160
191
  end
161
192
 
162
- def initialize(path)
163
- @socket = UNIXSocket.new(path)
193
+ def initialize(server)
194
+ @socket = Connection.socket(server)
164
195
  @sent = @received = @own = 0
165
196
  @reply = +""
166
197
  @chunk = +""
@@ -23,9 +23,10 @@ module Duel
23
23
  # Configures Duel for the plugin (c.use :memcached): the server
24
24
  # (+server+ is the program, +args+ more of its options, +env+ the
25
25
  # variables besides DUEL_MEMCACHED_SERVERS given its socket's path)
26
- # and its metrics, memcached_cpu too with +cpu+. Returns the plugin's
26
+ # and its metrics, memcached_cpu too with +cpu+, on a port of
27
+ # 127.0.0.1's with +tcp+ (by default on Windows). Returns the plugin's
27
28
  # own connection to it, a worker's.
28
- def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String], ?cpu: bool) -> InWorker[Connection]
29
+ def self.configure: (Config config, ?server: String, ?args: Array[String], ?env: Array[String], ?cpu: bool, ?tcp: bool) -> InWorker[Connection]
29
30
 
30
31
  # What the worker's server has done so far (but memcached_cpu), read
31
32
  # over +connection+ (the plugin's own). It allocates only its Hash.
@@ -50,7 +51,7 @@ module Duel
50
51
 
51
52
  # The least a connection needs to read a server's statistics.
52
53
  class Connection
53
- @socket: UNIXSocket
54
+ @socket: UNIXSocket | TCPSocket
54
55
  @sent: Integer
55
56
  @received: Integer
56
57
  @reply: String
@@ -62,9 +63,16 @@ module Duel
62
63
  # The most read at a time.
63
64
  READ: Integer
64
65
 
65
- def self.ready?: (String path) -> bool
66
+ # A socket to the server at +server+ (a Unix socket's path, or
67
+ # HOST:PORT).
68
+ def self.socket: (String server) -> (UNIXSocket | TCPSocket)
66
69
 
67
- def initialize: (String path) -> void
70
+ # The host and port of a HOST:PORT server, or nil.
71
+ def self.address: (String server) -> [String, Integer]?
72
+
73
+ def self.ready?: (String server) -> bool
74
+
75
+ def initialize: (String server) -> void
68
76
 
69
77
  # The server's statistics, by name.
70
78
  def stats: () -> Hash[String, String]
metadata CHANGED
@@ -1,65 +1,68 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duel-memcached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.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 memcached server of its own, and every
27
- benchmark is judged on the memcached operations, misses and bytes 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.2"
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.2"
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."
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/memcached.rb
38
- - lib/duel/memcached/version.rb
39
- - sig/duel/memcached.rbs
40
- homepage: https://github.com/sferik/duel-ruby/tree/main/plugins/memcached
35
+ - CHANGELOG.md
36
+ - LICENSE
37
+ - README.md
38
+ - lib/duel/memcached.rb
39
+ - lib/duel/memcached/version.rb
40
+ - sig/duel/memcached.rbs
41
+ homepage: "https://github.com/sferik/duel-ruby/tree/main/plugins/memcached"
41
42
  licenses:
42
- - MIT
43
+ - MIT
43
44
  metadata:
44
- source_code_uri: https://github.com/sferik/duel-ruby/tree/main/plugins/memcached
45
- changelog_uri: https://github.com/sferik/duel-ruby/blob/main/plugins/memcached/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/memcached"
46
+ changelog_uri: "https://github.com/sferik/duel-ruby/blob/main/plugins/memcached/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 memcached server for each Duel worker, and what it did for each benchmark
67
+ summary: "A memcached server for each Duel worker, and what it did for each benchmark"
65
68
  test_files: []