omq-rfc-zstd 0.1.1 → 0.1.2
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/lib/omq/rfc/zstd/compression.rb +7 -1
- data/lib/omq/rfc/zstd/connection.rb +30 -5
- data/lib/omq/rfc/zstd/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 141f24afe8fac939ca1518c76d62bc45d8d15d456fa415be3c8dc5343af33447
|
|
4
|
+
data.tar.gz: 2e16e4ce5413d0b181e2b293d8b9b5203133bb114527726936c466464754e8dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d181d5b3e6c463537599491667287603479d3928b9d2f4991e7c4e48b1ded8e15a730e3a825a059cdf384ded81b5f83e094093d9424341126e103ab3049a3723
|
|
7
|
+
data.tar.gz: efd7e9cb3caa37d11ed5cdb6ec374f3f85efd32ce2cfc0525552840d9dce92a0460302e8a315d73ae4b7a5bf34ce597296cf1f60a2d0083e750887635bf633f6
|
|
@@ -199,9 +199,15 @@ module OMQ
|
|
|
199
199
|
return if @training_done
|
|
200
200
|
return if plaintext.bytesize >= AUTO_DICT_MAX_SAMPLE_LEN
|
|
201
201
|
|
|
202
|
+
# OMQ's Writable mixin already hands us frozen binary Strings
|
|
203
|
+
# (frozen_binary + parts.freeze), so in the common case we
|
|
204
|
+
# can stash the caller's reference without a `.b` copy. Only
|
|
205
|
+
# coerce when the encoding/frozen invariants don't hold.
|
|
206
|
+
sample = plaintext.frozen? && plaintext.encoding == Encoding::BINARY ? plaintext : plaintext.b
|
|
207
|
+
|
|
202
208
|
@training_mutex.synchronize do
|
|
203
209
|
return if @training_done
|
|
204
|
-
@samples <<
|
|
210
|
+
@samples << sample
|
|
205
211
|
@samples_bytes += plaintext.bytesize
|
|
206
212
|
@samples_count += 1
|
|
207
213
|
maybe_train!
|
|
@@ -52,6 +52,11 @@ module OMQ
|
|
|
52
52
|
@dict_sent = false
|
|
53
53
|
@last_wire_size_out = nil
|
|
54
54
|
@last_wire_size_in = nil
|
|
55
|
+
|
|
56
|
+
# Cached once: is the send side an auto-training compression
|
|
57
|
+
# that still needs samples? Flipped false the moment training
|
|
58
|
+
# completes, so #encode_parts drops the per-message branch.
|
|
59
|
+
@auto_sampling = send_compression.is_a?(Compression) && send_compression.auto?
|
|
55
60
|
end
|
|
56
61
|
|
|
57
62
|
|
|
@@ -65,13 +70,18 @@ module OMQ
|
|
|
65
70
|
attr_reader :last_wire_size_in
|
|
66
71
|
|
|
67
72
|
|
|
68
|
-
#
|
|
73
|
+
# Hides +#write_wire+ from callers so
|
|
74
|
+
# +OMQ::Routing::FanOut+ falls back to per-connection
|
|
75
|
+
# +write_message+ -- see class docs for the rationale.
|
|
69
76
|
def respond_to?(name, include_private = false)
|
|
70
77
|
return false if name == :write_wire
|
|
71
78
|
super
|
|
72
79
|
end
|
|
73
80
|
|
|
74
81
|
|
|
82
|
+
# Compresses +parts+ and forwards the encoded payload through
|
|
83
|
+
# the underlying connection's synchronous send path (acquires
|
|
84
|
+
# the write mutex and flushes).
|
|
75
85
|
def send_message(parts)
|
|
76
86
|
encoded = encode_parts(parts)
|
|
77
87
|
ship_auto_dict_if_ready
|
|
@@ -79,6 +89,9 @@ module OMQ
|
|
|
79
89
|
end
|
|
80
90
|
|
|
81
91
|
|
|
92
|
+
# Compresses +parts+ and forwards to the underlying
|
|
93
|
+
# +#write_message+ (writes to the buffer without flushing --
|
|
94
|
+
# the send pump batches and flushes at the end of the cycle).
|
|
82
95
|
def write_message(parts)
|
|
83
96
|
encoded = encode_parts(parts)
|
|
84
97
|
ship_auto_dict_if_ready
|
|
@@ -86,6 +99,9 @@ module OMQ
|
|
|
86
99
|
end
|
|
87
100
|
|
|
88
101
|
|
|
102
|
+
# Compresses each message in +messages+ and forwards the
|
|
103
|
+
# batch to the underlying +#write_messages+. Used by the
|
|
104
|
+
# send pump's batched-flush path.
|
|
89
105
|
def write_messages(messages)
|
|
90
106
|
encoded = messages.map { |parts| encode_parts(parts) }
|
|
91
107
|
ship_auto_dict_if_ready
|
|
@@ -93,6 +109,9 @@ module OMQ
|
|
|
93
109
|
end
|
|
94
110
|
|
|
95
111
|
|
|
112
|
+
# Reads one message via the underlying connection, intercepts
|
|
113
|
+
# ZMTP-Zstd command frames (e.g. ZDICT) via the frame block,
|
|
114
|
+
# and returns the decoded plaintext parts.
|
|
96
115
|
def receive_message
|
|
97
116
|
parts = super do |frame|
|
|
98
117
|
handle_command_frame(frame)
|
|
@@ -143,11 +162,17 @@ module OMQ
|
|
|
143
162
|
|
|
144
163
|
def encode_parts(parts)
|
|
145
164
|
return parts if @send_compression.nil?
|
|
146
|
-
|
|
147
|
-
|
|
165
|
+
|
|
166
|
+
if @auto_sampling
|
|
167
|
+
if @send_compression.trained?
|
|
168
|
+
@auto_sampling = false
|
|
169
|
+
else
|
|
170
|
+
parts.each { |p| @send_compression.add_sample(p) }
|
|
171
|
+
end
|
|
148
172
|
end
|
|
173
|
+
|
|
149
174
|
encoded = parts.map { |p| Codec.encode_part(p, @send_compression) }
|
|
150
|
-
@last_wire_size_out = encoded.sum
|
|
175
|
+
@last_wire_size_out = encoded.sum { |p| p.bytesize }
|
|
151
176
|
encoded
|
|
152
177
|
end
|
|
153
178
|
|
|
@@ -161,7 +186,7 @@ module OMQ
|
|
|
161
186
|
|
|
162
187
|
def decode_parts(parts)
|
|
163
188
|
return parts if @recv_compression.nil?
|
|
164
|
-
@last_wire_size_in = parts.sum
|
|
189
|
+
@last_wire_size_in = parts.sum { |p| p.bytesize }
|
|
165
190
|
budget_remaining = @max_message_size
|
|
166
191
|
parts.map do |p|
|
|
167
192
|
plaintext = Codec.decode_part(p, @recv_compression, budget_remaining: budget_remaining)
|
data/lib/omq/rfc/zstd/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: omq-rfc-zstd
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrik Wenger
|
|
@@ -15,42 +15,42 @@ dependencies:
|
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version:
|
|
18
|
+
version: 0.19.3
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
23
|
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version:
|
|
25
|
+
version: 0.19.3
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: protocol-zmtp
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - ">="
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '0.
|
|
32
|
+
version: '0.7'
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - ">="
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '0.
|
|
39
|
+
version: '0.7'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: rzstd
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '0.
|
|
46
|
+
version: '0.2'
|
|
47
47
|
type: :runtime
|
|
48
48
|
prerelease: false
|
|
49
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
50
|
requirements:
|
|
51
51
|
- - ">="
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '0.
|
|
53
|
+
version: '0.2'
|
|
54
54
|
description: Negotiated, transparent per-frame Zstd compression with optional shared
|
|
55
55
|
dictionary for the OMQ pure-Ruby ZeroMQ library.
|
|
56
56
|
email:
|