uringmachine 0.19.1 → 0.20.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 +4 -4
- data/CHANGELOG.md +12 -1
- data/TODO.md +0 -1
- data/examples/bm_fileno.rb +33 -0
- data/examples/bm_mutex.rb +85 -0
- data/examples/bm_mutex_single.rb +33 -0
- data/examples/bm_queue.rb +27 -28
- data/examples/bm_send.rb +2 -5
- data/examples/bm_snooze.rb +20 -42
- data/examples/fiber_scheduler_demo.rb +15 -51
- data/examples/fiber_scheduler_fork.rb +24 -0
- data/examples/nc_ssl.rb +71 -0
- data/ext/um/extconf.rb +5 -15
- data/ext/um/um.c +57 -41
- data/ext/um/um.h +21 -11
- data/ext/um/um_async_op_class.c +2 -2
- data/ext/um/um_buffer.c +1 -1
- data/ext/um/um_class.c +94 -23
- data/ext/um/um_const.c +51 -3
- data/ext/um/um_mutex_class.c +1 -1
- data/ext/um/um_queue_class.c +1 -1
- data/ext/um/um_stream.c +5 -5
- data/ext/um/um_stream_class.c +3 -0
- data/ext/um/um_sync.c +22 -27
- data/ext/um/um_utils.c +59 -19
- data/grant-2025/journal.md +229 -0
- data/grant-2025/tasks.md +66 -0
- data/lib/uringmachine/fiber_scheduler.rb +180 -48
- data/lib/uringmachine/version.rb +1 -1
- data/lib/uringmachine.rb +6 -0
- data/test/test_fiber_scheduler.rb +138 -0
- data/test/test_stream.rb +2 -2
- data/test/test_um.rb +427 -34
- data/vendor/liburing/.github/workflows/ci.yml +94 -1
- data/vendor/liburing/.github/workflows/test_build.c +9 -0
- data/vendor/liburing/configure +27 -0
- data/vendor/liburing/examples/Makefile +6 -0
- data/vendor/liburing/examples/helpers.c +8 -0
- data/vendor/liburing/examples/helpers.h +5 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/src/Makefile +9 -3
- data/vendor/liburing/src/include/liburing/barrier.h +11 -5
- data/vendor/liburing/src/include/liburing/io_uring/query.h +41 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +50 -0
- data/vendor/liburing/src/include/liburing/sanitize.h +16 -4
- data/vendor/liburing/src/include/liburing.h +445 -121
- data/vendor/liburing/src/liburing-ffi.map +15 -0
- data/vendor/liburing/src/liburing.map +8 -0
- data/vendor/liburing/src/sanitize.c +4 -1
- data/vendor/liburing/src/setup.c +7 -4
- data/vendor/liburing/test/232c93d07b74.c +4 -16
- data/vendor/liburing/test/Makefile +15 -1
- data/vendor/liburing/test/accept.c +2 -13
- data/vendor/liburing/test/conn-unreach.c +132 -0
- data/vendor/liburing/test/fd-pass.c +32 -7
- data/vendor/liburing/test/fdinfo.c +39 -12
- data/vendor/liburing/test/fifo-futex-poll.c +114 -0
- data/vendor/liburing/test/fifo-nonblock-read.c +1 -12
- data/vendor/liburing/test/futex.c +1 -1
- data/vendor/liburing/test/helpers.c +99 -2
- data/vendor/liburing/test/helpers.h +9 -0
- data/vendor/liburing/test/io_uring_passthrough.c +6 -12
- data/vendor/liburing/test/mock_file.c +379 -0
- data/vendor/liburing/test/mock_file.h +47 -0
- data/vendor/liburing/test/nop.c +2 -2
- data/vendor/liburing/test/nop32-overflow.c +150 -0
- data/vendor/liburing/test/nop32.c +126 -0
- data/vendor/liburing/test/pipe.c +166 -0
- data/vendor/liburing/test/poll-race-mshot.c +13 -1
- data/vendor/liburing/test/recv-mshot-fair.c +81 -34
- data/vendor/liburing/test/recvsend_bundle.c +1 -1
- data/vendor/liburing/test/resize-rings.c +2 -0
- data/vendor/liburing/test/ring-query.c +322 -0
- data/vendor/liburing/test/ringbuf-loop.c +87 -0
- data/vendor/liburing/test/runtests.sh +2 -2
- data/vendor/liburing/test/send-zerocopy.c +43 -5
- data/vendor/liburing/test/send_recv.c +102 -32
- data/vendor/liburing/test/shutdown.c +2 -12
- data/vendor/liburing/test/socket-nb.c +3 -14
- data/vendor/liburing/test/socket-rw-eagain.c +2 -12
- data/vendor/liburing/test/socket-rw-offset.c +2 -12
- data/vendor/liburing/test/socket-rw.c +2 -12
- data/vendor/liburing/test/sqe-mixed-bad-wrap.c +87 -0
- data/vendor/liburing/test/sqe-mixed-nop.c +82 -0
- data/vendor/liburing/test/sqe-mixed-uring_cmd.c +153 -0
- data/vendor/liburing/test/timestamp.c +56 -19
- data/vendor/liburing/test/vec-regbuf.c +2 -4
- data/vendor/liburing/test/wq-aff.c +7 -0
- metadata +24 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 320cde6219f737bd65911d6b860852e1d706a20d807f68e97a103254d27a6c11
|
|
4
|
+
data.tar.gz: 2a5c40b6121dd4bc25bcfaf0852d56425f398b43660ccb86d883c5f7b2f68dcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6940030d3f45f731c2b2e8a853193c4ef46e815b84848fc6a310605e00bfd10dd633ff952fc324f33dd4748c82d72379ddf7e91c0c0020006cacf1a2a6a83cb
|
|
7
|
+
data.tar.gz: 60d92ed67095e67e7a36f329e5131a853dff9f4afde843c8022de88ee3613e97e6f032479ee3090870f6a00804d3863e70968e78e92a1753ced3f8baf0a11df2
|
data/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
# 0.
|
|
1
|
+
# 0.20.0 2025-11-26
|
|
2
|
+
|
|
3
|
+
- Add `UM.pidfd_open`, `UM.pidfd_send_signal` methods
|
|
4
|
+
- Add `#waitid`, `#waitid_status` methods, remove `#waitpid`
|
|
5
|
+
- Set minimal kernel version to 6.7
|
|
6
|
+
- Add `UM::Error` exception class
|
|
7
|
+
- Add support for `IO::Buffer` in all I/O methods
|
|
8
|
+
- Fix and improve mutex and queue implementations
|
|
9
|
+
- Add UM.debug method
|
|
10
|
+
- Implement Fiber scheduler (WIP)
|
|
11
|
+
|
|
12
|
+
# 0.19.1 2025-11-03
|
|
2
13
|
|
|
3
14
|
- Add `RB_GC_GUARD` in `process_runqueue_op`
|
|
4
15
|
|
data/TODO.md
CHANGED
|
@@ -37,7 +37,6 @@ Some resources:
|
|
|
37
37
|
- https://github.com/socketry/async/blob/main/context/getting-started.md
|
|
38
38
|
- https://github.com/socketry/async/blob/main/context/scheduler.md
|
|
39
39
|
- https://github.com/socketry/async/blob/main/lib/async/scheduler.rb#L28
|
|
40
|
-
-
|
|
41
40
|
|
|
42
41
|
## useful concurrency tools
|
|
43
42
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/inline'
|
|
4
|
+
|
|
5
|
+
gemfile do
|
|
6
|
+
source 'https://rubygems.org'
|
|
7
|
+
gem 'benchmark'
|
|
8
|
+
gem 'benchmark-ips'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
require 'benchmark/ips'
|
|
12
|
+
|
|
13
|
+
r, w = IO.pipe
|
|
14
|
+
|
|
15
|
+
class IO
|
|
16
|
+
def __fd__
|
|
17
|
+
@__fd__ ||= fileno
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
@map = ObjectSpace::WeakMap.new
|
|
22
|
+
|
|
23
|
+
def cached_fileno(r)
|
|
24
|
+
@map[r] ||= r.fileno
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
Benchmark.ips do |x|
|
|
28
|
+
x.report('IO#fileno') { r.fileno }
|
|
29
|
+
x.report('cached_fileno') { cached_fileno(r) }
|
|
30
|
+
x.report('__fd__') { r.__fd__ }
|
|
31
|
+
|
|
32
|
+
x.compare!(order: :baseline)
|
|
33
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/inline'
|
|
4
|
+
|
|
5
|
+
gemfile do
|
|
6
|
+
source 'https://rubygems.org'
|
|
7
|
+
gem 'uringmachine', path: '..'
|
|
8
|
+
gem 'benchmark'
|
|
9
|
+
gem 'benchmark-ips'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'benchmark/ips'
|
|
13
|
+
require 'uringmachine'
|
|
14
|
+
require 'thread'
|
|
15
|
+
|
|
16
|
+
COUNT = 10
|
|
17
|
+
CONCURRENCY = (ENV['CONCURRENCY'] || 4).to_i
|
|
18
|
+
|
|
19
|
+
p(CONCURRENCY: CONCURRENCY)
|
|
20
|
+
|
|
21
|
+
STRING = "foo...bar"
|
|
22
|
+
REGEXP = /foo(.+)bar/
|
|
23
|
+
|
|
24
|
+
def threads_setup
|
|
25
|
+
@threads_mutex = Mutex.new
|
|
26
|
+
@threads_start = Queue.new
|
|
27
|
+
@threads_done = Queue.new
|
|
28
|
+
@threads = CONCURRENCY.times.map {
|
|
29
|
+
Thread.new do
|
|
30
|
+
loop do
|
|
31
|
+
@threads_start.shift
|
|
32
|
+
COUNT.times do
|
|
33
|
+
@threads_mutex.synchronize do
|
|
34
|
+
COUNT.times do
|
|
35
|
+
STRING.match(REGEXP)[1]
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
@threads_done << true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def threads_run
|
|
46
|
+
@threads_start << true
|
|
47
|
+
@threads_done.shift
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def um_setup
|
|
51
|
+
@um_machine = UM.new
|
|
52
|
+
@um_mutex = UM::Mutex.new
|
|
53
|
+
@um_start = UM::Queue.new
|
|
54
|
+
@um_done = UM::Queue.new
|
|
55
|
+
@fibers = CONCURRENCY.times.map {
|
|
56
|
+
@um_machine.spin do
|
|
57
|
+
loop do
|
|
58
|
+
@um_machine.shift(@um_start)
|
|
59
|
+
COUNT.times do
|
|
60
|
+
@um_machine.synchronize(@um_mutex) do
|
|
61
|
+
COUNT.times do
|
|
62
|
+
STRING.match(REGEXP)[1]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
@um_machine.push(@um_done, true)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def um_run
|
|
73
|
+
@um_machine.push(@um_start, true)
|
|
74
|
+
@um_machine.shift(@um_done)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
threads_setup
|
|
78
|
+
um_setup
|
|
79
|
+
|
|
80
|
+
Benchmark.ips do |x|
|
|
81
|
+
x.report("threads") { @threads_run }
|
|
82
|
+
x.report("UM") { @um_run }
|
|
83
|
+
|
|
84
|
+
x.compare!(order: :baseline)
|
|
85
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/inline'
|
|
4
|
+
|
|
5
|
+
gemfile do
|
|
6
|
+
source 'https://rubygems.org'
|
|
7
|
+
gem 'uringmachine', path: '..'
|
|
8
|
+
gem 'benchmark'
|
|
9
|
+
gem 'benchmark-ips'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
require 'benchmark/ips'
|
|
13
|
+
require 'uringmachine'
|
|
14
|
+
require 'thread'
|
|
15
|
+
|
|
16
|
+
def threads_setup
|
|
17
|
+
@threads_mutex = Mutex.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def um_setup
|
|
21
|
+
@um_machine = UM.new
|
|
22
|
+
@um_mutex = UM::Mutex.new
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
threads_setup
|
|
26
|
+
um_setup
|
|
27
|
+
|
|
28
|
+
Benchmark.ips do |x|
|
|
29
|
+
x.report("threads") { @threads_mutex.synchronize { } }
|
|
30
|
+
x.report("UM") { @um_machine.synchronize(@um_mutex) {} }
|
|
31
|
+
|
|
32
|
+
x.compare!(order: :baseline)
|
|
33
|
+
end
|
data/examples/bm_queue.rb
CHANGED
|
@@ -12,17 +12,18 @@ require 'benchmark/ips'
|
|
|
12
12
|
require 'uringmachine'
|
|
13
13
|
|
|
14
14
|
COUNT = 1000
|
|
15
|
-
NUM_PRODUCERS =
|
|
16
|
-
NUM_CONSUMERS =
|
|
15
|
+
NUM_PRODUCERS = 8
|
|
16
|
+
NUM_CONSUMERS = 8
|
|
17
|
+
|
|
18
|
+
@queue = Queue.new
|
|
19
|
+
@done = Queue.new
|
|
17
20
|
|
|
18
21
|
def run_threads
|
|
19
|
-
queue = Queue.new
|
|
20
|
-
done = Queue.new
|
|
21
22
|
|
|
22
23
|
NUM_PRODUCERS.times do
|
|
23
24
|
Thread.new do
|
|
24
|
-
COUNT.times { queue << rand(1000) }
|
|
25
|
-
done << true
|
|
25
|
+
COUNT.times { @queue << rand(1000) }
|
|
26
|
+
@done << true
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
|
|
@@ -30,65 +31,64 @@ def run_threads
|
|
|
30
31
|
NUM_CONSUMERS.times do
|
|
31
32
|
Thread.new do
|
|
32
33
|
loop do
|
|
33
|
-
item = queue.shift
|
|
34
|
+
item = @queue.shift
|
|
34
35
|
break if item.nil?
|
|
35
36
|
|
|
36
37
|
total += item
|
|
37
38
|
end
|
|
38
|
-
done << true
|
|
39
|
+
@done << true
|
|
39
40
|
end
|
|
40
41
|
end
|
|
41
42
|
|
|
42
43
|
# wait for producers
|
|
43
|
-
NUM_PRODUCERS.times { done.shift }
|
|
44
|
+
NUM_PRODUCERS.times { @done.shift }
|
|
44
45
|
|
|
45
46
|
# stop and wait for consumers
|
|
46
47
|
NUM_CONSUMERS.times do
|
|
47
|
-
queue << nil
|
|
48
|
-
done.shift
|
|
48
|
+
@queue << nil
|
|
49
|
+
@done.shift
|
|
49
50
|
end
|
|
50
51
|
|
|
51
52
|
total
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
done = UM::Queue.new
|
|
55
|
+
@machine = UM.new
|
|
56
|
+
@um_queue = UM::Queue.new
|
|
57
|
+
@um_done = UM::Queue.new
|
|
58
58
|
|
|
59
|
+
def run_um
|
|
59
60
|
NUM_PRODUCERS.times do
|
|
60
|
-
machine.spin do
|
|
61
|
-
COUNT.times { machine.push(
|
|
62
|
-
machine.push(
|
|
61
|
+
@machine.spin do
|
|
62
|
+
COUNT.times { @machine.push(@um_queue, rand(1000)) }
|
|
63
|
+
@machine.push(@um_done, true)
|
|
63
64
|
end
|
|
64
65
|
end
|
|
65
66
|
|
|
66
67
|
total = 0
|
|
67
68
|
NUM_CONSUMERS.times do
|
|
68
|
-
machine.spin do
|
|
69
|
+
@machine.spin do
|
|
69
70
|
loop do
|
|
70
|
-
item = machine.shift(
|
|
71
|
+
item = @machine.shift(@um_queue)
|
|
71
72
|
break if item.nil?
|
|
72
73
|
|
|
73
74
|
total += item
|
|
74
75
|
end
|
|
75
|
-
machine.push(
|
|
76
|
+
@machine.push(@um_done, true)
|
|
76
77
|
end
|
|
77
78
|
end
|
|
78
79
|
|
|
79
80
|
# wait for producers
|
|
80
|
-
NUM_PRODUCERS.times { machine.shift(
|
|
81
|
+
NUM_PRODUCERS.times { @machine.shift(@um_done) }
|
|
81
82
|
|
|
82
83
|
# stop and wait for consumers
|
|
83
84
|
NUM_CONSUMERS.times do
|
|
84
|
-
machine.push(
|
|
85
|
-
machine.shift(
|
|
85
|
+
@machine.push(@um_queue, nil)
|
|
86
|
+
@machine.shift(@um_done)
|
|
86
87
|
end
|
|
87
88
|
|
|
88
89
|
total
|
|
89
90
|
end
|
|
90
91
|
|
|
91
|
-
|
|
92
92
|
# puts "running"
|
|
93
93
|
# res = run_threads
|
|
94
94
|
# p threads: res
|
|
@@ -98,14 +98,13 @@ end
|
|
|
98
98
|
# p fibers: res
|
|
99
99
|
# }
|
|
100
100
|
|
|
101
|
-
|
|
102
101
|
# __END__
|
|
103
102
|
|
|
104
103
|
Benchmark.ips do |x|
|
|
105
|
-
x.config(:time =>
|
|
104
|
+
x.config(:time => 10, :warmup => 3)
|
|
106
105
|
|
|
107
106
|
x.report("threads") { run_threads }
|
|
108
107
|
x.report("UM") { run_um }
|
|
109
108
|
|
|
110
|
-
x.compare!
|
|
109
|
+
x.compare!(order: :baseline)
|
|
111
110
|
end
|
data/examples/bm_send.rb
CHANGED
|
@@ -71,10 +71,6 @@ def um_send_bundle
|
|
|
71
71
|
@machine.send_bundle(@server_fd, @bgid, @parts)
|
|
72
72
|
end
|
|
73
73
|
|
|
74
|
-
# um_send_bundle
|
|
75
|
-
# 10.times { @machine.snooze }
|
|
76
|
-
# exit
|
|
77
|
-
|
|
78
74
|
p(STR_COUNT:, STR_SIZE:)
|
|
79
75
|
|
|
80
76
|
Benchmark.ips do |x|
|
|
@@ -82,5 +78,6 @@ Benchmark.ips do |x|
|
|
|
82
78
|
x.report('UM#write') { um_write }
|
|
83
79
|
x.report('UM#send') { um_send }
|
|
84
80
|
x.report('UM#send_bundle') { um_send_bundle }
|
|
85
|
-
|
|
81
|
+
|
|
82
|
+
x.compare!(order: :baseline)
|
|
86
83
|
end
|
data/examples/bm_snooze.rb
CHANGED
|
@@ -15,37 +15,19 @@ ITERATIONS = 1000
|
|
|
15
15
|
|
|
16
16
|
$machine = UringMachine.new
|
|
17
17
|
|
|
18
|
-
def
|
|
18
|
+
def run_snooze_um
|
|
19
19
|
count = 0
|
|
20
|
-
main = Fiber.current
|
|
21
20
|
|
|
22
|
-
f1 =
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
else
|
|
29
|
-
$machine.snooze
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
21
|
+
f1 = $machine.spin {
|
|
22
|
+
ITERATIONS.times { count += 1; $machine.snooze }
|
|
23
|
+
}
|
|
24
|
+
f2 = $machine.spin {
|
|
25
|
+
ITERATIONS.times { count += 1; $machine.snooze }
|
|
26
|
+
}
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
loop do
|
|
36
|
-
count += 1
|
|
37
|
-
if count == ITERATIONS
|
|
38
|
-
$machine.schedule(main, nil)
|
|
39
|
-
break
|
|
40
|
-
else
|
|
41
|
-
$machine.snooze
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
28
|
+
$machine.join(f1, f2)
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
$machine.schedule(f2, nil)
|
|
48
|
-
$machine.yield
|
|
30
|
+
count
|
|
49
31
|
end
|
|
50
32
|
|
|
51
33
|
def run_raw_transfer
|
|
@@ -53,36 +35,32 @@ def run_raw_transfer
|
|
|
53
35
|
main = Fiber.current
|
|
54
36
|
f2 = nil
|
|
55
37
|
f1 = Fiber.new do
|
|
56
|
-
|
|
38
|
+
ITERATIONS.times do
|
|
57
39
|
count += 1
|
|
58
|
-
|
|
59
|
-
main.transfer(nil)
|
|
60
|
-
break
|
|
61
|
-
else
|
|
62
|
-
f2.transfer(nil)
|
|
63
|
-
end
|
|
40
|
+
f2.transfer(nil)
|
|
64
41
|
end
|
|
65
42
|
end
|
|
66
43
|
|
|
67
44
|
f2 = Fiber.new do
|
|
68
|
-
|
|
45
|
+
ITERATIONS.times do
|
|
69
46
|
count += 1
|
|
70
|
-
|
|
71
|
-
main.transfer(nil)
|
|
72
|
-
break
|
|
73
|
-
else
|
|
74
|
-
f1.transfer(nil)
|
|
75
|
-
end
|
|
47
|
+
f1.transfer(nil)
|
|
76
48
|
end
|
|
49
|
+
main.transfer(nil)
|
|
77
50
|
end
|
|
78
51
|
|
|
79
52
|
f1.transfer(nil)
|
|
53
|
+
|
|
54
|
+
count
|
|
80
55
|
end
|
|
81
56
|
|
|
57
|
+
p run_snooze_um: run_snooze_um
|
|
58
|
+
p run_raw_transfer: run_raw_transfer
|
|
59
|
+
|
|
82
60
|
bm = Benchmark.ips do |x|
|
|
83
61
|
x.config(:time => 5, :warmup => 2)
|
|
84
62
|
|
|
85
|
-
x.report("
|
|
63
|
+
x.report("snooze_um") { run_snooze_um }
|
|
86
64
|
x.report("raw transfer") { run_raw_transfer }
|
|
87
65
|
|
|
88
66
|
x.compare!
|
|
@@ -1,71 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
|
|
5
|
+
require 'uringmachine'
|
|
6
|
+
require 'uringmachine/fiber_scheduler'
|
|
5
7
|
require 'net/http'
|
|
6
8
|
|
|
7
|
-
machine = UringMachine.new
|
|
8
|
-
scheduler = UM::FiberScheduler.new(machine)
|
|
9
|
+
$machine = UringMachine.new
|
|
10
|
+
scheduler = UM::FiberScheduler.new($machine)
|
|
9
11
|
Fiber.set_scheduler scheduler
|
|
10
12
|
|
|
11
13
|
i, o = IO.pipe
|
|
12
14
|
|
|
13
15
|
f1 = Fiber.schedule do
|
|
14
|
-
|
|
15
|
-
# o.write 'Hello, world!'
|
|
16
|
-
# o.close
|
|
16
|
+
puts "Hello from fiber 1!!!"
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
f2 = Fiber.schedule do
|
|
20
|
-
|
|
21
|
-
# 10.times do
|
|
22
|
-
# sleep 0.1
|
|
23
|
-
# puts "."
|
|
24
|
-
# end
|
|
20
|
+
puts "Hello from fiber 2!!!"
|
|
25
21
|
end
|
|
26
22
|
|
|
27
|
-
# Fiber.schedule do
|
|
28
|
-
# scheduler.block(:wait)
|
|
29
|
-
# end
|
|
30
|
-
|
|
31
23
|
f3 = Fiber.schedule do
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
# scheduler.p e
|
|
36
|
-
# scheduler.p e.backtrace
|
|
24
|
+
o.write 'hello'
|
|
25
|
+
puts "wrote it!"
|
|
26
|
+
o.close
|
|
37
27
|
end
|
|
38
28
|
|
|
39
29
|
f4 = Fiber.schedule do
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
# tcp.timeout = 10
|
|
43
|
-
# scheduler.p tcp
|
|
44
|
-
# tcp << "GET / HTTP/1.1\r\nHost: noteflakes.com\r\n\r\n"
|
|
45
|
-
# s = tcp.read
|
|
46
|
-
# scheduler.p s: s
|
|
47
|
-
ret = Net::HTTP.get('noteflakes.com', '/ping')
|
|
48
|
-
scheduler.p ret: ret
|
|
49
|
-
rescue => e
|
|
50
|
-
scheduler.p e
|
|
51
|
-
scheduler.p e.backtrace
|
|
30
|
+
str = i.read
|
|
31
|
+
puts "got: #{str}"
|
|
52
32
|
end
|
|
53
33
|
|
|
54
|
-
scheduler.join
|
|
55
|
-
|
|
56
|
-
__END__
|
|
57
|
-
|
|
58
|
-
stdout_fd = STDOUT.fileno
|
|
59
|
-
stdin_fd = STDIN.fileno
|
|
60
|
-
machine.write(stdout_fd, "Hello, world!\n")
|
|
61
|
-
|
|
62
|
-
loop do
|
|
63
|
-
machine.write(stdout_fd, "Say something: ")
|
|
64
|
-
buf = +''
|
|
65
|
-
res = machine.read(stdin_fd, buf, 8192)
|
|
66
|
-
if res > 0
|
|
67
|
-
machine.write(stdout_fd, "You said: #{buf}")
|
|
68
|
-
else
|
|
69
|
-
break
|
|
70
|
-
end
|
|
71
|
-
end
|
|
34
|
+
# scheduler.join
|
|
35
|
+
# Fiber.set_scheduler(nil)
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/setup'
|
|
4
|
+
|
|
5
|
+
require 'uringmachine'
|
|
6
|
+
require 'uringmachine/fiber_scheduler'
|
|
7
|
+
require 'net/http'
|
|
8
|
+
|
|
9
|
+
$machine = UringMachine.new
|
|
10
|
+
scheduler = UM::FiberScheduler.new($machine)
|
|
11
|
+
Fiber.set_scheduler scheduler
|
|
12
|
+
|
|
13
|
+
p parent: Fiber.scheduler
|
|
14
|
+
p Fiber.current
|
|
15
|
+
|
|
16
|
+
pid = fork do
|
|
17
|
+
Fiber.scheduler.post_fork
|
|
18
|
+
Fiber.set_scheduler nil
|
|
19
|
+
p child: Fiber.scheduler
|
|
20
|
+
# Fiber.scheduler.post_fork
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
Process.wait(pid)
|
|
24
|
+
p :done
|
data/examples/nc_ssl.rb
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/uringmachine'
|
|
4
|
+
require 'openssl'
|
|
5
|
+
|
|
6
|
+
HOST = ARGV[0]
|
|
7
|
+
PORT = ARGV[1].to_i
|
|
8
|
+
|
|
9
|
+
machine = UringMachine.new
|
|
10
|
+
|
|
11
|
+
conn_fd = machine.socket(Socket::AF_INET, Socket::SOCK_STREAM, 0, 0);
|
|
12
|
+
machine.connect(conn_fd, HOST, PORT)
|
|
13
|
+
|
|
14
|
+
class FakeIO < File
|
|
15
|
+
def initialize(machine, fd)
|
|
16
|
+
@machine = machine
|
|
17
|
+
@fd = fd
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def nonblock=(x)
|
|
21
|
+
p 'nonblock=': x
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def sync
|
|
25
|
+
p sync: true
|
|
26
|
+
true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def write(buf)
|
|
30
|
+
p write: buf
|
|
31
|
+
@machine.write(fd, buf)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def read(maxlen = 4096, buf = nil)
|
|
35
|
+
p read: [maxlen, buf]
|
|
36
|
+
buf ||= +''
|
|
37
|
+
_res = @machine.read(@fd, buf, maxlen)
|
|
38
|
+
buf
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
conn_io = FakeIO.new(machine, conn_fd)
|
|
43
|
+
|
|
44
|
+
ssl_io = OpenSSL::SSL::SSLSocket.new(conn_io)
|
|
45
|
+
|
|
46
|
+
stdin_fd = STDIN.fileno
|
|
47
|
+
stdout_fd = STDOUT.fileno
|
|
48
|
+
|
|
49
|
+
f_writer = Fiber.new do
|
|
50
|
+
bgidw = machine.setup_buffer_ring(4096, 1024)
|
|
51
|
+
machine.read_each(stdin_fd, bgidw) do |buf|
|
|
52
|
+
ssl_io.write(buf)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
machine.schedule(f_writer, nil)
|
|
56
|
+
|
|
57
|
+
f_reader = Fiber.new do
|
|
58
|
+
buffer = +''
|
|
59
|
+
loop do
|
|
60
|
+
ssl_io.read(4096, buffer)
|
|
61
|
+
break if buffer.empty?
|
|
62
|
+
|
|
63
|
+
machine.write(stdout_fd, buf)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
machine.schedule(f_reader, nil)
|
|
67
|
+
|
|
68
|
+
trap('SIGINT') { exit! }
|
|
69
|
+
loop do
|
|
70
|
+
machine.sleep(60)
|
|
71
|
+
end
|
data/ext/um/extconf.rb
CHANGED
|
@@ -19,19 +19,12 @@ def get_config
|
|
|
19
19
|
version, major_revision, distribution = m[1].to_i, m[2].to_i, m[4]
|
|
20
20
|
|
|
21
21
|
combined_version = version.to_i * 100 + major_revision.to_i
|
|
22
|
-
raise "UringMachine requires kernel version 6.
|
|
22
|
+
raise "UringMachine requires kernel version 6.7 or newer!" if combined_version < 607
|
|
23
23
|
|
|
24
24
|
{
|
|
25
25
|
kernel_version: combined_version,
|
|
26
|
-
submit_all_flag: combined_version >= 518,
|
|
27
|
-
coop_taskrun_flag: combined_version >= 519,
|
|
28
|
-
single_issuer_flag: combined_version >= 600,
|
|
29
26
|
prep_bind: combined_version >= 611,
|
|
30
|
-
prep_listen: combined_version >= 611
|
|
31
|
-
prep_cmd_sock: combined_version >= 607,
|
|
32
|
-
prep_futex: combined_version >= 607,
|
|
33
|
-
prep_waitid: combined_version >= 607,
|
|
34
|
-
prep_read_multishot: combined_version >= 607
|
|
27
|
+
prep_listen: combined_version >= 611
|
|
35
28
|
}
|
|
36
29
|
end
|
|
37
30
|
|
|
@@ -56,15 +49,12 @@ if !find_library('uring', nil, File.join(liburing_path, 'src'))
|
|
|
56
49
|
raise "Couldn't find liburing.a"
|
|
57
50
|
end
|
|
58
51
|
|
|
52
|
+
have_func("rb_process_status_new")
|
|
53
|
+
|
|
59
54
|
$defs << "-DUM_KERNEL_VERSION=#{config[:kernel_version]}"
|
|
60
|
-
$defs << '-DHAVE_IORING_SETUP_SUBMIT_ALL' if config[:submit_all_flag]
|
|
61
|
-
$defs << '-DHAVE_IORING_SETUP_COOP_TASKRUN' if config[:coop_taskrun_flag]
|
|
62
55
|
$defs << '-DHAVE_IO_URING_PREP_BIND' if config[:prep_bind]
|
|
63
56
|
$defs << '-DHAVE_IO_URING_PREP_LISTEN' if config[:prep_listen]
|
|
64
|
-
|
|
65
|
-
$defs << '-DHAVE_IO_URING_PREP_FUTEX' if config[:prep_futex]
|
|
66
|
-
$defs << '-DHAVE_IO_URING_PREP_WAITID' if config[:prep_waitid]
|
|
67
|
-
$defs << '-DHAVE_IO_URING_PREP_READ_MULTISHOT' if config[:prep_read_multishot]
|
|
57
|
+
|
|
68
58
|
$CFLAGS << ' -Wno-pointer-arith'
|
|
69
59
|
|
|
70
60
|
CONFIG['optflags'] << ' -fno-strict-aliasing'
|