uringmachine 1.0.7 → 1.0.8
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/CHANGELOG.md +6 -0
- data/README.md +1 -1
- data/TODO.md +67 -0
- data/ext/um/um.h +2 -2
- data/ext/um/um_io.c +1 -1
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +13 -0
- data/test/fixtures/portrait.jpg +0 -0
- data/test/test_io.rb +9 -9
- data/test/test_um.rb +40 -2
- data/uringmachine.gemspec +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf67592c033a0106bdd648ba5ead31df0d9eeea94ddb489466fd033f51d8fa4d
|
|
4
|
+
data.tar.gz: 17d54c7e04ff3d854f087fdaa4072ae2be772f661e62b47397e21a06aa8a0491
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 401116f03c5e8ce75fa1702a01599a50ca60f8329501aeba677728f5742a5cc24724a90dc273afd468ce4e6028c9e3925836190f71951dce39ff70bba1d1c2f8
|
|
7
|
+
data.tar.gz: 944d8b62e828b452b339e97235f010f4f383b0480deee4073db84e1c5db252785498cce46e2c25a56342207064b75869ccea2fd3f15992d809a56b1fe1aca08a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -64,7 +64,7 @@ allow any library that performs I/O using standard-library classes such as `IO`,
|
|
|
64
64
|
To install UringMachine, simply run `gem install uringmachine` or `bundle add
|
|
65
65
|
uringmachine` in your project directory. Note: to use UringMachine, you'll need
|
|
66
66
|
a Linux machine with a minimum Linux kernel version of 6.7. Some features
|
|
67
|
-
require newer kernel versions.
|
|
67
|
+
require newer kernel versions. You'll also need to use Ruby 4.0 or newer.
|
|
68
68
|
|
|
69
69
|
To perform I/O using UringMachine, simply create an instance:
|
|
70
70
|
|
data/TODO.md
CHANGED
|
@@ -1,3 +1,70 @@
|
|
|
1
|
+
## CSP
|
|
2
|
+
|
|
3
|
+
How amenable is UringMachine to CSP-style programming?
|
|
4
|
+
|
|
5
|
+
https://go.dev/talks/2012/concurrency.slide#50
|
|
6
|
+
|
|
7
|
+
also:
|
|
8
|
+
|
|
9
|
+
https://www.youtube.com/watch?v=BcHI3U0FuoY
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
def do_search
|
|
13
|
+
q = UM::Queue.new
|
|
14
|
+
@machine.spin { @machine.push(q, query(web1, web2)) }
|
|
15
|
+
@machine.spin { @machine.push(q, query(img1, img2)) }
|
|
16
|
+
@machine.spin { @machine.push(q, query(vid1, vid2)) }
|
|
17
|
+
results = []
|
|
18
|
+
@machine.timeout(0.08, Timeout::Error) {
|
|
19
|
+
3.times { results << @machine.shift(q) }
|
|
20
|
+
}
|
|
21
|
+
results
|
|
22
|
+
end
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
But maybe we can build an abstraction on top of it:
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
def do_search
|
|
29
|
+
c = UM::Channel.new(@machine)
|
|
30
|
+
@machine.spin { c << query(web1, web2) }
|
|
31
|
+
@machine.spin { c << query(img1, img2) }
|
|
32
|
+
@machine.spin { c << query(vid1, vid2) }
|
|
33
|
+
results = []
|
|
34
|
+
@machine.timeout(0.08, Timeout::Error) {
|
|
35
|
+
3.times { results << c.next }
|
|
36
|
+
}
|
|
37
|
+
results
|
|
38
|
+
end
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Enahance working with queues
|
|
42
|
+
|
|
43
|
+
- Add `#shift_each`
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
machine.shift_each(queue) { |v| ... }
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```ruby
|
|
50
|
+
q1 = UM::Queue.new
|
|
51
|
+
q2 = UM::Queue.new
|
|
52
|
+
|
|
53
|
+
# return value is array containing queue and shifted value
|
|
54
|
+
machine.multi_shift(q1, q2) #=> [q, v]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Add support for shifting from a UM::IO
|
|
58
|
+
|
|
59
|
+
This lets us treat an IO as a channel/queue:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
io = machine.io(fd)
|
|
63
|
+
queue = UM::Queue.new
|
|
64
|
+
|
|
65
|
+
q, v = machine.multi_shift(io, queue)
|
|
66
|
+
```
|
|
67
|
+
|
|
1
68
|
## File copying with IO
|
|
2
69
|
|
|
3
70
|
```ruby
|
data/ext/um/um.h
CHANGED
|
@@ -126,8 +126,8 @@ enum um_io_mode {
|
|
|
126
126
|
|
|
127
127
|
#define BP_BGID 0xF00B
|
|
128
128
|
#define BP_BR_ENTRIES 1024
|
|
129
|
-
#define BP_INITIAL_BUFFER_SIZE (1U <<
|
|
130
|
-
#define BP_INITIAL_COMMIT_LEVEL (BP_INITIAL_BUFFER_SIZE *
|
|
129
|
+
#define BP_INITIAL_BUFFER_SIZE (1U << 16) // 64KB
|
|
130
|
+
#define BP_INITIAL_COMMIT_LEVEL (BP_INITIAL_BUFFER_SIZE * 4) // 256KB
|
|
131
131
|
#define BP_MAX_BUFFER_SIZE (1U << 20) // 1MB
|
|
132
132
|
#define BP_MAX_COMMIT_LEVEL (BP_MAX_BUFFER_SIZE * BP_BR_ENTRIES) // 1GB
|
|
133
133
|
#define BP_AVAIL_BID_BITMAP_WORDS (BP_BR_ENTRIES / 64)
|
data/ext/um/um_io.c
CHANGED
data/lib/uringmachine/version.rb
CHANGED
data/lib/uringmachine.rb
CHANGED
|
@@ -232,6 +232,19 @@ class UringMachine
|
|
|
232
232
|
open(fn, O_RDONLY) { io(it, :file).read(-(1 << 30)) }
|
|
233
233
|
end
|
|
234
234
|
|
|
235
|
+
# call-seq:
|
|
236
|
+
# machine.fd_read(fd) -> data
|
|
237
|
+
# machine.fd_read(fd, mode) -> data
|
|
238
|
+
#
|
|
239
|
+
# Reads from the given fd until EOF and returns the read data, with a maximum length of 1GB.
|
|
240
|
+
#
|
|
241
|
+
# @param fd [Integer] file descriptor
|
|
242
|
+
# @param mode [Symbol] IO mode (:file, :socket, :ssl)
|
|
243
|
+
# @return [String] read data
|
|
244
|
+
def fd_read(fd, mode = :file)
|
|
245
|
+
io(fd, mode).read(-(1 << 30))
|
|
246
|
+
end
|
|
247
|
+
|
|
235
248
|
# Creates, binds and sets up a TCP socket for listening on the given host and
|
|
236
249
|
# port.
|
|
237
250
|
#
|
|
Binary file
|
data/test/test_io.rb
CHANGED
|
@@ -50,7 +50,7 @@ class IOTest < IOBaseTest
|
|
|
50
50
|
|
|
51
51
|
# initial buffer size: 6BKV, initial buffers commited: 16 (256KB)
|
|
52
52
|
# (plus an additional buffer commited after first usage)
|
|
53
|
-
assert_equal [
|
|
53
|
+
assert_equal [4, 0, 256, 16384 * 16, 16384 * 16 - 6], buffer_metrics
|
|
54
54
|
assert_equal 0, machine.metrics[:ops_pending]
|
|
55
55
|
end
|
|
56
56
|
|
|
@@ -72,7 +72,7 @@ class IOTest < IOBaseTest
|
|
|
72
72
|
assert_equal 0, machine.metrics[:ops_pending]
|
|
73
73
|
assert_equal 256, machine.metrics[:segments_free]
|
|
74
74
|
|
|
75
|
-
assert_equal [
|
|
75
|
+
assert_equal [4, 0, 256, 16384 * 16, 16384 * 16 - 6], buffer_metrics
|
|
76
76
|
ensure
|
|
77
77
|
machine.close(rfd) rescue nil
|
|
78
78
|
machine.close(wfd) rescue nil
|
|
@@ -124,8 +124,8 @@ class IOTest < IOBaseTest
|
|
|
124
124
|
|
|
125
125
|
conn.clear
|
|
126
126
|
# numbers may vary with different kernel versions
|
|
127
|
-
assert_in_range
|
|
128
|
-
|
|
127
|
+
assert_in_range 3..8, machine.metrics[:buffers_allocated]
|
|
128
|
+
assert_equal 0, machine.metrics[:buffers_free]
|
|
129
129
|
assert_equal 256, machine.metrics[:segments_free]
|
|
130
130
|
ensure
|
|
131
131
|
machine.terminate(f)
|
|
@@ -140,7 +140,7 @@ class IOTest < IOBaseTest
|
|
|
140
140
|
|
|
141
141
|
assert_equal 'foo', conn.read_line(0)
|
|
142
142
|
|
|
143
|
-
assert_equal [
|
|
143
|
+
assert_equal [4, 0, 255, 16384 * 16, 16384 * 16 - 12], buffer_metrics
|
|
144
144
|
assert_equal 'bar', conn.read_line(0)
|
|
145
145
|
assert_nil conn.read_line(0)
|
|
146
146
|
assert_equal "baz", conn.read(-6)
|
|
@@ -156,11 +156,11 @@ class IOTest < IOBaseTest
|
|
|
156
156
|
machine.close(@wfd)
|
|
157
157
|
|
|
158
158
|
# three segments received
|
|
159
|
-
assert_equal [
|
|
159
|
+
assert_equal [4, 0, 253, 16384 * 16, 16384 * 16 - 13], buffer_metrics
|
|
160
160
|
assert_equal 'bar', conn.read_line(0)
|
|
161
|
-
assert_equal [
|
|
161
|
+
assert_equal [4, 0, 255, 16384 * 16, 16384 * 16 - 13], buffer_metrics
|
|
162
162
|
assert_equal 'baz', conn.read_line(0)
|
|
163
|
-
assert_equal [
|
|
163
|
+
assert_equal [4, 0, 256, 16384 * 16, 16384 * 16 - 13], buffer_metrics
|
|
164
164
|
assert_nil conn.read_line(0)
|
|
165
165
|
end
|
|
166
166
|
|
|
@@ -186,7 +186,7 @@ class IOTest < IOBaseTest
|
|
|
186
186
|
assert_equal 'bizz', conn.read_line(5)
|
|
187
187
|
|
|
188
188
|
assert_nil conn.read_line(8)
|
|
189
|
-
assert_equal [
|
|
189
|
+
assert_equal [4, 0, 256, 16384 * 16, 16384 * 16 - 17], buffer_metrics
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
def test_io_read
|
data/test/test_um.rb
CHANGED
|
@@ -3534,7 +3534,7 @@ class IOMethodTest < UMBaseTest
|
|
|
3534
3534
|
end
|
|
3535
3535
|
end
|
|
3536
3536
|
|
|
3537
|
-
class
|
|
3537
|
+
class ConvenienceMethodsTest < UMBaseTest
|
|
3538
3538
|
def setup
|
|
3539
3539
|
super
|
|
3540
3540
|
@fn = Tempfile.new('uringmachine_test_io_from_file').path
|
|
@@ -3549,6 +3549,44 @@ class FileHelperMethodsTest < UMBaseTest
|
|
|
3549
3549
|
def test_file_read_bad_fn
|
|
3550
3550
|
assert_raises(Errno::ENOENT) { machine.file_read(@fn + '-missing') }
|
|
3551
3551
|
end
|
|
3552
|
+
|
|
3553
|
+
def test_file_read_portrait
|
|
3554
|
+
buf = machine.file_read(File.join(__dir__, 'fixtures/portrait.jpg'))
|
|
3555
|
+
refute_nil buf
|
|
3556
|
+
end
|
|
3557
|
+
|
|
3558
|
+
def test_fd_read
|
|
3559
|
+
r, w = UM.pipe
|
|
3560
|
+
machine.write(w, 'foobar' * 321)
|
|
3561
|
+
machine.close(w)
|
|
3562
|
+
buf = machine.fd_read(r)
|
|
3563
|
+
assert_equal 'foobar' * 321, buf
|
|
3564
|
+
end
|
|
3565
|
+
|
|
3566
|
+
def test_fd_read_socket_mode_non_socket
|
|
3567
|
+
r, w = UM.pipe
|
|
3568
|
+
machine.write(w, 'foobar' * 321)
|
|
3569
|
+
machine.close(w)
|
|
3570
|
+
assert_raises(Errno::ENOTSOCK) { machine.fd_read(r, :socket) }
|
|
3571
|
+
end
|
|
3572
|
+
|
|
3573
|
+
def test_fd_read_socket_mode
|
|
3574
|
+
r, w = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
|
|
3575
|
+
machine.write(w, 'foobar' * 321)
|
|
3576
|
+
machine.close(w)
|
|
3577
|
+
buf = machine.fd_read(r, :socket)
|
|
3578
|
+
assert_equal 'foobar' * 321, buf
|
|
3579
|
+
end
|
|
3580
|
+
|
|
3581
|
+
def test_fd_read_bad_fd
|
|
3582
|
+
r, w = UM.pipe
|
|
3583
|
+
assert_raises(Errno::EBADF) { machine.fd_read(w) }
|
|
3584
|
+
end
|
|
3585
|
+
|
|
3586
|
+
def test_fd_read_bad_mode
|
|
3587
|
+
r, w = UM.pipe
|
|
3588
|
+
assert_raises(UM::Error) { machine.fd_read(r, :foo) }
|
|
3589
|
+
end
|
|
3552
3590
|
end
|
|
3553
3591
|
|
|
3554
3592
|
class TCPHelperMethodsTest < UMBaseTest
|
|
@@ -3609,7 +3647,7 @@ class TCPHelperMethodsTest < UMBaseTest
|
|
|
3609
3647
|
assert_raises(TypeError) { machine.tcp_connect('127.0.0.1', :foo) }
|
|
3610
3648
|
assert_raises(TypeError) { machine.tcp_connect(1234, 5678) }
|
|
3611
3649
|
ensure
|
|
3612
|
-
machine.close(server_fd)
|
|
3650
|
+
machine.close(server_fd) if server_fd
|
|
3613
3651
|
end
|
|
3614
3652
|
end
|
|
3615
3653
|
|
data/uringmachine.gemspec
CHANGED
|
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
|
|
|
18
18
|
s.extra_rdoc_files = `git ls-files -z *.rdoc *.md lib/*.rb lib/**/*.rb ext/um/*.c ext/um/*.h benchmark/*.md benchmark/*.png`.split("\x0")
|
|
19
19
|
s.extensions = ["ext/um/extconf.rb"]
|
|
20
20
|
s.require_paths = ["lib"]
|
|
21
|
-
s.required_ruby_version = '>=
|
|
21
|
+
s.required_ruby_version = '>= 4.0'
|
|
22
22
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: uringmachine
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sharon Rosner
|
|
@@ -145,6 +145,7 @@ files:
|
|
|
145
145
|
- lib/uringmachine/fiber_scheduler.rb
|
|
146
146
|
- lib/uringmachine/version.rb
|
|
147
147
|
- supressions/ruby.supp
|
|
148
|
+
- test/fixtures/portrait.jpg
|
|
148
149
|
- test/helper.rb
|
|
149
150
|
- test/run.rb
|
|
150
151
|
- test/test_actor.rb
|
|
@@ -500,7 +501,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
500
501
|
-
|
|
501
502
|
- ">="
|
|
502
503
|
- !ruby/object:Gem::Version
|
|
503
|
-
version: "
|
|
504
|
+
version: "4.0"
|
|
504
505
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
505
506
|
requirements:
|
|
506
507
|
-
|