omq-ractor 0.1.4 → 0.1.7

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/lib/omq/ractor.rb +24 -17
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82a5648228e78d1c9b2a8f4262f24ac561c7160f72023c8eceff5b97092869a5
4
- data.tar.gz: b6314c18b53f4c0fef2ab27b6a9875def79315e4d4fad1a304463d4aedafaed7
3
+ metadata.gz: 33bdfec66293ba5838114ae557b6ce2f1e99f52e6b930fd8cfad82bf97950827
4
+ data.tar.gz: c7370bc226312e82c3aafba801bfbc29a743c4fbfeb2d8ea028f23ec0b9a6ac9
5
5
  SHA512:
6
- metadata.gz: 2423d2faa42c4fea749eee4e278f0584ad53d19d2f2f578cb949f1a7d5172e501a13290aa9fa9a7b5c6fbbd1633adcf03d375810edc49d45ca1276792fe6a986
7
- data.tar.gz: ea22884ba96d26427eee41b4f7764ef7ec05674d381ab4bb3dabc86bc22d68858268dcc381bf34cd4b465125d3b13739aa211e4cb55ae4e19d6e80e5f2b1f42b
6
+ metadata.gz: 5cbc8e3b3c4c3c712d4da7015e78a0e6a970a2cdeea377a41ceb9c9bcfde5e63aca9dff7320fe6ab1c5d7669f6d2d91b345d357ea183accf9ca1684e892579d6
7
+ data.tar.gz: 4f97b42bc7835c12dc89c47390e4d6b80119db3c7eb0852be9508b8f5e633cb7b3e1e0f85db5d6776088745434591d448a51d0b89eb7b65c6a8fc6696c9bc914
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OMQ::Ractor -- Networked Ractors
2
2
 
