polyphony 0.44.0 → 0.45.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/.rubocop.yml +7 -1
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +9 -11
- data/Rakefile +1 -1
- data/TODO.md +12 -7
- 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/core/{xx-agent.rb → xx-backend.rb} +5 -5
- data/examples/io/xx-pry.rb +18 -0
- data/examples/io/xx-rack_server.rb +71 -0
- data/examples/performance/thread-vs-fiber/polyphony_server_read_loop.rb +1 -1
- data/ext/polyphony/backend.h +41 -0
- data/ext/polyphony/event.c +3 -3
- data/ext/polyphony/extconf.rb +1 -1
- data/ext/polyphony/{libev_agent.c → libev_backend.c} +175 -175
- data/ext/polyphony/polyphony.c +1 -1
- data/ext/polyphony/polyphony.h +4 -4
- data/ext/polyphony/polyphony_ext.c +2 -2
- data/ext/polyphony/queue.c +2 -2
- data/ext/polyphony/thread.c +21 -21
- data/lib/polyphony.rb +13 -12
- 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 -2
- data/lib/polyphony/adapters/readline.rb +17 -0
- data/lib/polyphony/adapters/sequel.rb +1 -1
- data/lib/polyphony/core/global_api.rb +11 -6
- data/lib/polyphony/core/resource_pool.rb +2 -2
- data/lib/polyphony/core/sync.rb +38 -2
- data/lib/polyphony/core/throttler.rb +1 -1
- data/lib/polyphony/extensions/core.rb +31 -20
- data/lib/polyphony/extensions/fiber.rb +1 -1
- data/lib/polyphony/extensions/io.rb +7 -8
- data/lib/polyphony/extensions/openssl.rb +6 -6
- data/lib/polyphony/extensions/socket.rb +4 -14
- data/lib/polyphony/extensions/thread.rb +6 -5
- data/lib/polyphony/version.rb +1 -1
- data/polyphony.gemspec +4 -3
- data/test/helper.rb +1 -1
- data/test/{test_agent.rb → test_backend.rb} +22 -22
- data/test/test_fiber.rb +4 -4
- data/test/test_io.rb +1 -1
- data/test/test_kernel.rb +5 -0
- data/test/test_signal.rb +3 -3
- data/test/test_sync.rb +52 -0
- metadata +40 -30
- data/.gitbook.yaml +0 -4
- 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
|
data/test/test_io.rb
CHANGED
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
@@ -23,7 +23,7 @@ class SignalTrapTest < Minitest::Test
|
|
23
23
|
sleep 0.01
|
24
24
|
o.close
|
25
25
|
Process.kill('INT', pid)
|
26
|
-
Thread.current.
|
26
|
+
Thread.current.backend.waitpid(pid)
|
27
27
|
buffer = i.read
|
28
28
|
assert_equal "3-interrupt\n", buffer
|
29
29
|
end
|
@@ -51,7 +51,7 @@ class SignalTrapTest < Minitest::Test
|
|
51
51
|
sleep 0.02
|
52
52
|
o.close
|
53
53
|
Process.kill('INT', pid)
|
54
|
-
Thread.current.
|
54
|
+
Thread.current.backend.waitpid(pid)
|
55
55
|
buffer = i.read
|
56
56
|
assert_equal "3 - interrupted\n2 - terminated\n1 - terminated\n", buffer
|
57
57
|
end
|
@@ -69,7 +69,7 @@ class SignalTrapTest < Minitest::Test
|
|
69
69
|
o.close
|
70
70
|
sleep 0.1
|
71
71
|
Process.kill('INT', pid)
|
72
|
-
Thread.current.
|
72
|
+
Thread.current.backend.waitpid(pid)
|
73
73
|
buffer = i.read
|
74
74
|
assert_equal "3-interrupt\n", buffer
|
75
75
|
end
|
data/test/test_sync.rb
ADDED
@@ -0,0 +1,52 @@
|
|
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_condition_variable
|
24
|
+
buf = []
|
25
|
+
lock1 = Polyphony::Mutex.new
|
26
|
+
lock2 = Polyphony::Mutex.new
|
27
|
+
cond = Polyphony::ConditionVariable.new
|
28
|
+
|
29
|
+
spin do
|
30
|
+
lock1.synchronize do
|
31
|
+
sleep 0.01
|
32
|
+
cond.wait(lock1)
|
33
|
+
lock2.synchronize do
|
34
|
+
buf << :foo
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
spin do
|
40
|
+
lock2.synchronize do
|
41
|
+
sleep 0.01
|
42
|
+
lock1.synchronize do
|
43
|
+
buf << :bar
|
44
|
+
end
|
45
|
+
cond.signal
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Fiber.current.await_all_children
|
50
|
+
assert_equal [:bar, :foo], buf
|
51
|
+
end
|
52
|
+
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.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: 2020-07-
|
11
|
+
date: 2020-07-29 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.
|
19
|
+
version: 1.0.5
|
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.
|
26
|
+
version: 1.0.5
|
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
|
@@ -256,7 +262,6 @@ extensions:
|
|
256
262
|
extra_rdoc_files:
|
257
263
|
- README.md
|
258
264
|
files:
|
259
|
-
- ".gitbook.yaml"
|
260
265
|
- ".github/workflows/test.yml"
|
261
266
|
- ".gitignore"
|
262
267
|
- ".rubocop.yml"
|
@@ -273,6 +278,7 @@ files:
|
|
273
278
|
- docs/_config.yml
|
274
279
|
- docs/_includes/head.html
|
275
280
|
- docs/_includes/title.html
|
281
|
+
- docs/_posts/2020-07-26-polyphony-0.44.md
|
276
282
|
- docs/_sass/custom/custom.scss
|
277
283
|
- docs/_sass/overrides.scss
|
278
284
|
- docs/_user-guide/all-about-timers.md
|
@@ -327,8 +333,8 @@ files:
|
|
327
333
|
- examples/core/02-awaiting-fibers.rb
|
328
334
|
- examples/core/03-interrupting.rb
|
329
335
|
- examples/core/04-handling-signals.rb
|
330
|
-
- examples/core/xx-agent.rb
|
331
336
|
- examples/core/xx-at_exit.rb
|
337
|
+
- examples/core/xx-backend.rb
|
332
338
|
- examples/core/xx-caller.rb
|
333
339
|
- examples/core/xx-channels.rb
|
334
340
|
- examples/core/xx-daemon.rb
|
@@ -380,6 +386,8 @@ files:
|
|
380
386
|
- examples/io/xx-irb.rb
|
381
387
|
- examples/io/xx-net-http.rb
|
382
388
|
- examples/io/xx-open.rb
|
389
|
+
- examples/io/xx-pry.rb
|
390
|
+
- examples/io/xx-rack_server.rb
|
383
391
|
- examples/io/xx-switch.rb
|
384
392
|
- examples/io/xx-system.rb
|
385
393
|
- examples/io/xx-tcpserver.rb
|
@@ -419,13 +427,13 @@ files:
|
|
419
427
|
- ext/libev/ev_win32.c
|
420
428
|
- ext/libev/ev_wrap.h
|
421
429
|
- ext/libev/test_libev_win32.c
|
422
|
-
- ext/polyphony/
|
430
|
+
- ext/polyphony/backend.h
|
423
431
|
- ext/polyphony/event.c
|
424
432
|
- ext/polyphony/extconf.rb
|
425
433
|
- ext/polyphony/fiber.c
|
426
434
|
- ext/polyphony/libev.c
|
427
435
|
- ext/polyphony/libev.h
|
428
|
-
- ext/polyphony/
|
436
|
+
- ext/polyphony/libev_backend.c
|
429
437
|
- ext/polyphony/polyphony.c
|
430
438
|
- ext/polyphony/polyphony.h
|
431
439
|
- ext/polyphony/polyphony_ext.c
|
@@ -440,6 +448,7 @@ files:
|
|
440
448
|
- lib/polyphony/adapters/mysql2.rb
|
441
449
|
- lib/polyphony/adapters/postgres.rb
|
442
450
|
- lib/polyphony/adapters/process.rb
|
451
|
+
- lib/polyphony/adapters/readline.rb
|
443
452
|
- lib/polyphony/adapters/redis.rb
|
444
453
|
- lib/polyphony/adapters/sequel.rb
|
445
454
|
- lib/polyphony/adapters/trace.rb
|
@@ -465,7 +474,7 @@ files:
|
|
465
474
|
- test/q.rb
|
466
475
|
- test/run.rb
|
467
476
|
- test/stress.rb
|
468
|
-
- test/
|
477
|
+
- test/test_backend.rb
|
469
478
|
- test/test_event.rb
|
470
479
|
- test/test_ext.rb
|
471
480
|
- test/test_fiber.rb
|
@@ -478,6 +487,7 @@ files:
|
|
478
487
|
- test/test_signal.rb
|
479
488
|
- test/test_socket.rb
|
480
489
|
- test/test_supervise.rb
|
490
|
+
- test/test_sync.rb
|
481
491
|
- test/test_thread.rb
|
482
492
|
- test/test_thread_pool.rb
|
483
493
|
- test/test_throttler.rb
|
data/.gitbook.yaml
DELETED
data/ext/polyphony/agent.h
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
#ifndef AGENT_H
|
2
|
-
#define AGENT_H
|
3
|
-
|
4
|
-
#include "ruby.h"
|
5
|
-
|
6
|
-
// agent interface function signatures
|
7
|
-
|
8
|
-
// VALUE LibevAgent_accept(VALUE self, VALUE sock);
|
9
|
-
// VALUE LibevAgent_accept_loop(VALUE self, VALUE sock);
|
10
|
-
// VALUE libev_agent_await(VALUE self);
|
11
|
-
// VALUE LibevAgent_connect(VALUE self, VALUE sock, VALUE host, VALUE port);
|
12
|
-
// VALUE LibevAgent_finalize(VALUE self);
|
13
|
-
// VALUE LibevAgent_post_fork(VALUE self);
|
14
|
-
// VALUE LibevAgent_read(VALUE self, VALUE io, VALUE str, VALUE length, VALUE to_eof);
|
15
|
-
// VALUE LibevAgent_read_loop(VALUE self, VALUE io);
|
16
|
-
// VALUE LibevAgent_sleep(VALUE self, VALUE duration);
|
17
|
-
// VALUE LibevAgent_wait_io(VALUE self, VALUE io, VALUE write);
|
18
|
-
// VALUE LibevAgent_wait_pid(VALUE self, VALUE pid);
|
19
|
-
// VALUE LibevAgent_write(int argc, VALUE *argv, VALUE self);
|
20
|
-
|
21
|
-
typedef VALUE (* agent_pending_count_t)(VALUE self);
|
22
|
-
typedef VALUE (*agent_poll_t)(VALUE self, VALUE nowait, VALUE current_fiber, VALUE queue);
|
23
|
-
typedef VALUE (* agent_ref_t)(VALUE self);
|
24
|
-
typedef int (* agent_ref_count_t)(VALUE self);
|
25
|
-
typedef void (* agent_reset_ref_count_t)(VALUE self);
|
26
|
-
typedef VALUE (* agent_unref_t)(VALUE self);
|
27
|
-
typedef VALUE (* agent_wait_event_t)(VALUE self, VALUE raise_on_exception);
|
28
|
-
typedef VALUE (* agent_wakeup_t)(VALUE self);
|
29
|
-
|
30
|
-
typedef struct agent_interface {
|
31
|
-
agent_pending_count_t pending_count;
|
32
|
-
agent_poll_t poll;
|
33
|
-
agent_ref_t ref;
|
34
|
-
agent_ref_count_t ref_count;
|
35
|
-
agent_reset_ref_count_t reset_ref_count;
|
36
|
-
agent_unref_t unref;
|
37
|
-
agent_wait_event_t wait_event;
|
38
|
-
agent_wakeup_t wakeup;
|
39
|
-
} agent_interface_t;
|
40
|
-
|
41
|
-
#endif /* AGENT_H */
|