polyphony 0.99 → 0.99.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +1 -1
- data/.rubocop.yml +3 -3
- data/.yardopts +30 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE +1 -1
- data/README.md +63 -29
- data/Rakefile +1 -5
- data/TODO.md +0 -4
- data/docs/{main-concepts/concurrency.md → concurrency.md} +2 -9
- data/docs/{main-concepts/design-principles.md → design-principles.md} +3 -9
- data/docs/{main-concepts/exception-handling.md → exception-handling.md} +2 -9
- data/docs/{main-concepts/extending.md → extending.md} +2 -9
- data/docs/faq.md +3 -16
- data/docs/{main-concepts/fiber-scheduling.md → fiber-scheduling.md} +1 -9
- data/docs/link_rewriter.rb +16 -0
- data/docs/{getting-started/overview.md → overview.md} +1 -30
- data/docs/{getting-started/tutorial.md → tutorial.md} +3 -28
- data/docs/{_posts/2020-07-26-polyphony-0.44.md → whats-new.md} +3 -1
- data/examples/adapters/redis_client.rb +3 -2
- data/examples/io/echo_server.rb +1 -1
- data/examples/io/echo_server_plain_ruby.rb +26 -0
- data/ext/polyphony/backend_io_uring.c +154 -9
- data/ext/polyphony/backend_io_uring_context.c +21 -12
- data/ext/polyphony/backend_io_uring_context.h +12 -7
- data/ext/polyphony/backend_libev.c +1 -1
- data/ext/polyphony/extconf.rb +24 -8
- data/ext/polyphony/fiber.c +79 -2
- data/ext/polyphony/io_extensions.c +53 -0
- data/ext/polyphony/pipe.c +42 -2
- data/ext/polyphony/polyphony.c +345 -31
- data/ext/polyphony/polyphony.h +9 -2
- data/ext/polyphony/queue.c +181 -0
- data/ext/polyphony/ring_buffer.c +0 -1
- data/ext/polyphony/runqueue.c +8 -1
- data/ext/polyphony/runqueue_ring_buffer.c +13 -0
- data/ext/polyphony/runqueue_ring_buffer.h +2 -1
- data/ext/polyphony/socket_extensions.c +6 -0
- data/ext/polyphony/thread.c +34 -2
- data/lib/polyphony/adapters/process.rb +11 -1
- data/lib/polyphony/adapters/sequel.rb +1 -1
- data/lib/polyphony/core/channel.rb +2 -0
- data/lib/polyphony/core/debug.rb +1 -1
- data/lib/polyphony/core/global_api.rb +25 -24
- data/lib/polyphony/core/resource_pool.rb +7 -6
- data/lib/polyphony/core/sync.rb +2 -2
- data/lib/polyphony/core/thread_pool.rb +3 -3
- data/lib/polyphony/core/timer.rb +8 -8
- data/lib/polyphony/extensions/exception.rb +2 -0
- data/lib/polyphony/extensions/fiber.rb +15 -13
- data/lib/polyphony/extensions/io.rb +127 -5
- data/lib/polyphony/extensions/kernel.rb +20 -2
- data/lib/polyphony/extensions/openssl.rb +100 -11
- data/lib/polyphony/extensions/pipe.rb +103 -7
- data/lib/polyphony/extensions/process.rb +13 -1
- data/lib/polyphony/extensions/socket.rb +93 -27
- data/lib/polyphony/extensions/thread.rb +9 -1
- data/lib/polyphony/extensions/timeout.rb +1 -1
- data/lib/polyphony/version.rb +2 -1
- data/lib/polyphony.rb +27 -7
- data/polyphony.gemspec +1 -8
- data/test/stress.rb +1 -1
- data/test/test_global_api.rb +45 -7
- data/test/test_socket.rb +96 -0
- data/test/test_timer.rb +5 -5
- metadata +17 -40
- data/docs/_config.yml +0 -64
- data/docs/_includes/head.html +0 -40
- data/docs/_includes/title.html +0 -1
- data/docs/_sass/custom/custom.scss +0 -10
- data/docs/_sass/overrides.scss +0 -0
- data/docs/api-reference/exception.md +0 -31
- data/docs/api-reference/fiber.md +0 -425
- data/docs/api-reference/index.md +0 -9
- data/docs/api-reference/io.md +0 -36
- data/docs/api-reference/object.md +0 -99
- data/docs/api-reference/polyphony-baseexception.md +0 -33
- data/docs/api-reference/polyphony-cancel.md +0 -26
- data/docs/api-reference/polyphony-moveon.md +0 -24
- data/docs/api-reference/polyphony-net.md +0 -20
- data/docs/api-reference/polyphony-process.md +0 -28
- data/docs/api-reference/polyphony-resourcepool.md +0 -59
- data/docs/api-reference/polyphony-restart.md +0 -18
- data/docs/api-reference/polyphony-terminate.md +0 -18
- data/docs/api-reference/polyphony-threadpool.md +0 -67
- data/docs/api-reference/polyphony-throttler.md +0 -77
- data/docs/api-reference/polyphony.md +0 -36
- data/docs/api-reference/thread.md +0 -88
- data/docs/favicon.ico +0 -0
- data/docs/getting-started/index.md +0 -10
- data/docs/getting-started/installing.md +0 -34
- /data/{docs/assets/img → assets}/echo-fibers.svg +0 -0
- /data/{docs → assets}/polyphony-logo.png +0 -0
- /data/{docs/assets/img → assets}/sleeping-fiber.svg +0 -0
data/test/test_socket.rb
CHANGED
@@ -383,3 +383,99 @@ class SSLSocketTest < MiniTest::Test
|
|
383
383
|
assert_kind_of OpenSSL::SSL::SSLError, errors.first
|
384
384
|
end
|
385
385
|
end
|
386
|
+
|
387
|
+
class MultishotAcceptTest < MiniTest::Test
|
388
|
+
def setup
|
389
|
+
skip if !TCPServer.instance_methods(false).include?(:multishot_accept)
|
390
|
+
end
|
391
|
+
|
392
|
+
def start_tcp_server_on_random_port(host = '127.0.0.1')
|
393
|
+
port = rand(1100..60000)
|
394
|
+
server = TCPServer.new(host, port)
|
395
|
+
[port, server]
|
396
|
+
rescue Errno::EADDRINUSE
|
397
|
+
retry
|
398
|
+
end
|
399
|
+
|
400
|
+
def test_multishot_accept_while_loop
|
401
|
+
port, server = start_tcp_server_on_random_port
|
402
|
+
server_fiber = spin do
|
403
|
+
server.multishot_accept do
|
404
|
+
while (socket = server.accept)
|
405
|
+
spin do
|
406
|
+
while (data = socket.gets(8192))
|
407
|
+
socket << data
|
408
|
+
end
|
409
|
+
end
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
snooze
|
415
|
+
client = TCPSocket.new('127.0.0.1', port)
|
416
|
+
client.write("1234\n")
|
417
|
+
assert_equal "1234\n", client.recv(8192)
|
418
|
+
client.close
|
419
|
+
|
420
|
+
client = TCPSocket.new('127.0.0.1', port)
|
421
|
+
client.write("5678\n")
|
422
|
+
assert_equal "5678\n", client.recv(8192)
|
423
|
+
client.close
|
424
|
+
|
425
|
+
ensure
|
426
|
+
server_fiber&.stop
|
427
|
+
server_fiber&.await
|
428
|
+
server&.close
|
429
|
+
end
|
430
|
+
|
431
|
+
def spin_client(socket)
|
432
|
+
spin do
|
433
|
+
while (data = socket.gets(8192))
|
434
|
+
socket << data
|
435
|
+
end
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
def test_multishot_accept_loop
|
440
|
+
port, server = start_tcp_server_on_random_port
|
441
|
+
server_fiber = spin do
|
442
|
+
server.multishot_accept do
|
443
|
+
server.accept_loop { |s| spin_client(s) }
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
snooze
|
448
|
+
client = TCPSocket.new('127.0.0.1', port)
|
449
|
+
client.write("1234\n")
|
450
|
+
assert_equal "1234\n", client.recv(8192)
|
451
|
+
client.close
|
452
|
+
|
453
|
+
client = TCPSocket.new('127.0.0.1', port)
|
454
|
+
client.write("5678\n")
|
455
|
+
assert_equal "5678\n", client.recv(8192)
|
456
|
+
client.close
|
457
|
+
|
458
|
+
ensure
|
459
|
+
server_fiber&.stop
|
460
|
+
server_fiber&.await
|
461
|
+
server&.close
|
462
|
+
end
|
463
|
+
|
464
|
+
def test_multishot_accept_error
|
465
|
+
port, server = start_tcp_server_on_random_port
|
466
|
+
error = nil
|
467
|
+
server_fiber = spin do
|
468
|
+
server.multishot_accept do
|
469
|
+
server.accept_loop { |s| spin_client(s) }
|
470
|
+
rescue SystemCallError => e
|
471
|
+
error = e
|
472
|
+
end
|
473
|
+
end
|
474
|
+
snooze
|
475
|
+
server.close
|
476
|
+
snooze
|
477
|
+
server_fiber.await
|
478
|
+
assert_kind_of Errno::EBADF, error
|
479
|
+
end
|
480
|
+
|
481
|
+
end
|
data/test/test_timer.rb
CHANGED
@@ -39,18 +39,18 @@ class TimerMoveOnAfterTest < MiniTest::Test
|
|
39
39
|
skip unless IS_LINUX
|
40
40
|
|
41
41
|
t0 = Time.now
|
42
|
-
v = @timer.move_on_after(0.
|
43
|
-
sleep 0.
|
42
|
+
v = @timer.move_on_after(0.1, with_value: :moved_on) do
|
43
|
+
sleep 0.07
|
44
44
|
@timer.reset
|
45
|
-
sleep 0.
|
45
|
+
sleep 0.07
|
46
46
|
@timer.reset
|
47
|
-
sleep 0.
|
47
|
+
sleep 0.07
|
48
48
|
nil
|
49
49
|
end
|
50
50
|
t1 = Time.now
|
51
51
|
|
52
52
|
assert_nil v
|
53
|
-
assert_in_range 0.
|
53
|
+
assert_in_range 0.15..0.4, t1 - t0
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
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:
|
4
|
+
version: 0.99.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sharon Rosner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake-compiler
|
@@ -137,58 +137,35 @@ files:
|
|
137
137
|
- ".gitmodules"
|
138
138
|
- ".rubocop.yml"
|
139
139
|
- ".vscode/launch.json"
|
140
|
+
- ".yardopts"
|
140
141
|
- CHANGELOG.md
|
141
142
|
- Gemfile
|
142
143
|
- LICENSE
|
143
144
|
- README.md
|
144
145
|
- Rakefile
|
145
146
|
- TODO.md
|
147
|
+
- assets/echo-fibers.svg
|
148
|
+
- assets/polyphony-logo.png
|
149
|
+
- assets/sleeping-fiber.svg
|
146
150
|
- bin/pdbg
|
147
151
|
- bin/polyphony-debug
|
148
152
|
- bin/stress.rb
|
149
153
|
- bin/test
|
150
|
-
- docs/_config.yml
|
151
|
-
- docs/_includes/head.html
|
152
|
-
- docs/_includes/title.html
|
153
|
-
- docs/_posts/2020-07-26-polyphony-0.44.md
|
154
|
-
- docs/_sass/custom/custom.scss
|
155
|
-
- docs/_sass/overrides.scss
|
156
154
|
- docs/_user-guide/all-about-timers.md
|
157
155
|
- docs/_user-guide/index.md
|
158
156
|
- docs/_user-guide/web-server.md
|
159
|
-
- docs/
|
160
|
-
- docs/
|
161
|
-
- docs/
|
162
|
-
- docs/
|
163
|
-
- docs/api-reference/object.md
|
164
|
-
- docs/api-reference/polyphony-baseexception.md
|
165
|
-
- docs/api-reference/polyphony-cancel.md
|
166
|
-
- docs/api-reference/polyphony-moveon.md
|
167
|
-
- docs/api-reference/polyphony-net.md
|
168
|
-
- docs/api-reference/polyphony-process.md
|
169
|
-
- docs/api-reference/polyphony-resourcepool.md
|
170
|
-
- docs/api-reference/polyphony-restart.md
|
171
|
-
- docs/api-reference/polyphony-terminate.md
|
172
|
-
- docs/api-reference/polyphony-threadpool.md
|
173
|
-
- docs/api-reference/polyphony-throttler.md
|
174
|
-
- docs/api-reference/polyphony.md
|
175
|
-
- docs/api-reference/thread.md
|
176
|
-
- docs/assets/img/echo-fibers.svg
|
177
|
-
- docs/assets/img/sleeping-fiber.svg
|
157
|
+
- docs/concurrency.md
|
158
|
+
- docs/design-principles.md
|
159
|
+
- docs/exception-handling.md
|
160
|
+
- docs/extending.md
|
178
161
|
- docs/faq.md
|
179
|
-
- docs/
|
180
|
-
- docs/getting-started/index.md
|
181
|
-
- docs/getting-started/installing.md
|
182
|
-
- docs/getting-started/overview.md
|
183
|
-
- docs/getting-started/tutorial.md
|
162
|
+
- docs/fiber-scheduling.md
|
184
163
|
- docs/index.md
|
185
|
-
- docs/
|
186
|
-
- docs/main-concepts/design-principles.md
|
187
|
-
- docs/main-concepts/exception-handling.md
|
188
|
-
- docs/main-concepts/extending.md
|
189
|
-
- docs/main-concepts/fiber-scheduling.md
|
164
|
+
- docs/link_rewriter.rb
|
190
165
|
- docs/main-concepts/index.md
|
191
|
-
- docs/
|
166
|
+
- docs/overview.md
|
167
|
+
- docs/tutorial.md
|
168
|
+
- docs/whats-new.md
|
192
169
|
- examples/adapters/pg_client.rb
|
193
170
|
- examples/adapters/pg_notify.rb
|
194
171
|
- examples/adapters/pg_pool.rb
|
@@ -243,6 +220,7 @@ files:
|
|
243
220
|
- examples/io/echo_client_from_stdin.rb
|
244
221
|
- examples/io/echo_pipe.rb
|
245
222
|
- examples/io/echo_server.rb
|
223
|
+
- examples/io/echo_server_plain_ruby.rb
|
246
224
|
- examples/io/echo_server_with_timeout.rb
|
247
225
|
- examples/io/echo_stdin.rb
|
248
226
|
- examples/io/gzip.rb
|
@@ -789,8 +767,7 @@ licenses:
|
|
789
767
|
- MIT
|
790
768
|
metadata:
|
791
769
|
source_code_uri: https://github.com/digital-fabric/polyphony
|
792
|
-
documentation_uri: https://
|
793
|
-
homepage_uri: https://digital-fabric.github.io/polyphony/
|
770
|
+
documentation_uri: https://www.rubydoc.info/gems/polyphony
|
794
771
|
changelog_uri: https://github.com/digital-fabric/polyphony/blob/master/CHANGELOG.md
|
795
772
|
post_install_message:
|
796
773
|
rdoc_options:
|
data/docs/_config.yml
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
title: "Polyphony"
|
2
|
-
description: Fine-grained concurrency for Ruby
|
3
|
-
|
4
|
-
plugins:
|
5
|
-
- jekyll-remote-theme
|
6
|
-
|
7
|
-
permalink: pretty
|
8
|
-
remote_theme: pmarsceill/just-the-docs
|
9
|
-
color_scheme: light
|
10
|
-
|
11
|
-
search_enabled: true
|
12
|
-
search:
|
13
|
-
# Split pages into sections that can be searched individually
|
14
|
-
# Supports 1 - 6, default: 2
|
15
|
-
heading_level: 2
|
16
|
-
# Maximum amount of previews per search result
|
17
|
-
# Default: 3
|
18
|
-
previews: 3
|
19
|
-
# Maximum amount of words to display before a matched word in the preview
|
20
|
-
# Default: 5
|
21
|
-
preview_words_before: 5
|
22
|
-
# Maximum amount of words to display after a matched word in the preview
|
23
|
-
# Default: 10
|
24
|
-
preview_words_after: 10
|
25
|
-
# Set the search token separator
|
26
|
-
# Default: /[\s\-/]+/
|
27
|
-
# Example: enable support for hyphenated search words
|
28
|
-
tokenizer_separator: /[\s/]+/
|
29
|
-
# Display the relative url in search results
|
30
|
-
# Supports true (default) or false
|
31
|
-
rel_url: true
|
32
|
-
# Enable or disable the search button that appears in the bottom right corner of every page
|
33
|
-
# Supports true or false (default)
|
34
|
-
button: false
|
35
|
-
|
36
|
-
aux_links:
|
37
|
-
"Polyphony on GitHub":
|
38
|
-
- "//github.com/digital-fabric/polyphony"
|
39
|
-
|
40
|
-
# Makes Aux links open in a new tab. Default is false
|
41
|
-
aux_links_new_tab: false
|
42
|
-
|
43
|
-
# Enable or disable heading anchors
|
44
|
-
heading_anchors: true
|
45
|
-
|
46
|
-
back_to_top: true
|
47
|
-
back_to_top_text: "Back to top"
|
48
|
-
|
49
|
-
footer_content: "Copyright © 2020 Sharon Rosner. Distributed by an <a href=\"https://github.com/digital-fabric/polyphony/tree/master/LICENSE\">MIT license.</a>"
|
50
|
-
|
51
|
-
# Footer "Edit this page on GitHub" link text
|
52
|
-
gh_edit_link: true # show or hide edit this page link
|
53
|
-
gh_edit_link_text: "Edit this page on GitHub"
|
54
|
-
gh_edit_repository: "https://github.com/digital-fabric/polyphony" # the github URL for your repo
|
55
|
-
gh_edit_branch: "master/docs" # the branch that your docs is served from
|
56
|
-
gh_edit_view_mode: "tree" # "tree" or "edit" if you want the user to jump into the editor immediately
|
57
|
-
|
58
|
-
compress_html:
|
59
|
-
clippings: all
|
60
|
-
comments: all
|
61
|
-
endings: all
|
62
|
-
startings: []
|
63
|
-
blanklines: false
|
64
|
-
profile: false
|
data/docs/_includes/head.html
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
<head>
|
2
|
-
<meta charset="UTF-8">
|
3
|
-
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
|
4
|
-
|
5
|
-
{% unless site.plugins contains "jekyll-seo-tag" %}
|
6
|
-
<title>{{ page.title }} - {{ site.title }}</title>
|
7
|
-
|
8
|
-
{% if page.description %}
|
9
|
-
<meta name="Description" content="{{ page.description }}">
|
10
|
-
{% endif %}
|
11
|
-
{% endunless %}
|
12
|
-
|
13
|
-
<link rel="shortcut icon" href="{{ 'polyphony-logo.png' | absolute_url }}" type="image/png">
|
14
|
-
|
15
|
-
<link rel="stylesheet" href="{{ '/assets/css/just-the-docs-default.css' | absolute_url }}">
|
16
|
-
|
17
|
-
{% if site.ga_tracking != nil %}
|
18
|
-
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.ga_tracking }}"></script>
|
19
|
-
<script>
|
20
|
-
window.dataLayer = window.dataLayer || [];
|
21
|
-
function gtag(){dataLayer.push(arguments);}
|
22
|
-
gtag('js', new Date());
|
23
|
-
|
24
|
-
gtag('config', '{{ site.ga_tracking }}'{% unless site.ga_tracking_anonymize_ip == nil %}, { 'anonymize_ip': true }{% endunless %});
|
25
|
-
</script>
|
26
|
-
|
27
|
-
{% endif %}
|
28
|
-
|
29
|
-
{% if site.search_enabled != false %}
|
30
|
-
<script type="text/javascript" src="{{ '/assets/js/vendor/lunr.min.js' | absolute_url }}"></script>
|
31
|
-
{% endif %}
|
32
|
-
<script type="text/javascript" src="{{ '/assets/js/just-the-docs.js' | absolute_url }}"></script>
|
33
|
-
|
34
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
35
|
-
|
36
|
-
{% seo %}
|
37
|
-
|
38
|
-
{% include head_custom.html %}
|
39
|
-
|
40
|
-
</head>
|
data/docs/_includes/title.html
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
<img src="{{ 'polyphony-logo.png' | absolute_url }}" style="height: 1.5em; margin-right: 0.5em">Polyphony
|
data/docs/_sass/overrides.scss
DELETED
File without changes
|
@@ -1,31 +0,0 @@
|
|
1
|
-
---
|
2
|
-
layout: page
|
3
|
-
title: ::Exception
|
4
|
-
parent: API Reference
|
5
|
-
permalink: /api-reference/exception/
|
6
|
-
source_url: https://github.com/digital-fabric/polyphony/blob/master/lib/polyphony/extensions/core.rb
|
7
|
-
ruby_docs_url: https://rubyapi.org/3.0/o/exception
|
8
|
-
---
|
9
|
-
# ::Exception
|
10
|
-
|
11
|
-
[Ruby core Exception documentation](https://rubyapi.org/3.0/o/exception)
|
12
|
-
|
13
|
-
The core `Exception` class is enhanced to provide a better backtrace that takes
|
14
|
-
into account the fiber hierarchy. In addition, a `source_fiber` attribute allows
|
15
|
-
tracking the fiber from which an uncaught exception was propagated.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
## Class Methods
|
20
|
-
|
21
|
-
## Instance methods
|
22
|
-
|
23
|
-
### #source_fiber → fiber
|
24
|
-
|
25
|
-
Returns the fiber in which the exception occurred. Polyphony sets this attribute
|
26
|
-
only for uncaught exceptions. Currently this attribute is only used in a
|
27
|
-
meaningful way for supervising fibers.
|
28
|
-
|
29
|
-
### #source_fiber=(fiber) → fiber
|
30
|
-
|
31
|
-
Sets the fiber in which the exception occurred.
|