3
- [![CI](https://github.com/paddor/omq-ractor/actions/workflows/ci.yml/badge.svg)](https://github.com/paddor/omq-ractor/actions/workflows/ci.yml)
3
+ [![CI](https://github.com/zeromq/omq.rb/actions/workflows/ci.yml/badge.svg)](https://github.com/zeromq/omq.rb/actions/workflows/ci.yml)
4
4
  [![Gem Version](https://img.shields.io/gem/v/omq-ractor?color=e9573f)](https://rubygems.org/gems/omq-ractor)
5
5
  [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE)
6
6
  [![Ruby](https://img.shields.io/badge/Ruby-%3E%3D%204.0-CC342D?logo=ruby&logoColor=white)](https://www.ruby-lang.org)
@@ -119,7 +119,7 @@ end
119
119
  ```
120
120
 
121
121
  Topic prefix matching works normally. The topic stays as a plain string
122
- frame; only the payload is serialized.
122
+ frame. Only the payload is serialized.
123
123
 
124
124
  ### Worker pool
125
125
 
@@ -215,7 +215,7 @@ a Reactor.run round-trip per message.
215
215
  Setup handshake: the worker must call `omq.sockets` as its first
216
216
  action. This creates worker-owned input ports, sends them to the main
217
217
  Ractor, and returns SocketProxy objects. The main Ractor waits up to
218
- 100ms; if the handshake doesn't complete, the Ractor is stopped and
218
+ 100ms. If the handshake doesn't complete, the Ractor is stopped and
219
219
  an error is raised.
220
220
 
221
221
 
data/lib/omq/ractor.rb CHANGED
@@ -31,7 +31,7 @@ module OMQ
31
31
  #
32
32
  class Ractor
33
33
 
34
- HANDSHAKE_TIMEOUT = 5
34
+ HANDSHAKE_TIMEOUT = 1
35
35
 
36
36
 
37
37
  # Socket types that use topic/group-based routing.
@@ -43,7 +43,7 @@ module OMQ
43
43
  # -- Connection wrappers -------------------------------------------
44
44
 
45
45
  # Mixed into all connection wrappers so is_a? checks against
46
- # the wrapped class (e.g. DirectPipe) still work.
46
+ # the wrapped class (e.g. Pipe) still work.
47
47
  #
48
48
  module TransparentDelegator
49
49
  # @param klass [Class] class to check against
@@ -107,6 +107,13 @@ module OMQ
107
107
  end
108
108
 
109
109
 
110
+ # @param batch [Array<Array<String>>] batch of message frames to serialize and write
111
+ # @return [void]
112
+ def write_messages(batch)
113
+ super(batch.map { |parts| [@cache.marshal(parts)] })
114
+ end
115
+
116
+
110
117
  # @return [Object] deserialized message
111
118
  def receive_message
112
119
  Marshal.load(super.first)
@@ -114,7 +121,7 @@ module OMQ
114
121
  end
115
122
 
116
123
 
117
- # Wraps an inproc DirectPipe with Ractor.make_shareable.
124
+ # Wraps an inproc Pipe with Ractor.make_shareable.
118
125
  #
119
126
  class ShareableConnection < SimpleDelegator
120
127
  include TransparentDelegator
@@ -156,6 +163,13 @@ module OMQ
156
163
  end
157
164
 
158
165
 
166
+ # @param batch [Array<Array<String>>] batch of message frames; first frame is topic
167
+ # @return [void]
168
+ def write_messages(batch)
169
+ super(batch.map { |parts| [parts[0], @cache.marshal(parts[1..])] })
170
+ end
171
+
172
+
159
173
  # @return [Array<String>] deserialized message with topic as first element
160
174
  def receive_message
161
175
  parts = super
@@ -511,10 +525,10 @@ module OMQ
511
525
  @sockets.each_with_index do |socket, i|
512
526
  cache = SerializeCache.new
513
527
  topic_type = socket_configs[i][:topic_type]
514
- engine = socket.instance_variable_get(:@engine)
528
+ engine = socket.engine
515
529
 
516
530
  engine.connection_wrapper = ->(conn) do
517
- inproc = conn.is_a?(Transport::Inproc::DirectPipe)
531
+ inproc = conn.is_a?(Transport::Inproc::Pipe)
518
532
  if topic_type
519
533
  inproc ? TopicShareableConnection.new(conn) : TopicMarshalConnection.new(conn, cache)
520
534
  else
@@ -565,11 +579,9 @@ module OMQ
565
579
  port = output_ports[i]
566
580
  next unless port
567
581
 
568
- do_serialize = socket_configs[i][:serialize]
569
- topic_type = socket_configs[i][:topic_type]
570
- engine = socket.instance_variable_get(:@engine)
571
- queue = Thread::Queue.new
572
- rd, wr = IO.pipe
582
+ engine = socket.engine
583
+ queue = Thread::Queue.new
584
+ rd, wr = IO.pipe
573
585
  @output_pipes << rd << wr
574
586
 
575
587
  # Thread: port.receive -> queue + pipe signal
@@ -593,13 +605,8 @@ module OMQ
593
605
  rd.read_nonblock(4096) rescue nil
594
606
 
595
607
  while (msg = queue.pop(true) rescue nil)
596
- if do_serialize
597
- parts = topic_type && msg.is_a?(Array) ? msg : [msg]
598
- engine.enqueue_send(parts)
599
- else
600
- parts = socket.__send__(:freeze_message, msg)
601
- engine.enqueue_send(parts)
602
- end
608
+ parts = msg.is_a?(Array) ? msg : [msg]
609
+ engine.enqueue_send(parts)
603
610
  end
604
611
  rescue IOError, Async::Stop
605
612
  break
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omq-ractor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrik Wenger
@@ -13,16 +13,16 @@ dependencies:
13
13
  name: omq
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0.11'
18
+ version: '0.28'
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: '0.11'
25
+ version: '0.28'
26
26
  email:
27
27
  - paddor@gmail.com
28
28
  executables: []
@@ -33,7 +33,7 @@ files:
33
33
  - README.md
34
34
  - lib/omq-ractor.rb
35
35
  - lib/omq/ractor.rb
36
- homepage: https://github.com/paddor/omq-ractor
36
+ homepage: https://github.com/zeromq/omq.rb/tree/main/gems/omq-ractor
37
37
  licenses:
38
38
  - ISC
39
39
  metadata: {}
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  - !ruby/object:Gem::Version
52
52
  version: '0'
53
53
  requirements: []
54
- rubygems_version: 4.0.6
54
+ rubygems_version: 4.0.16
55
55
  specification_version: 4
56
56
  summary: Bridge OMQ sockets into Ruby Ractors for true parallel processing
57
57
  test_files: []