polyphony 0.47.2 → 0.48.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +317 -293
- data/Gemfile.lock +1 -1
- data/TODO.md +46 -3
- data/examples/core/supervisor.rb +3 -3
- data/examples/core/worker-thread.rb +3 -4
- data/examples/io/tcp_proxy.rb +32 -0
- data/examples/io/unix_socket.rb +26 -0
- data/examples/performance/line_splitting.rb +34 -0
- data/examples/performance/loop.rb +32 -0
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +6 -0
- data/ext/polyphony/backend_common.h +2 -2
- data/ext/polyphony/backend_io_uring.c +42 -83
- data/ext/polyphony/backend_libev.c +32 -77
- data/ext/polyphony/event.c +1 -1
- data/ext/polyphony/polyphony.c +0 -2
- data/ext/polyphony/polyphony.h +5 -4
- data/ext/polyphony/queue.c +2 -2
- data/ext/polyphony/thread.c +9 -28
- data/lib/polyphony/adapters/postgres.rb +3 -3
- data/lib/polyphony/core/global_api.rb +19 -16
- data/lib/polyphony/core/resource_pool.rb +1 -12
- data/lib/polyphony/core/thread_pool.rb +3 -1
- data/lib/polyphony/core/throttler.rb +1 -1
- data/lib/polyphony/extensions/fiber.rb +34 -8
- data/lib/polyphony/extensions/io.rb +8 -14
- data/lib/polyphony/extensions/openssl.rb +4 -4
- data/lib/polyphony/extensions/socket.rb +68 -16
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +1 -1
- data/test/helper.rb +1 -0
- data/test/test_backend.rb +1 -1
- data/test/test_fiber.rb +64 -0
- data/test/test_global_api.rb +41 -1
- data/test/test_io.rb +26 -0
- data/test/test_resource_pool.rb +0 -21
- data/test/test_signal.rb +18 -0
- data/test/test_socket.rb +27 -2
- data/test/test_supervise.rb +2 -1
- metadata +7 -4
- data/ext/polyphony/backend.h +0 -26
data/test/test_io.rb
CHANGED
@@ -92,6 +92,32 @@ class IOTest < MiniTest::Test
|
|
92
92
|
assert_raises(EOFError) { i.readpartial(1) }
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_gets
|
96
|
+
i, o = IO.pipe
|
97
|
+
|
98
|
+
buf = []
|
99
|
+
f = spin do
|
100
|
+
while (l = i.gets)
|
101
|
+
buf << l
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
snooze
|
106
|
+
assert_equal [], buf
|
107
|
+
|
108
|
+
o << 'fab'
|
109
|
+
snooze
|
110
|
+
assert_equal [], buf
|
111
|
+
|
112
|
+
o << "ulous\n"
|
113
|
+
10.times { snooze }
|
114
|
+
assert_equal ["fabulous\n"], buf
|
115
|
+
|
116
|
+
o.close
|
117
|
+
f.await
|
118
|
+
assert_equal ["fabulous\n"], buf
|
119
|
+
end
|
120
|
+
|
95
121
|
def test_getc
|
96
122
|
i, o = IO.pipe
|
97
123
|
|
data/test/test_resource_pool.rb
CHANGED
@@ -48,27 +48,6 @@ class ResourcePoolTest < MiniTest::Test
|
|
48
48
|
assert_equal 1, pool.size
|
49
49
|
end
|
50
50
|
|
51
|
-
def test_discard_with_block
|
52
|
-
resources = [+'a', +'b', +'c', +'d', +'e', +'f']
|
53
|
-
pool = Polyphony::ResourcePool.new(limit: 4) { resources.shift }
|
54
|
-
|
55
|
-
buffer = []
|
56
|
-
(1..4).each do |i|
|
57
|
-
spin do
|
58
|
-
3.times do
|
59
|
-
pool.acquire { |r| buffer << [i, r]; trace [i]; snooze }
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
2.times { trace [0]; snooze }
|
65
|
-
assert_equal [[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd']], buffer
|
66
|
-
|
67
|
-
pool.discard! { |r| r == 'a' || r == 'c' }
|
68
|
-
2.times { trace [0]; snooze }
|
69
|
-
assert_equal [[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd'], [1, 'b'], [2, 'd'], [3, 'e'], [4, 'f']], buffer
|
70
|
-
end
|
71
|
-
|
72
51
|
def test_single_resource_limit
|
73
52
|
resources = [+'a', +'b']
|
74
53
|
pool = Polyphony::ResourcePool.new(limit: 1) { resources.shift }
|
data/test/test_signal.rb
CHANGED
@@ -76,4 +76,22 @@ class SignalTrapTest < Minitest::Test
|
|
76
76
|
buffer = i.read
|
77
77
|
assert_equal "3-interrupt\n", buffer
|
78
78
|
end
|
79
|
+
|
80
|
+
def test_io_in_signal_handler
|
81
|
+
i, o = IO.pipe
|
82
|
+
pid = Polyphony.fork do
|
83
|
+
trap('INT') { o.puts 'INT'; o.close; exit! }
|
84
|
+
i.close
|
85
|
+
sleep
|
86
|
+
ensure
|
87
|
+
o.close
|
88
|
+
end
|
89
|
+
|
90
|
+
o.close
|
91
|
+
sleep 0.1
|
92
|
+
Process.kill('INT', pid)
|
93
|
+
Thread.current.backend.waitpid(pid)
|
94
|
+
buffer = i.read
|
95
|
+
assert_equal "INT\n", buffer
|
96
|
+
end
|
79
97
|
end
|
data/test/test_socket.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'helper'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
class SocketTest < MiniTest::Test
|
6
7
|
def setup
|
@@ -24,7 +25,32 @@ class SocketTest < MiniTest::Test
|
|
24
25
|
snooze
|
25
26
|
client = TCPSocket.new('127.0.0.1', port)
|
26
27
|
client.write("1234\n")
|
27
|
-
assert_equal "1234\n", client.
|
28
|
+
assert_equal "1234\n", client.recv(8192)
|
29
|
+
client.close
|
30
|
+
ensure
|
31
|
+
server_fiber&.stop
|
32
|
+
server_fiber&.await
|
33
|
+
server&.close
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_unix_socket
|
37
|
+
path = '/tmp/test_unix_socket'
|
38
|
+
FileUtils.rm(path) rescue nil
|
39
|
+
server = UNIXServer.new(path)
|
40
|
+
server_fiber = spin do
|
41
|
+
server.accept_loop do |socket|
|
42
|
+
spin do
|
43
|
+
while (data = socket.gets(8192))
|
44
|
+
socket << data
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
snooze
|
51
|
+
client = UNIXSocket.new(path)
|
52
|
+
client.write("1234\n")
|
53
|
+
assert_equal "1234\n", client.recv(8192)
|
28
54
|
client.close
|
29
55
|
ensure
|
30
56
|
server_fiber&.stop
|
@@ -34,7 +60,6 @@ class SocketTest < MiniTest::Test
|
|
34
60
|
end
|
35
61
|
|
36
62
|
class HTTPClientTest < MiniTest::Test
|
37
|
-
require 'httparty'
|
38
63
|
require 'json'
|
39
64
|
|
40
65
|
def test_http
|
data/test/test_supervise.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.48.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -269,7 +269,7 @@ dependencies:
|
|
269
269
|
- !ruby/object:Gem::Version
|
270
270
|
version: 0.3.0
|
271
271
|
description:
|
272
|
-
email:
|
272
|
+
email: sharon@noteflakes.com
|
273
273
|
executables: []
|
274
274
|
extensions:
|
275
275
|
- ext/polyphony/extconf.rb
|
@@ -383,13 +383,17 @@ files:
|
|
383
383
|
- examples/io/raw.rb
|
384
384
|
- examples/io/reline.rb
|
385
385
|
- examples/io/system.rb
|
386
|
+
- examples/io/tcp_proxy.rb
|
386
387
|
- examples/io/tcpserver.rb
|
387
388
|
- examples/io/tcpsocket.rb
|
388
389
|
- examples/io/tunnel.rb
|
390
|
+
- examples/io/unix_socket.rb
|
389
391
|
- examples/io/zip.rb
|
390
392
|
- examples/performance/fiber_resume.rb
|
391
393
|
- examples/performance/fiber_transfer.rb
|
392
394
|
- examples/performance/fs_read.rb
|
395
|
+
- examples/performance/line_splitting.rb
|
396
|
+
- examples/performance/loop.rb
|
393
397
|
- examples/performance/mem-usage.rb
|
394
398
|
- examples/performance/messaging.rb
|
395
399
|
- examples/performance/multi_snooze.rb
|
@@ -432,7 +436,6 @@ files:
|
|
432
436
|
- ext/liburing/setup.c
|
433
437
|
- ext/liburing/syscall.c
|
434
438
|
- ext/liburing/syscall.h
|
435
|
-
- ext/polyphony/backend.h
|
436
439
|
- ext/polyphony/backend_common.h
|
437
440
|
- ext/polyphony/backend_io_uring.c
|
438
441
|
- ext/polyphony/backend_io_uring_context.c
|
data/ext/polyphony/backend.h
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#ifndef BACKEND_H
|
2
|
-
#define BACKEND_H
|
3
|
-
|
4
|
-
#include "ruby.h"
|
5
|
-
|
6
|
-
typedef VALUE (* backend_pending_count_t)(VALUE self);
|
7
|
-
typedef VALUE (*backend_poll_t)(VALUE self, VALUE nowait, VALUE current_fiber, VALUE runqueue);
|
8
|
-
typedef VALUE (* backend_ref_t)(VALUE self);
|
9
|
-
typedef int (* backend_ref_count_t)(VALUE self);
|
10
|
-
typedef void (* backend_reset_ref_count_t)(VALUE self);
|
11
|
-
typedef VALUE (* backend_unref_t)(VALUE self);
|
12
|
-
typedef VALUE (* backend_wait_event_t)(VALUE self, VALUE raise_on_exception);
|
13
|
-
typedef VALUE (* backend_wakeup_t)(VALUE self);
|
14
|
-
|
15
|
-
typedef struct backend_interface {
|
16
|
-
backend_pending_count_t pending_count;
|
17
|
-
backend_poll_t poll;
|
18
|
-
backend_ref_t ref;
|
19
|
-
backend_ref_count_t ref_count;
|
20
|
-
backend_reset_ref_count_t reset_ref_count;
|
21
|
-
backend_unref_t unref;
|
22
|
-
backend_wait_event_t wait_event;
|
23
|
-
backend_wakeup_t wakeup;
|
24
|
-
} backend_interface_t;
|
25
|
-
|
26
|
-
#endif /* BACKEND_H */
|