polyphony 1.4 → 1.6
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/.rubocop.yml +3 -0
- data/CHANGELOG.md +22 -0
- data/TODO.md +5 -14
- data/examples/pipes/http_server.rb +42 -12
- data/examples/pipes/http_server2.rb +45 -0
- data/ext/polyphony/backend_common.h +5 -0
- data/ext/polyphony/backend_io_uring.c +174 -121
- data/ext/polyphony/backend_io_uring_context.c +24 -18
- data/ext/polyphony/backend_io_uring_context.h +4 -2
- data/ext/polyphony/backend_libev.c +46 -22
- data/ext/polyphony/event.c +21 -0
- data/ext/polyphony/extconf.rb +25 -19
- data/ext/polyphony/fiber.c +0 -2
- data/ext/polyphony/pipe.c +1 -1
- data/ext/polyphony/polyphony.c +2 -20
- data/ext/polyphony/polyphony.h +5 -5
- data/ext/polyphony/ring_buffer.c +1 -0
- data/ext/polyphony/runqueue_ring_buffer.c +1 -0
- data/ext/polyphony/thread.c +63 -0
- data/ext/polyphony/win_uio.h +18 -0
- data/lib/polyphony/adapters/open3.rb +190 -0
- data/lib/polyphony/core/sync.rb +83 -13
- data/lib/polyphony/core/timer.rb +7 -25
- data/lib/polyphony/extensions/exception.rb +15 -0
- data/lib/polyphony/extensions/fiber.rb +14 -13
- data/lib/polyphony/extensions/io.rb +56 -14
- data/lib/polyphony/extensions/kernel.rb +1 -1
- data/lib/polyphony/extensions/object.rb +1 -13
- data/lib/polyphony/extensions/process.rb +76 -1
- data/lib/polyphony/extensions/socket.rb +0 -14
- data/lib/polyphony/extensions/thread.rb +19 -27
- data/lib/polyphony/extensions/timeout.rb +5 -1
- data/lib/polyphony/version.rb +1 -1
- data/lib/polyphony.rb +11 -5
- data/test/helper.rb +46 -4
- data/test/open3/envutil.rb +380 -0
- data/test/open3/find_executable.rb +24 -0
- data/test/stress.rb +11 -7
- data/test/test_backend.rb +11 -4
- data/test/test_event.rb +10 -3
- data/test/test_ext.rb +16 -1
- data/test/test_fiber.rb +16 -4
- data/test/test_global_api.rb +17 -16
- data/test/test_io.rb +39 -0
- data/test/test_kernel.rb +2 -2
- data/test/test_monitor.rb +356 -0
- data/test/test_open3.rb +338 -0
- data/test/test_signal.rb +5 -1
- data/test/test_socket.rb +6 -98
- data/test/test_sync.rb +46 -0
- data/test/test_thread.rb +10 -1
- data/test/test_thread_pool.rb +5 -0
- data/test/test_throttler.rb +1 -1
- data/test/test_timer.rb +8 -2
- data/test/test_trace.rb +2 -0
- data/vendor/liburing/.github/workflows/build.yml +8 -0
- data/vendor/liburing/.gitignore +1 -0
- data/vendor/liburing/CHANGELOG +8 -0
- data/vendor/liburing/configure +17 -25
- data/vendor/liburing/debian/liburing-dev.manpages +2 -0
- data/vendor/liburing/debian/rules +2 -1
- data/vendor/liburing/examples/Makefile +2 -1
- data/vendor/liburing/examples/io_uring-udp.c +11 -3
- data/vendor/liburing/examples/rsrc-update-bench.c +100 -0
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/make-debs.sh +4 -2
- data/vendor/liburing/src/Makefile +5 -5
- data/vendor/liburing/src/arch/aarch64/lib.h +1 -1
- data/vendor/liburing/src/include/liburing/io_uring.h +41 -16
- data/vendor/liburing/src/include/liburing.h +86 -11
- data/vendor/liburing/src/int_flags.h +1 -0
- data/vendor/liburing/src/liburing-ffi.map +12 -0
- data/vendor/liburing/src/liburing.map +8 -0
- data/vendor/liburing/src/register.c +7 -2
- data/vendor/liburing/src/setup.c +373 -81
- data/vendor/liburing/test/232c93d07b74.c +3 -3
- data/vendor/liburing/test/Makefile +10 -3
- data/vendor/liburing/test/accept.c +2 -1
- data/vendor/liburing/test/buf-ring.c +35 -75
- data/vendor/liburing/test/connect-rep.c +204 -0
- data/vendor/liburing/test/coredump.c +59 -0
- data/vendor/liburing/test/fallocate.c +9 -0
- data/vendor/liburing/test/fd-pass.c +34 -3
- data/vendor/liburing/test/file-verify.c +27 -6
- data/vendor/liburing/test/helpers.c +3 -1
- data/vendor/liburing/test/io_uring_register.c +25 -28
- data/vendor/liburing/test/io_uring_setup.c +1 -1
- data/vendor/liburing/test/poll-cancel-all.c +29 -5
- data/vendor/liburing/test/poll-race-mshot.c +6 -22
- data/vendor/liburing/test/read-write.c +53 -0
- data/vendor/liburing/test/recv-msgall.c +21 -23
- data/vendor/liburing/test/reg-fd-only.c +55 -0
- data/vendor/liburing/test/reg-hint.c +56 -0
- data/vendor/liburing/test/regbuf-merge.c +91 -0
- data/vendor/liburing/test/ringbuf-read.c +2 -10
- data/vendor/liburing/test/send_recvmsg.c +5 -16
- data/vendor/liburing/test/shutdown.c +2 -1
- data/vendor/liburing/test/socket-io-cmd.c +215 -0
- data/vendor/liburing/test/socket-rw-eagain.c +2 -1
- data/vendor/liburing/test/socket-rw-offset.c +2 -1
- data/vendor/liburing/test/socket-rw.c +2 -1
- data/vendor/liburing/test/timeout.c +276 -0
- data/vendor/liburing/test/xattr.c +38 -25
- metadata +20 -7
- data/vendor/liburing/test/timeout-overflow.c +0 -204
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9bed700ffe759bddcee9727be8e3c11d194f45fe44f05a0a879c92c7b221c6c5
|
4
|
+
data.tar.gz: 0f864fa278709cb00c6b2fae7e3725ef581b05f2b111661a7b5a8d4be1696346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e94ad30b3e9392f8afc0ae85a22afbe6ee6ab4b60c6fa1c412ab6d571d51ebec6e7bf8280106f6d0d7ad6c479dd8b6d748f4aed70b8dc2791f16a1d650fd7667
|
7
|
+
data.tar.gz: 2d8a3f5f2b9dd4d5107dedba344d5e4c46efc43546878779918997e3cb81c9087428e4872e70a631169a0b9d2ff3f1b8b745aa3668817a30475f921106b117e9
|
data/.rubocop.yml
CHANGED
@@ -81,6 +81,8 @@ Metrics/MethodLength:
|
|
81
81
|
Exclude:
|
82
82
|
- lib/polyphony/extensions/io.rb
|
83
83
|
- lib/polyphony/extensions/fiber.rb
|
84
|
+
- lib/polyphony/extensions/thread.rb
|
85
|
+
- lib/polyphony/adapters/open3.rb
|
84
86
|
- test/**/*.rb
|
85
87
|
- examples/**/*.rb
|
86
88
|
|
@@ -94,6 +96,7 @@ Metrics/ClassLength:
|
|
94
96
|
- lib/polyphony/extensions/io.rb
|
95
97
|
- lib/polyphony/extensions/fiber.rb
|
96
98
|
- lib/polyphony/extensions/object.rb
|
99
|
+
- lib/polyphony/extensions/thread.rb
|
97
100
|
- test/**/*.rb
|
98
101
|
- examples/**/*.rb
|
99
102
|
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 1.6 2023-08-05
|
2
|
+
|
3
|
+
- Refactor exception instantiation
|
4
|
+
- Fix race condition in `Thread#join`
|
5
|
+
- Fix race condition in `Event` class
|
6
|
+
- Add support for open3 API
|
7
|
+
- Update liburing to version 2.4
|
8
|
+
- Various fixes to `IO` instance methods
|
9
|
+
- Fix `IO#double_splice` on non-Linux OSes
|
10
|
+
- Implement `IO.copy_stream`
|
11
|
+
- Add `Fiber#value` as alias to `Fiber#await`
|
12
|
+
- Implement fiber-aware `Monitor` class (#113)
|
13
|
+
- Implement Thread#value
|
14
|
+
|
15
|
+
## 1.5 2023-07-28
|
16
|
+
|
17
|
+
- Refactor backend_await in io_uring backend
|
18
|
+
- Fix calling `Timeout.timeout` with `nil` or `0` (#114)
|
19
|
+
- Rework support for io_uring multishot accept
|
20
|
+
- Combine SQE submission and waiting for CQE into a single syscall
|
21
|
+
- Use io_uring for closing a `Polyphony::Pipe`, removing call to `close()`
|
22
|
+
|
1
23
|
## 1.4 2023-07-01
|
2
24
|
|
3
25
|
- Implement concurrent `IO#close`
|
data/TODO.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
- Look at RPC benchmark more closely: is there a way to reduce the overhead of
|
2
|
-
the `backend_base_switch_fiber` function?
|
3
|
-
|
4
1
|
- io_uring backend:
|
5
2
|
- if `io_uring_get_sqe` returns null, call `io_uring_submit`, (snooze fiber)?
|
6
3
|
and try again
|
7
4
|
|
5
|
+
- closing and shutdown:
|
6
|
+
- `Pipe_free()` - can we use the backend to close the pipe fds?
|
7
|
+
- Implement `BasicSocket#shutdown`, add `Backend_shutdown` API.
|
8
|
+
|
8
9
|
- Tracing:
|
9
10
|
- Emit events on I/O ops, e.g.:
|
10
11
|
- [:op_read_submit, id, io, len]
|
@@ -19,18 +20,8 @@
|
|
19
20
|
- More tight loops
|
20
21
|
- `IO#gets_loop`, `Socket#gets_loop`, `OpenSSL::Socket#gets_loop` (medium effort)
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
## Roadmap for Polyphony 1.1
|
25
|
-
|
26
|
-
- io_uring
|
27
|
-
- Use playground.c to find out why we when submitting and waiting for
|
28
|
-
completion in single syscall signals seem to be blocked until the syscall
|
29
|
-
returns. Is this a bug in io_uring/liburing?
|
30
|
-
|
31
|
-
-----------------------------------------------------
|
23
|
+
## Roadmap for Polyphony 2
|
32
24
|
|
33
|
-
- allow backend selection at runtime?
|
34
25
|
- Debugging
|
35
26
|
- Eat your own dogfood: need a good tool to check what's going on when some
|
36
27
|
test fails
|
@@ -4,33 +4,63 @@ require 'bundler/inline'
|
|
4
4
|
|
5
5
|
gemfile do
|
6
6
|
source 'https://rubygems.org'
|
7
|
-
gem 'h1p'
|
8
|
-
gem 'polyphony', path: '.'
|
7
|
+
gem 'h1p', path: '../h1p'
|
8
|
+
# gem 'polyphony', path: '.'
|
9
9
|
end
|
10
10
|
|
11
|
-
require 'polyphony'
|
11
|
+
# require 'polyphony'
|
12
12
|
require 'h1p'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
module ::Kernel
|
15
|
+
def trace(*args)
|
16
|
+
STDOUT << format_trace(args)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def format_trace(args)
|
20
|
+
if args.first.is_a?(String)
|
21
|
+
if args.size > 1
|
22
|
+
format("%s: %p\n", args.shift, args)
|
23
|
+
else
|
24
|
+
format("%s\n", args.first)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
format("%p\n", args.size == 1 ? args.first : args)
|
28
|
+
end
|
29
|
+
end
|
21
30
|
|
22
|
-
|
31
|
+
def monotonic_clock
|
32
|
+
::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
33
|
+
end
|
34
|
+
end
|
23
35
|
|
36
|
+
def handle_client(conn)
|
37
|
+
Thread.new do
|
38
|
+
reader = proc do |len, buf, buf_pos|
|
39
|
+
trace(len:, buf:, buf_pos:)
|
40
|
+
s = conn.readpartial(len)
|
41
|
+
buf ? (buf << s) : +s
|
42
|
+
rescue EOFError
|
43
|
+
nil
|
44
|
+
end
|
45
|
+
parser = H1P::Parser.new(reader, :server)
|
46
|
+
# parser = H1P::Parser.new(conn, :server)
|
47
|
+
while (headers = parser.parse_headers)
|
48
|
+
parser.read_body unless parser.complete?
|
24
49
|
conn << "HTTP/1.1 200 OK\r\nContent-Length: 14\r\n\r\nHello, world!\n"
|
25
50
|
end
|
26
|
-
rescue Errno::ECONNRESET
|
51
|
+
rescue Errno::ECONNRESET, Errno::EPIPE
|
27
52
|
# ignore
|
28
53
|
rescue H1P::Error
|
29
54
|
puts 'Got invalid request, closing connection...'
|
30
55
|
ensure
|
56
|
+
parser = nil
|
31
57
|
conn.close rescue nil
|
32
58
|
end
|
33
59
|
end
|
34
60
|
|
35
61
|
puts "Serving HTTP on port 1234..."
|
36
|
-
TCPServer.new('0.0.0.0', 1234)
|
62
|
+
s = TCPServer.new('0.0.0.0', 1234)
|
63
|
+
while true
|
64
|
+
c = s.accept
|
65
|
+
handle_client(c)
|
66
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/inline'
|
4
|
+
|
5
|
+
gemfile do
|
6
|
+
source 'https://rubygems.org'
|
7
|
+
gem 'http_parser.rb'
|
8
|
+
gem 'polyphony', path: '.'
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'polyphony'
|
12
|
+
require 'http_parser.rb'
|
13
|
+
|
14
|
+
def handle_client(conn)
|
15
|
+
spin do
|
16
|
+
parser = Http::Parser.new
|
17
|
+
done = false
|
18
|
+
headers = nil
|
19
|
+
parser.on_headers_complete = proc do |h|
|
20
|
+
headers = h
|
21
|
+
headers[':method'] = parser.http_method
|
22
|
+
headers[':path'] = parser.request_url
|
23
|
+
end
|
24
|
+
parser.on_message_complete = proc { done = true }
|
25
|
+
|
26
|
+
while true # assuming persistent connection
|
27
|
+
conn.read_loop do |msg|
|
28
|
+
parser << msg
|
29
|
+
break if done
|
30
|
+
end
|
31
|
+
|
32
|
+
conn << "HTTP/1.1 200 OK\r\nContent-Length: 14\r\n\r\nHello, world!\n"
|
33
|
+
done = false
|
34
|
+
headers = nil
|
35
|
+
end
|
36
|
+
rescue Errno::ECONNRESET, Errno::EPIPE
|
37
|
+
# ignore
|
38
|
+
ensure
|
39
|
+
parser = nil
|
40
|
+
conn.close rescue nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "Serving HTTP on port 1234..."
|
45
|
+
TCPServer.new('0.0.0.0', 1234).accept_loop { |c| handle_client(c) }
|
@@ -2,9 +2,14 @@
|
|
2
2
|
#define BACKEND_COMMON_H
|
3
3
|
|
4
4
|
#include <sys/types.h>
|
5
|
+
#ifdef POLYPHONY_WINDOWS
|
6
|
+
#include <winsock2.h>
|
7
|
+
#else
|
5
8
|
#include <arpa/inet.h>
|
6
9
|
#include <netinet/in.h>
|
7
10
|
#include <netdb.h>
|
11
|
+
#include <sys/socket.h>
|
12
|
+
#endif
|
8
13
|
|
9
14
|
#include "ruby.h"
|
10
15
|
#include "ruby/io.h"
|