polyphony 0.44.0 → 0.45.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -1
- data/CHANGELOG.md +41 -0
- data/Gemfile.lock +14 -8
- data/Rakefile +1 -1
- data/TODO.md +12 -15
- data/docs/_posts/2020-07-26-polyphony-0.44.md +77 -0
- data/docs/api-reference/thread.md +1 -1
- data/docs/getting-started/overview.md +14 -14
- data/docs/getting-started/tutorial.md +1 -1
- data/examples/adapters/redis_client.rb +3 -1
- data/examples/adapters/redis_pubsub_perf.rb +11 -8
- data/examples/adapters/sequel_mysql.rb +1 -1
- data/examples/adapters/sequel_pg.rb +24 -0
- data/examples/core/{02-awaiting-fibers.rb → await.rb} +0 -0
- data/examples/core/{xx-channels.rb → channels.rb} +0 -0
- data/examples/core/deferring-an-operation.rb +16 -0
- data/examples/core/{xx-erlang-style-genserver.rb → erlang-style-genserver.rb} +16 -9
- data/examples/core/{xx-forking.rb → forking.rb} +1 -1
- data/examples/core/handling-signals.rb +11 -0
- data/examples/core/{03-interrupting.rb → interrupt.rb} +0 -0
- data/examples/core/{xx-pingpong.rb → pingpong.rb} +7 -5
- data/examples/core/{xx-recurrent-timer.rb → recurrent-timer.rb} +1 -1
- data/examples/core/{xx-resource_delegate.rb → resource_delegate.rb} +3 -4
- data/examples/core/{01-spinning-up-fibers.rb → spin.rb} +1 -1
- data/examples/core/{xx-spin_error_backtrace.rb → spin_error_backtrace.rb} +1 -1
- data/examples/core/{xx-supervise-process.rb → supervise-process.rb} +8 -5
- data/examples/core/supervisor.rb +20 -0
- data/examples/core/{xx-thread-sleep.rb → thread-sleep.rb} +0 -0
- data/examples/core/{xx-thread_pool.rb → thread_pool.rb} +0 -0
- data/examples/core/{xx-throttling.rb → throttling.rb} +0 -0
- data/examples/core/{xx-timeout.rb → timeout.rb} +0 -0
- data/examples/core/{xx-using-a-mutex.rb → using-a-mutex.rb} +0 -0
- data/examples/core/{xx-worker-thread.rb → worker-thread.rb} +2 -2
- data/examples/io/{xx-backticks.rb → backticks.rb} +0 -0
- data/examples/io/{xx-echo_client.rb → echo_client.rb} +1 -1
- data/examples/io/{xx-echo_client_from_stdin.rb → echo_client_from_stdin.rb} +2 -2
- data/examples/io/{xx-echo_pipe.rb → echo_pipe.rb} +1 -1
- data/examples/io/{xx-echo_server.rb → echo_server.rb} +0 -0
- data/examples/io/{xx-echo_server_with_timeout.rb → echo_server_with_timeout.rb} +1 -1
- data/examples/io/{xx-echo_stdin.rb → echo_stdin.rb} +0 -0
- data/examples/io/{xx-happy-eyeballs.rb → happy-eyeballs.rb} +0 -0
- data/examples/io/{xx-httparty.rb → httparty.rb} +4 -13
- data/examples/io/{xx-irb.rb → irb.rb} +0 -0
- data/examples/io/{xx-net-http.rb → net-http.rb} +0 -0
- data/examples/io/{xx-open.rb → open.rb} +0 -0
- data/examples/io/pry.rb +18 -0
- data/examples/io/rack_server.rb +71 -0
- data/examples/io/raw.rb +14 -0
- data/examples/io/reline.rb +18 -0
- data/examples/io/{xx-system.rb → system.rb} +1 -1
- data/examples/io/{xx-tcpserver.rb → tcpserver.rb} +0 -0
- data/examples/io/{xx-tcpsocket.rb → tcpsocket.rb} +0 -0
- data/examples/io/tunnel.rb +6 -1
- data/examples/io/{xx-zip.rb → zip.rb} +0 -0
- data/examples/performance/fiber_transfer.rb +2 -1
- data/examples/performance/fs_read.rb +5 -6
- data/examples/performance/multi_snooze.rb +0 -1
- data/examples/{io/xx-switch.rb → performance/switch.rb} +2 -1
- data/examples/performance/thread-vs-fiber/{xx-httparty_multi.rb → httparty_multi.rb} +3 -4
- data/examples/performance/thread-vs-fiber/{xx-httparty_threaded.rb → httparty_threaded.rb} +0 -0
- data/examples/performance/thread-vs-fiber/polyphony_mt_server.rb +1 -1
- data/examples/performance/thread-vs-fiber/polyphony_server.rb +1 -1
- data/examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb +1 -1
- data/examples/performance/thread-vs-fiber/threaded_server.rb +1 -5
- data/examples/performance/thread_pool_perf.rb +6 -7
- data/ext/polyphony/backend.h +40 -0
- data/ext/polyphony/event.c +3 -3
- data/ext/polyphony/extconf.rb +1 -1
- data/ext/polyphony/fiber.c +90 -13
- data/ext/polyphony/{libev_agent.c → libev_backend.c} +226 -224
- data/ext/polyphony/polyphony.c +5 -7
- data/ext/polyphony/polyphony.h +18 -18
- data/ext/polyphony/polyphony_ext.c +5 -4
- data/ext/polyphony/queue.c +5 -6
- data/ext/polyphony/ring_buffer.c +0 -1
- data/ext/polyphony/runqueue.c +102 -0
- data/ext/polyphony/runqueue_ring_buffer.c +85 -0
- data/ext/polyphony/runqueue_ring_buffer.h +31 -0
- data/ext/polyphony/thread.c +53 -102
- data/lib/polyphony.rb +15 -14
- data/lib/polyphony/adapters/fs.rb +1 -1
- data/lib/polyphony/adapters/irb.rb +2 -17
- data/lib/polyphony/adapters/mysql2.rb +1 -1
- data/lib/polyphony/adapters/postgres.rb +5 -5
- data/lib/polyphony/adapters/process.rb +2 -5
- data/lib/polyphony/adapters/readline.rb +17 -0
- data/lib/polyphony/adapters/redis.rb +1 -1
- data/lib/polyphony/adapters/sequel.rb +1 -1
- data/lib/polyphony/core/global_api.rb +19 -14
- data/lib/polyphony/core/resource_pool.rb +2 -2
- data/lib/polyphony/core/sync.rb +43 -3
- data/lib/polyphony/core/throttler.rb +1 -1
- data/lib/polyphony/extensions/core.rb +25 -32
- data/lib/polyphony/extensions/fiber.rb +22 -45
- data/lib/polyphony/extensions/io.rb +60 -16
- data/lib/polyphony/extensions/openssl.rb +6 -6
- data/lib/polyphony/extensions/socket.rb +14 -15
- data/lib/polyphony/extensions/thread.rb +6 -5
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +5 -3
- data/test/helper.rb +1 -1
- data/test/{test_agent.rb → test_backend.rb} +22 -22
- data/test/test_fiber.rb +13 -12
- data/test/test_global_api.rb +29 -0
- data/test/test_io.rb +59 -1
- data/test/test_kernel.rb +5 -0
- data/test/test_signal.rb +14 -11
- data/test/test_socket.rb +17 -0
- data/test/test_sync.rb +73 -0
- metadata +99 -98
- data/.gitbook.yaml +0 -4
- data/examples/adapters/concurrent-ruby.rb +0 -9
- data/examples/core/04-handling-signals.rb +0 -19
- data/examples/core/xx-agent.rb +0 -102
- data/examples/core/xx-at_exit.rb +0 -29
- data/examples/core/xx-caller.rb +0 -12
- data/examples/core/xx-daemon.rb +0 -14
- data/examples/core/xx-deadlock.rb +0 -8
- data/examples/core/xx-deferring-an-operation.rb +0 -14
- data/examples/core/xx-exception-backtrace.rb +0 -40
- data/examples/core/xx-fork-cleanup.rb +0 -22
- data/examples/core/xx-fork-spin.rb +0 -42
- data/examples/core/xx-fork-terminate.rb +0 -27
- data/examples/core/xx-move_on.rb +0 -23
- data/examples/core/xx-queue-async.rb +0 -120
- data/examples/core/xx-readpartial.rb +0 -18
- data/examples/core/xx-signals.rb +0 -16
- data/examples/core/xx-sleep-forever.rb +0 -9
- data/examples/core/xx-sleeping.rb +0 -25
- data/examples/core/xx-snooze-starve.rb +0 -16
- data/examples/core/xx-spin-fork.rb +0 -49
- data/examples/core/xx-state-machine.rb +0 -51
- data/examples/core/xx-stop.rb +0 -20
- data/examples/core/xx-supervisors.rb +0 -21
- data/examples/core/xx-thread-selector-sleep.rb +0 -51
- data/examples/core/xx-thread-selector-snooze.rb +0 -46
- data/examples/core/xx-thread-snooze.rb +0 -34
- data/examples/core/xx-timer-gc.rb +0 -17
- data/examples/core/xx-trace.rb +0 -79
- data/examples/performance/xx-array.rb +0 -11
- data/examples/performance/xx-fiber-switch.rb +0 -9
- data/examples/performance/xx-snooze.rb +0 -15
- data/examples/xx-spin.rb +0 -32
- data/ext/polyphony/agent.h +0 -41
data/test/test_fiber.rb
CHANGED
@@ -352,7 +352,7 @@ class FiberTest < MiniTest::Test
|
|
352
352
|
result = []
|
353
353
|
f = Fiber.current.spin do
|
354
354
|
result << :start
|
355
|
-
result << Thread.current.
|
355
|
+
result << Thread.current.backend.sleep(1)
|
356
356
|
end
|
357
357
|
snooze
|
358
358
|
f.interrupt
|
@@ -641,7 +641,7 @@ class FiberTest < MiniTest::Test
|
|
641
641
|
end
|
642
642
|
end
|
643
643
|
sleep 0.1
|
644
|
-
f = spin { Thread.current.
|
644
|
+
f = spin { Thread.current.backend.waitpid(pid) }
|
645
645
|
o.close
|
646
646
|
Process.kill('INT', pid)
|
647
647
|
f.await
|
@@ -663,7 +663,7 @@ class FiberTest < MiniTest::Test
|
|
663
663
|
end
|
664
664
|
end
|
665
665
|
sleep 0.2
|
666
|
-
f = spin { Thread.current.
|
666
|
+
f = spin { Thread.current.backend.waitpid(pid) }
|
667
667
|
o.close
|
668
668
|
Process.kill('TERM', pid)
|
669
669
|
f.await
|
@@ -690,7 +690,7 @@ class FiberTest < MiniTest::Test
|
|
690
690
|
sleep 0.2
|
691
691
|
Process.kill('TERM', pid)
|
692
692
|
end
|
693
|
-
Thread.current.
|
693
|
+
Thread.current.backend.waitpid(pid)
|
694
694
|
klass = i.read
|
695
695
|
i.close
|
696
696
|
assert_equal 'Polyphony::Terminate', klass
|
@@ -700,15 +700,16 @@ class FiberTest < MiniTest::Test
|
|
700
700
|
buffer = []
|
701
701
|
f = Fiber.new { buffer << receive }
|
702
702
|
|
703
|
-
|
703
|
+
assert_nil f.thread
|
704
704
|
snooze
|
705
705
|
f.setup_raw
|
706
706
|
assert_equal Thread.current, f.thread
|
707
707
|
assert_nil f.parent
|
708
708
|
|
709
709
|
f.schedule
|
710
|
+
snooze
|
710
711
|
f << 'bar'
|
711
|
-
|
712
|
+
snooze
|
712
713
|
assert_equal ['bar'], buffer
|
713
714
|
end
|
714
715
|
end
|
@@ -811,20 +812,20 @@ class MailboxTest < MiniTest::Test
|
|
811
812
|
assert_equal ['foo'] * 100, messages
|
812
813
|
end
|
813
814
|
|
814
|
-
def
|
815
|
-
assert_equal [],
|
815
|
+
def test_receive_all_pending
|
816
|
+
assert_equal [], receive_all_pending
|
816
817
|
|
817
818
|
(1..5).each { |i| Fiber.current << i }
|
818
|
-
assert_equal (1..5).to_a,
|
819
|
-
assert_equal [],
|
819
|
+
assert_equal (1..5).to_a, receive_all_pending
|
820
|
+
assert_equal [], receive_all_pending
|
820
821
|
end
|
821
822
|
|
822
|
-
def
|
823
|
+
def test_receive_all_pending_on_termination
|
823
824
|
buffer = []
|
824
825
|
worker = spin do
|
825
826
|
loop { buffer << receive }
|
826
827
|
rescue Polyphony::Terminate
|
827
|
-
|
828
|
+
receive_all_pending.each { |r| buffer << r }
|
828
829
|
end
|
829
830
|
|
830
831
|
worker << 1
|
data/test/test_global_api.rb
CHANGED
@@ -122,6 +122,21 @@ class MoveOnAfterTest < MiniTest::Test
|
|
122
122
|
assert_equal :bar, v
|
123
123
|
end
|
124
124
|
|
125
|
+
def test_move_on_after_with_reset
|
126
|
+
t0 = Time.now
|
127
|
+
v = move_on_after(0.01, with_value: :moved_on) do |timeout|
|
128
|
+
sleep 0.007
|
129
|
+
timeout.reset
|
130
|
+
sleep 0.007
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
t1 = Time.now
|
134
|
+
|
135
|
+
assert_nil v
|
136
|
+
assert t1 - t0 >= 0.014
|
137
|
+
assert t1 - t0 < 0.02
|
138
|
+
end
|
139
|
+
|
125
140
|
def test_move_on_after_without_block
|
126
141
|
t0 = Time.now
|
127
142
|
f = move_on_after(0.01, with_value: 'foo')
|
@@ -160,6 +175,20 @@ class CancelAfterTest < MiniTest::Test
|
|
160
175
|
assert t1 - t0 < 0.1
|
161
176
|
end
|
162
177
|
|
178
|
+
def test_cancel_after_with_reset
|
179
|
+
t0 = Time.now
|
180
|
+
cancel_after(0.01) do |f|
|
181
|
+
assert_kind_of Fiber, f
|
182
|
+
assert_equal Fiber.current, f.parent
|
183
|
+
sleep 0.007
|
184
|
+
f.reset
|
185
|
+
sleep 0.007
|
186
|
+
end
|
187
|
+
t1 = Time.now
|
188
|
+
assert t1 - t0 >= 0.014
|
189
|
+
assert t1 - t0 < 0.02
|
190
|
+
end
|
191
|
+
|
163
192
|
class CustomException < Exception
|
164
193
|
end
|
165
194
|
|
data/test/test_io.rb
CHANGED
@@ -55,7 +55,7 @@ class IOTest < MiniTest::Test
|
|
55
55
|
results << result
|
56
56
|
case result
|
57
57
|
when :wait_readable
|
58
|
-
Thread.current.
|
58
|
+
Thread.current.backend.wait_io(i, false)
|
59
59
|
else
|
60
60
|
break result
|
61
61
|
end
|
@@ -92,6 +92,48 @@ class IOTest < MiniTest::Test
|
|
92
92
|
assert_raises(EOFError) { i.readpartial(1) }
|
93
93
|
end
|
94
94
|
|
95
|
+
def test_getc
|
96
|
+
i, o = IO.pipe
|
97
|
+
|
98
|
+
buf = []
|
99
|
+
f = spin do
|
100
|
+
while (c = i.getc)
|
101
|
+
buf << c
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
snooze
|
106
|
+
assert_equal [], buf
|
107
|
+
|
108
|
+
o << 'f'
|
109
|
+
snooze
|
110
|
+
o << 'g'
|
111
|
+
o.close
|
112
|
+
f.await
|
113
|
+
assert_equal ['f', 'g'], buf
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_getbyte
|
117
|
+
i, o = IO.pipe
|
118
|
+
|
119
|
+
buf = []
|
120
|
+
f = spin do
|
121
|
+
while (b = i.getbyte)
|
122
|
+
buf << b
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
snooze
|
127
|
+
assert_equal [], buf
|
128
|
+
|
129
|
+
o << 'f'
|
130
|
+
snooze
|
131
|
+
o << 'g'
|
132
|
+
o.close
|
133
|
+
f.await
|
134
|
+
assert_equal [102, 103], buf
|
135
|
+
end
|
136
|
+
|
95
137
|
# see https://github.com/digital-fabric/polyphony/issues/30
|
96
138
|
def test_reopened_tempfile
|
97
139
|
file = Tempfile.new
|
@@ -246,4 +288,20 @@ class IOClassMethodsTest < MiniTest::Test
|
|
246
288
|
assert_equal 1e6, s.bytesize
|
247
289
|
assert s == IO.orig_read(fn)
|
248
290
|
end
|
291
|
+
|
292
|
+
def pipe_read
|
293
|
+
i, o = IO.pipe
|
294
|
+
yield o
|
295
|
+
o.close
|
296
|
+
i.read
|
297
|
+
ensure
|
298
|
+
i.close
|
299
|
+
end
|
300
|
+
|
301
|
+
def test_puts
|
302
|
+
assert_equal "foo\n", pipe_read { |f| f.puts 'foo' }
|
303
|
+
assert_equal "foo\n", pipe_read { |f| f.puts "foo\n" }
|
304
|
+
assert_equal "foo\nbar\n", pipe_read { |f| f.puts 'foo', 'bar' }
|
305
|
+
assert_equal "foo\nbar\n", pipe_read { |f| f.puts 'foo', "bar\n" }
|
306
|
+
end
|
249
307
|
end
|
data/test/test_kernel.rb
CHANGED
@@ -19,6 +19,11 @@ class KernelTest < MiniTest::Test
|
|
19
19
|
timer&.stop
|
20
20
|
end
|
21
21
|
|
22
|
+
def test_Kernel_system_singleton_method
|
23
|
+
assert_equal true, Kernel.system("which ruby > /dev/null 2>&1")
|
24
|
+
assert_equal false, Kernel.system("which rruubbyy > /dev/null 2>&1")
|
25
|
+
end
|
26
|
+
|
22
27
|
def patch_open3
|
23
28
|
class << Open3
|
24
29
|
alias_method :orig_popen2, :popen2
|
data/test/test_signal.rb
CHANGED
@@ -3,18 +3,21 @@
|
|
3
3
|
require_relative 'helper'
|
4
4
|
|
5
5
|
class SignalTrapTest < Minitest::Test
|
6
|
+
def test_int_signal
|
7
|
+
Thread.new { sleep 0.001; Process.kill('INT', Process.pid) }
|
8
|
+
assert_raises(Interrupt) { sleep 5 }
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_term_signal
|
12
|
+
Thread.new { sleep 0.001; Process.kill('TERM', Process.pid) }
|
13
|
+
assert_raises(SystemExit) { sleep 5 }
|
14
|
+
end
|
15
|
+
|
6
16
|
def test_signal_exception_handling
|
7
17
|
i, o = IO.pipe
|
8
18
|
pid = Polyphony.fork do
|
9
19
|
i.close
|
10
|
-
|
11
|
-
spin do
|
12
|
-
sleep 5
|
13
|
-
rescue ::Interrupt => e
|
14
|
-
# the signal should be raised only in the main fiber
|
15
|
-
o.puts "1-interrupt"
|
16
|
-
end.await
|
17
|
-
end.await
|
20
|
+
sleep 5
|
18
21
|
rescue ::Interrupt => e
|
19
22
|
o.puts "3-interrupt"
|
20
23
|
ensure
|
@@ -23,7 +26,7 @@ class SignalTrapTest < Minitest::Test
|
|
23
26
|
sleep 0.01
|
24
27
|
o.close
|
25
28
|
Process.kill('INT', pid)
|
26
|
-
Thread.current.
|
29
|
+
Thread.current.backend.waitpid(pid)
|
27
30
|
buffer = i.read
|
28
31
|
assert_equal "3-interrupt\n", buffer
|
29
32
|
end
|
@@ -51,7 +54,7 @@ class SignalTrapTest < Minitest::Test
|
|
51
54
|
sleep 0.02
|
52
55
|
o.close
|
53
56
|
Process.kill('INT', pid)
|
54
|
-
Thread.current.
|
57
|
+
Thread.current.backend.waitpid(pid)
|
55
58
|
buffer = i.read
|
56
59
|
assert_equal "3 - interrupted\n2 - terminated\n1 - terminated\n", buffer
|
57
60
|
end
|
@@ -69,7 +72,7 @@ class SignalTrapTest < Minitest::Test
|
|
69
72
|
o.close
|
70
73
|
sleep 0.1
|
71
74
|
Process.kill('INT', pid)
|
72
|
-
Thread.current.
|
75
|
+
Thread.current.backend.waitpid(pid)
|
73
76
|
buffer = i.read
|
74
77
|
assert_equal "3-interrupt\n", buffer
|
75
78
|
end
|
data/test/test_socket.rb
CHANGED
@@ -32,3 +32,20 @@ class SocketTest < MiniTest::Test
|
|
32
32
|
server&.close
|
33
33
|
end
|
34
34
|
end
|
35
|
+
|
36
|
+
class HTTPClientTest < MiniTest::Test
|
37
|
+
require 'httparty'
|
38
|
+
require 'json'
|
39
|
+
|
40
|
+
def test_http
|
41
|
+
res = HTTParty.get('http://worldtimeapi.org/api/timezone/Europe/Paris')
|
42
|
+
response = JSON.load(res.body)
|
43
|
+
assert_equal "CEST", response['abbreviation']
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_https
|
47
|
+
res = HTTParty.get('https://worldtimeapi.org/api/timezone/Europe/Paris')
|
48
|
+
response = JSON.load(res.body)
|
49
|
+
assert_equal "CEST", response['abbreviation']
|
50
|
+
end
|
51
|
+
end
|
data/test/test_sync.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'helper'
|
4
|
+
|
5
|
+
class MutexTest < MiniTest::Test
|
6
|
+
def test_mutex
|
7
|
+
buf = []
|
8
|
+
lock = Polyphony::Mutex.new
|
9
|
+
(1..3).each do |i|
|
10
|
+
spin do
|
11
|
+
lock.synchronize do
|
12
|
+
buf << ">> #{i}"
|
13
|
+
sleep(rand * 0.05)
|
14
|
+
buf << "<< #{i}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Fiber.current.await_all_children
|
20
|
+
assert_equal ['>> 1', '<< 1', '>> 2', '<< 2', '>> 3', '<< 3'], buf
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_mutex_race_condition
|
24
|
+
lock = Polyphony::Mutex.new
|
25
|
+
buf = []
|
26
|
+
f1 = spin do
|
27
|
+
lock.synchronize { buf << 1; snooze; lock.synchronize { buf << 1.1 }; snooze }
|
28
|
+
end
|
29
|
+
f2 = spin do
|
30
|
+
lock.synchronize { buf << 2 }
|
31
|
+
end
|
32
|
+
f3 = spin do
|
33
|
+
lock.synchronize { buf << 3 }
|
34
|
+
end
|
35
|
+
|
36
|
+
snooze
|
37
|
+
f2.terminate
|
38
|
+
|
39
|
+
f3.await
|
40
|
+
|
41
|
+
assert_equal [1, 1.1, 3], buf
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_condition_variable
|
45
|
+
buf = []
|
46
|
+
lock1 = Polyphony::Mutex.new
|
47
|
+
lock2 = Polyphony::Mutex.new
|
48
|
+
cond = Polyphony::ConditionVariable.new
|
49
|
+
|
50
|
+
spin do
|
51
|
+
lock1.synchronize do
|
52
|
+
sleep 0.01
|
53
|
+
cond.wait(lock1)
|
54
|
+
lock2.synchronize do
|
55
|
+
buf << :foo
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
spin do
|
61
|
+
lock2.synchronize do
|
62
|
+
sleep 0.01
|
63
|
+
lock1.synchronize do
|
64
|
+
buf << :bar
|
65
|
+
end
|
66
|
+
cond.signal
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
Fiber.current.await_all_children
|
71
|
+
assert_equal [:bar, :foo], buf
|
72
|
+
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyphony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.45.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 0.17.0
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 0.17.0
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: localhost
|
14
|
+
name: rake-compiler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - '='
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.1.
|
19
|
+
version: 1.1.1
|
34
20
|
type: :development
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - '='
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.1.
|
26
|
+
version: 1.1.1
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: minitest
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,33 +81,33 @@ dependencies:
|
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
version: 0.85.1
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: pry
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - '='
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
89
|
+
version: 0.13.1
|
104
90
|
type: :development
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - '='
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
96
|
+
version: 0.13.1
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: pg
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - '='
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.
|
103
|
+
version: 1.1.4
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - '='
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: 1.
|
110
|
+
version: 1.1.4
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: redis
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,6 +150,26 @@ dependencies:
|
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
152
|
version: 0.6.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rack
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 2.0.8
|
160
|
+
- - "<"
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: 2.3.0
|
163
|
+
type: :development
|
164
|
+
prerelease: false
|
165
|
+
version_requirements: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: 2.0.8
|
170
|
+
- - "<"
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: 2.3.0
|
167
173
|
- !ruby/object:Gem::Dependency
|
168
174
|
name: mysql2
|
169
175
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +198,20 @@ dependencies:
|
|
192
198
|
- - '='
|
193
199
|
- !ruby/object:Gem::Version
|
194
200
|
version: 5.34.0
|
201
|
+
- !ruby/object:Gem::Dependency
|
202
|
+
name: httparty
|
203
|
+
requirement: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - '='
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: 0.17.1
|
208
|
+
type: :development
|
209
|
+
prerelease: false
|
210
|
+
version_requirements: !ruby/object:Gem::Requirement
|
211
|
+
requirements:
|
212
|
+
- - '='
|
213
|
+
- !ruby/object:Gem::Version
|
214
|
+
version: 0.17.1
|
195
215
|
- !ruby/object:Gem::Dependency
|
196
216
|
name: jekyll
|
197
217
|
requirement: !ruby/object:Gem::Requirement
|
@@ -256,7 +276,6 @@ extensions:
|
|
256
276
|
extra_rdoc_files:
|
257
277
|
- README.md
|
258
278
|
files:
|
259
|
-
- ".gitbook.yaml"
|
260
279
|
- ".github/workflows/test.yml"
|
261
280
|
- ".gitignore"
|
262
281
|
- ".rubocop.yml"
|
@@ -273,6 +292,7 @@ files:
|
|
273
292
|
- docs/_config.yml
|
274
293
|
- docs/_includes/head.html
|
275
294
|
- docs/_includes/title.html
|
295
|
+
- docs/_posts/2020-07-26-polyphony-0.44.md
|
276
296
|
- docs/_sass/custom/custom.scss
|
277
297
|
- docs/_sass/overrides.scss
|
278
298
|
- docs/_user-guide/all-about-timers.md
|
@@ -311,7 +331,6 @@ files:
|
|
311
331
|
- docs/main-concepts/fiber-scheduling.md
|
312
332
|
- docs/main-concepts/index.md
|
313
333
|
- docs/polyphony-logo.png
|
314
|
-
- examples/adapters/concurrent-ruby.rb
|
315
334
|
- examples/adapters/pg_client.rb
|
316
335
|
- examples/adapters/pg_notify.rb
|
317
336
|
- examples/adapters/pg_pool.rb
|
@@ -323,68 +342,48 @@ files:
|
|
323
342
|
- examples/adapters/redis_pubsub_perf.rb
|
324
343
|
- examples/adapters/sequel_mysql.rb
|
325
344
|
- examples/adapters/sequel_mysql_pool.rb
|
326
|
-
- examples/
|
327
|
-
- examples/core/
|
328
|
-
- examples/core/
|
329
|
-
- examples/core/
|
330
|
-
- examples/core/
|
331
|
-
- examples/core/
|
332
|
-
- examples/core/
|
333
|
-
- examples/core/
|
334
|
-
- examples/core/
|
335
|
-
- examples/core/
|
336
|
-
- examples/core/
|
337
|
-
- examples/core/
|
338
|
-
- examples/core/
|
339
|
-
- examples/core/
|
340
|
-
- examples/core/
|
341
|
-
- examples/core/
|
342
|
-
- examples/core/
|
343
|
-
- examples/core/
|
344
|
-
- examples/core/
|
345
|
-
- examples/core/
|
346
|
-
- examples/core/
|
347
|
-
- examples/
|
348
|
-
- examples/
|
349
|
-
- examples/
|
350
|
-
- examples/
|
351
|
-
- examples/
|
352
|
-
- examples/
|
353
|
-
- examples/
|
354
|
-
- examples/
|
355
|
-
- examples/
|
356
|
-
- examples/
|
357
|
-
- examples/
|
358
|
-
- examples/
|
359
|
-
- examples/
|
360
|
-
- examples/
|
361
|
-
- examples/
|
362
|
-
- examples/
|
363
|
-
- examples/
|
364
|
-
- examples/
|
365
|
-
- examples/
|
366
|
-
- examples/core/xx-timer-gc.rb
|
367
|
-
- examples/core/xx-trace.rb
|
368
|
-
- examples/core/xx-using-a-mutex.rb
|
369
|
-
- examples/core/xx-worker-thread.rb
|
345
|
+
- examples/adapters/sequel_pg.rb
|
346
|
+
- examples/core/await.rb
|
347
|
+
- examples/core/channels.rb
|
348
|
+
- examples/core/deferring-an-operation.rb
|
349
|
+
- examples/core/erlang-style-genserver.rb
|
350
|
+
- examples/core/forking.rb
|
351
|
+
- examples/core/handling-signals.rb
|
352
|
+
- examples/core/interrupt.rb
|
353
|
+
- examples/core/pingpong.rb
|
354
|
+
- examples/core/recurrent-timer.rb
|
355
|
+
- examples/core/resource_delegate.rb
|
356
|
+
- examples/core/spin.rb
|
357
|
+
- examples/core/spin_error_backtrace.rb
|
358
|
+
- examples/core/supervise-process.rb
|
359
|
+
- examples/core/supervisor.rb
|
360
|
+
- examples/core/thread-sleep.rb
|
361
|
+
- examples/core/thread_pool.rb
|
362
|
+
- examples/core/throttling.rb
|
363
|
+
- examples/core/timeout.rb
|
364
|
+
- examples/core/using-a-mutex.rb
|
365
|
+
- examples/core/worker-thread.rb
|
366
|
+
- examples/io/backticks.rb
|
367
|
+
- examples/io/echo_client.rb
|
368
|
+
- examples/io/echo_client_from_stdin.rb
|
369
|
+
- examples/io/echo_pipe.rb
|
370
|
+
- examples/io/echo_server.rb
|
371
|
+
- examples/io/echo_server_with_timeout.rb
|
372
|
+
- examples/io/echo_stdin.rb
|
373
|
+
- examples/io/happy-eyeballs.rb
|
374
|
+
- examples/io/httparty.rb
|
375
|
+
- examples/io/irb.rb
|
376
|
+
- examples/io/net-http.rb
|
377
|
+
- examples/io/open.rb
|
378
|
+
- examples/io/pry.rb
|
379
|
+
- examples/io/rack_server.rb
|
380
|
+
- examples/io/raw.rb
|
381
|
+
- examples/io/reline.rb
|
382
|
+
- examples/io/system.rb
|
383
|
+
- examples/io/tcpserver.rb
|
384
|
+
- examples/io/tcpsocket.rb
|
370
385
|
- examples/io/tunnel.rb
|
371
|
-
- examples/io/
|
372
|
-
- examples/io/xx-echo_client.rb
|
373
|
-
- examples/io/xx-echo_client_from_stdin.rb
|
374
|
-
- examples/io/xx-echo_pipe.rb
|
375
|
-
- examples/io/xx-echo_server.rb
|
376
|
-
- examples/io/xx-echo_server_with_timeout.rb
|
377
|
-
- examples/io/xx-echo_stdin.rb
|
378
|
-
- examples/io/xx-happy-eyeballs.rb
|
379
|
-
- examples/io/xx-httparty.rb
|
380
|
-
- examples/io/xx-irb.rb
|
381
|
-
- examples/io/xx-net-http.rb
|
382
|
-
- examples/io/xx-open.rb
|
383
|
-
- examples/io/xx-switch.rb
|
384
|
-
- examples/io/xx-system.rb
|
385
|
-
- examples/io/xx-tcpserver.rb
|
386
|
-
- examples/io/xx-tcpsocket.rb
|
387
|
-
- examples/io/xx-zip.rb
|
386
|
+
- examples/io/zip.rb
|
388
387
|
- examples/performance/fiber_transfer.rb
|
389
388
|
- examples/performance/fs_read.rb
|
390
389
|
- examples/performance/mem-usage.rb
|
@@ -392,17 +391,14 @@ files:
|
|
392
391
|
- examples/performance/multi_snooze.rb
|
393
392
|
- examples/performance/snooze.rb
|
394
393
|
- examples/performance/snooze_raw.rb
|
394
|
+
- examples/performance/switch.rb
|
395
|
+
- examples/performance/thread-vs-fiber/httparty_multi.rb
|
396
|
+
- examples/performance/thread-vs-fiber/httparty_threaded.rb
|
395
397
|
- examples/performance/thread-vs-fiber/polyphony_mt_server.rb
|
396
398
|
- examples/performance/thread-vs-fiber/polyphony_server.rb
|
397
399
|
- examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb
|
398
400
|
- examples/performance/thread-vs-fiber/threaded_server.rb
|
399
|
-
- examples/performance/thread-vs-fiber/xx-httparty_multi.rb
|
400
|
-
- examples/performance/thread-vs-fiber/xx-httparty_threaded.rb
|
401
401
|
- examples/performance/thread_pool_perf.rb
|
402
|
-
- examples/performance/xx-array.rb
|
403
|
-
- examples/performance/xx-fiber-switch.rb
|
404
|
-
- examples/performance/xx-snooze.rb
|
405
|
-
- examples/xx-spin.rb
|
406
402
|
- ext/libev/Changes
|
407
403
|
- ext/libev/LICENSE
|
408
404
|
- ext/libev/README
|
@@ -419,19 +415,22 @@ files:
|
|
419
415
|
- ext/libev/ev_win32.c
|
420
416
|
- ext/libev/ev_wrap.h
|
421
417
|
- ext/libev/test_libev_win32.c
|
422
|
-
- ext/polyphony/
|
418
|
+
- ext/polyphony/backend.h
|
423
419
|
- ext/polyphony/event.c
|
424
420
|
- ext/polyphony/extconf.rb
|
425
421
|
- ext/polyphony/fiber.c
|
426
422
|
- ext/polyphony/libev.c
|
427
423
|
- ext/polyphony/libev.h
|
428
|
-
- ext/polyphony/
|
424
|
+
- ext/polyphony/libev_backend.c
|
429
425
|
- ext/polyphony/polyphony.c
|
430
426
|
- ext/polyphony/polyphony.h
|
431
427
|
- ext/polyphony/polyphony_ext.c
|
432
428
|
- ext/polyphony/queue.c
|
433
429
|
- ext/polyphony/ring_buffer.c
|
434
430
|
- ext/polyphony/ring_buffer.h
|
431
|
+
- ext/polyphony/runqueue.c
|
432
|
+
- ext/polyphony/runqueue_ring_buffer.c
|
433
|
+
- ext/polyphony/runqueue_ring_buffer.h
|
435
434
|
- ext/polyphony/thread.c
|
436
435
|
- ext/polyphony/tracing.c
|
437
436
|
- lib/polyphony.rb
|
@@ -440,6 +439,7 @@ files:
|
|
440
439
|
- lib/polyphony/adapters/mysql2.rb
|
441
440
|
- lib/polyphony/adapters/postgres.rb
|
442
441
|
- lib/polyphony/adapters/process.rb
|
442
|
+
- lib/polyphony/adapters/readline.rb
|
443
443
|
- lib/polyphony/adapters/redis.rb
|
444
444
|
- lib/polyphony/adapters/sequel.rb
|
445
445
|
- lib/polyphony/adapters/trace.rb
|
@@ -465,7 +465,7 @@ files:
|
|
465
465
|
- test/q.rb
|
466
466
|
- test/run.rb
|
467
467
|
- test/stress.rb
|
468
|
-
- test/
|
468
|
+
- test/test_backend.rb
|
469
469
|
- test/test_event.rb
|
470
470
|
- test/test_ext.rb
|
471
471
|
- test/test_fiber.rb
|
@@ -478,6 +478,7 @@ files:
|
|
478
478
|
- test/test_signal.rb
|
479
479
|
- test/test_socket.rb
|
480
480
|
- test/test_supervise.rb
|
481
|
+
- test/test_sync.rb
|
481
482
|
- test/test_thread.rb
|
482
483
|
- test/test_thread_pool.rb
|
483
484
|
- test/test_throttler.rb
|
@@ -509,7 +510,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
509
510
|
- !ruby/object:Gem::Version
|
510
511
|
version: '0'
|
511
512
|
requirements: []
|
512
|
-
rubygems_version: 3.1.
|
513
|
+
rubygems_version: 3.1.4
|
513
514
|
signing_key:
|
514
515
|
specification_version: 4
|
515
516
|
summary: Fine grained concurrency for Ruby
|