polyphony 0.98 → 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 +11 -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/examples/io/https_server_sni_2.rb +14 -8
- 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 +25 -8
- data/ext/polyphony/fiber.c +79 -2
- data/ext/polyphony/io_extensions.c +53 -0
- data/ext/polyphony/libev.h +0 -2
- 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 +55 -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 +161 -16
- data/lib/polyphony/extensions/kernel.rb +20 -2
- data/lib/polyphony/extensions/openssl.rb +101 -12
- 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_io.rb +6 -7
- data/test/test_socket.rb +157 -0
- data/test/test_sync.rb +42 -1
- data/test/test_timer.rb +5 -5
- data/vendor/liburing/.github/workflows/build.yml +7 -16
- data/vendor/liburing/.gitignore +5 -0
- data/vendor/liburing/CHANGELOG +23 -1
- data/vendor/liburing/Makefile +4 -3
- data/vendor/liburing/Makefile.common +1 -0
- data/vendor/liburing/README +48 -0
- data/vendor/liburing/configure +76 -6
- data/vendor/liburing/debian/changelog +11 -0
- data/vendor/liburing/debian/control +7 -16
- data/vendor/liburing/debian/liburing-dev.manpages +3 -6
- data/vendor/liburing/debian/liburing2.install +1 -0
- data/vendor/liburing/debian/liburing2.symbols +56 -0
- data/vendor/liburing/debian/rules +15 -68
- data/vendor/liburing/examples/Makefile +4 -0
- data/vendor/liburing/examples/io_uring-close-test.c +123 -0
- data/vendor/liburing/examples/io_uring-udp.c +1 -1
- data/vendor/liburing/examples/send-zerocopy.c +315 -56
- data/vendor/liburing/examples/ucontext-cp.c +2 -17
- data/vendor/liburing/liburing-ffi.pc.in +12 -0
- data/vendor/liburing/liburing.pc.in +1 -1
- data/vendor/liburing/liburing.spec +1 -1
- data/vendor/liburing/make-debs.sh +3 -3
- data/vendor/liburing/man/IO_URING_CHECK_VERSION.3 +1 -0
- data/vendor/liburing/man/IO_URING_VERSION_MAJOR.3 +1 -0
- data/vendor/liburing/man/IO_URING_VERSION_MINOR.3 +1 -0
- data/vendor/liburing/man/io_uring_buf_ring_add.3 +6 -6
- data/vendor/liburing/man/io_uring_check_version.3 +72 -0
- data/vendor/liburing/man/io_uring_close_ring_fd.3 +43 -0
- data/vendor/liburing/man/io_uring_major_version.3 +1 -0
- data/vendor/liburing/man/io_uring_minor_version.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_accept.3 +1 -1
- data/vendor/liburing/man/io_uring_prep_fgetxattr.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_fsetxattr.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_getxattr.3 +61 -0
- data/vendor/liburing/man/io_uring_prep_link_timeout.3 +94 -0
- data/vendor/liburing/man/io_uring_prep_msg_ring.3 +22 -2
- data/vendor/liburing/man/io_uring_prep_msg_ring_cqe_flags.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_poll_add.3 +1 -1
- data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +18 -9
- data/vendor/liburing/man/io_uring_prep_readv.3 +3 -3
- data/vendor/liburing/man/io_uring_prep_readv2.3 +3 -3
- data/vendor/liburing/man/io_uring_prep_recv.3 +5 -5
- data/vendor/liburing/man/io_uring_prep_recvmsg.3 +4 -4
- data/vendor/liburing/man/io_uring_prep_send.3 +9 -0
- data/vendor/liburing/man/io_uring_prep_send_set_addr.3 +38 -0
- data/vendor/liburing/man/io_uring_prep_send_zc.3 +39 -7
- data/vendor/liburing/man/io_uring_prep_send_zc_fixed.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_sendmsg.3 +20 -0
- data/vendor/liburing/man/io_uring_prep_sendmsg_zc.3 +1 -0
- data/vendor/liburing/man/io_uring_prep_setxattr.3 +64 -0
- data/vendor/liburing/man/io_uring_prep_splice.3 +40 -0
- data/vendor/liburing/man/io_uring_prep_writev.3 +2 -2
- data/vendor/liburing/man/io_uring_prep_writev2.3 +2 -2
- data/vendor/liburing/man/io_uring_recvmsg_out.3 +13 -9
- data/vendor/liburing/man/io_uring_register.2 +15 -9
- data/vendor/liburing/man/io_uring_register_buf_ring.3 +4 -4
- data/vendor/liburing/man/io_uring_register_buffers.3 +49 -6
- data/vendor/liburing/man/io_uring_register_buffers_sparse.3 +1 -0
- data/vendor/liburing/man/io_uring_register_buffers_tags.3 +1 -0
- data/vendor/liburing/man/io_uring_register_buffers_update_tag.3 +1 -0
- data/vendor/liburing/man/io_uring_register_files.3 +60 -5
- data/vendor/liburing/man/io_uring_register_files_tags.3 +1 -0
- data/vendor/liburing/man/io_uring_register_files_update.3 +1 -0
- data/vendor/liburing/man/io_uring_register_files_update_tag.3 +1 -0
- data/vendor/liburing/man/io_uring_setup.2 +31 -2
- data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +1 -1
- data/vendor/liburing/src/Makefile +25 -3
- data/vendor/liburing/src/ffi.c +15 -0
- data/vendor/liburing/src/include/liburing/io_uring.h +30 -7
- data/vendor/liburing/src/include/liburing.h +190 -148
- data/vendor/liburing/src/int_flags.h +1 -0
- data/vendor/liburing/src/lib.h +5 -16
- data/vendor/liburing/src/liburing-ffi.map +172 -0
- data/vendor/liburing/src/liburing.map +11 -0
- data/vendor/liburing/src/nolibc.c +9 -2
- data/vendor/liburing/src/queue.c +2 -2
- data/vendor/liburing/src/register.c +66 -96
- data/vendor/liburing/src/setup.c +5 -4
- data/vendor/liburing/src/version.c +21 -0
- data/vendor/liburing/test/232c93d07b74.c +3 -3
- data/vendor/liburing/test/35fa71a030ca.c +3 -3
- data/vendor/liburing/test/500f9fbadef8.c +2 -0
- data/vendor/liburing/test/917257daa0fe.c +1 -1
- data/vendor/liburing/test/Makefile +27 -7
- data/vendor/liburing/test/a0908ae19763.c +2 -2
- data/vendor/liburing/test/a4c0b3decb33.c +2 -2
- data/vendor/liburing/test/accept-link.c +4 -4
- data/vendor/liburing/test/accept-reuse.c +5 -7
- data/vendor/liburing/test/accept.c +34 -31
- data/vendor/liburing/test/b19062a56726.c +1 -1
- data/vendor/liburing/test/buf-ring.c +58 -4
- data/vendor/liburing/test/ce593a6c480a.c +2 -2
- data/vendor/liburing/test/close-opath.c +2 -1
- data/vendor/liburing/test/connect.c +8 -0
- data/vendor/liburing/test/cq-overflow.c +14 -8
- data/vendor/liburing/test/d4ae271dfaae.c +1 -1
- data/vendor/liburing/test/defer-taskrun.c +64 -9
- data/vendor/liburing/test/defer.c +1 -1
- data/vendor/liburing/test/double-poll-crash.c +3 -3
- data/vendor/liburing/test/eeed8b54e0df.c +8 -3
- data/vendor/liburing/test/eploop.c +74 -0
- data/vendor/liburing/test/eventfd-ring.c +1 -1
- data/vendor/liburing/test/eventfd.c +1 -1
- data/vendor/liburing/test/evloop.c +73 -0
- data/vendor/liburing/test/exit-no-cleanup.c +1 -1
- data/vendor/liburing/test/fadvise.c +1 -1
- data/vendor/liburing/test/fc2a85cb02ef.c +3 -3
- data/vendor/liburing/test/fd-pass.c +35 -16
- data/vendor/liburing/test/file-register.c +61 -0
- data/vendor/liburing/test/file-verify.c +2 -2
- data/vendor/liburing/test/files-exit-hang-timeout.c +2 -2
- data/vendor/liburing/test/fixed-link.c +1 -1
- data/vendor/liburing/test/fsnotify.c +118 -0
- data/vendor/liburing/test/hardlink.c +1 -1
- data/vendor/liburing/test/helpers.c +54 -2
- data/vendor/liburing/test/helpers.h +4 -0
- data/vendor/liburing/test/io-cancel.c +3 -1
- data/vendor/liburing/test/io_uring_passthrough.c +39 -8
- data/vendor/liburing/test/io_uring_setup.c +3 -80
- data/vendor/liburing/test/iopoll-overflow.c +118 -0
- data/vendor/liburing/test/iopoll.c +90 -4
- data/vendor/liburing/test/lfs-openat-write.c +7 -9
- data/vendor/liburing/test/lfs-openat.c +6 -8
- data/vendor/liburing/test/link_drain.c +31 -5
- data/vendor/liburing/test/madvise.c +1 -1
- data/vendor/liburing/test/msg-ring-flags.c +192 -0
- data/vendor/liburing/test/msg-ring-overflow.c +159 -0
- data/vendor/liburing/test/msg-ring.c +173 -13
- data/vendor/liburing/test/multicqes_drain.c +22 -19
- data/vendor/liburing/test/nvme.h +4 -3
- data/vendor/liburing/test/pipe-bug.c +95 -0
- data/vendor/liburing/test/poll-link.c +3 -3
- data/vendor/liburing/test/poll-many.c +41 -19
- data/vendor/liburing/test/poll-mshot-overflow.c +105 -2
- data/vendor/liburing/test/poll-race-mshot.c +292 -0
- data/vendor/liburing/test/poll-race.c +105 -0
- data/vendor/liburing/test/poll.c +244 -26
- data/vendor/liburing/test/pollfree.c +5 -5
- data/vendor/liburing/test/read-before-exit.c +20 -3
- data/vendor/liburing/test/read-write.c +2 -0
- data/vendor/liburing/test/recv-multishot.c +96 -3
- data/vendor/liburing/test/reg-reg-ring.c +90 -0
- data/vendor/liburing/test/rename.c +1 -1
- data/vendor/liburing/test/ring-leak.c +0 -1
- data/vendor/liburing/test/ring-leak2.c +1 -1
- data/vendor/liburing/test/ringbuf-read.c +10 -6
- data/vendor/liburing/test/send-zerocopy.c +273 -103
- data/vendor/liburing/test/send_recv.c +7 -4
- data/vendor/liburing/test/sendmsg_fs_cve.c +2 -2
- data/vendor/liburing/test/single-issuer.c +7 -9
- data/vendor/liburing/test/skip-cqe.c +3 -4
- data/vendor/liburing/test/socket.c +0 -1
- data/vendor/liburing/test/sq-poll-dup.c +10 -3
- data/vendor/liburing/test/sq-poll-kthread.c +1 -1
- data/vendor/liburing/test/sq-poll-share.c +3 -2
- data/vendor/liburing/test/sqpoll-cancel-hang.c +17 -6
- data/vendor/liburing/test/sqpoll-disable-exit.c +4 -4
- data/vendor/liburing/test/symlink.c +2 -1
- data/vendor/liburing/test/test.h +2 -1
- data/vendor/liburing/test/timeout-new.c +11 -7
- data/vendor/liburing/test/timeout.c +1 -2
- data/vendor/liburing/test/unlink.c +1 -1
- data/vendor/liburing/test/version.c +25 -0
- data/vendor/liburing/test/wakeup-hang.c +1 -1
- data/vendor/liburing/test/xattr.c +8 -4
- metadata +57 -44
- 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/vendor/liburing/debian/compat +0 -1
- data/vendor/liburing/debian/liburing1-udeb.install +0 -1
- data/vendor/liburing/debian/liburing1.install +0 -1
- data/vendor/liburing/debian/liburing1.symbols +0 -32
- /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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f9f6713f2080b0ad929afc680c52a88ad737701575c30433e9ec4c759258dd7
|
4
|
+
data.tar.gz: c7f3fd09e72c34269624d52d8dc77e9f5645cfa2d65743afe51e07db850598e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3472d5ffee0ce36370701c98d28d33d9c76e7ac21a6635e4dff063a6d28e313cd518290dbd0904c496ec29471cab39922daf2473f6b9a168588d0ef861f5ff2
|
7
|
+
data.tar.gz: 2a230e7c9b2a95e24992d4a844b92a7af243da5113f355945ce8f585a415dafbde0e2f1fe2fcd1ba434bda94992a3cdf906e37ab78c01caa355e131c8103c87b
|
data/.github/FUNDING.yml
CHANGED
@@ -1 +1 @@
|
|
1
|
-
github:
|
1
|
+
github: noteflakes
|
data/.rubocop.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2
|
2
|
+
TargetRubyVersion: 3.2
|
3
3
|
RubyInterpreters:
|
4
4
|
- ruby
|
5
5
|
Exclude:
|
@@ -49,7 +49,7 @@ Style/NumericPredicate:
|
|
49
49
|
Style/TrivialAccessors:
|
50
50
|
Enabled: false
|
51
51
|
|
52
|
-
|
52
|
+
Lint/MissingSuper:
|
53
53
|
Enabled: false
|
54
54
|
|
55
55
|
Style/GlobalVars:
|
@@ -90,7 +90,7 @@ Metrics/MethodLength:
|
|
90
90
|
|
91
91
|
Metrics/ModuleLength:
|
92
92
|
Exclude:
|
93
|
-
- lib/polyphony/
|
93
|
+
- lib/polyphony/core/global_api.rb
|
94
94
|
- examples/**/*.rb
|
95
95
|
|
96
96
|
Metrics/ClassLength:
|
data/.yardopts
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
-o ./_yardoc
|
2
|
+
-m markdown -M redcarpet
|
3
|
+
--verbose
|
4
|
+
--protected
|
5
|
+
--no-private
|
6
|
+
--asset assets/:assets
|
7
|
+
--exclude debugger.rb
|
8
|
+
--exclude redis.rb
|
9
|
+
--exclude readline.rb
|
10
|
+
--exclude postgres.rb
|
11
|
+
--exclude zlib_conf.rb
|
12
|
+
--exclude extconf.rb
|
13
|
+
--exclude mysql2.rb
|
14
|
+
--exclude sequel.rb
|
15
|
+
--exclude event.c
|
16
|
+
--exclude backend.+\.c
|
17
|
+
--load ./docs/link_rewriter.rb
|
18
|
+
./lib
|
19
|
+
./ext/polyphony
|
20
|
+
-
|
21
|
+
docs/overview.md
|
22
|
+
docs/tutorial.md
|
23
|
+
docs/faq.md
|
24
|
+
docs/concurrency.md
|
25
|
+
docs/fiber-scheduling.md
|
26
|
+
docs/exception-handling.md
|
27
|
+
docs/extending.md
|
28
|
+
docs/design-principles.md
|
29
|
+
CHANGELOG.md
|
30
|
+
LICENSE
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
## 0.99.1 2023-05-08
|
2
|
+
|
3
|
+
- Reorganize docs, use Yard for all docs.
|
4
|
+
|
5
|
+
## 0.99 2023-03-09
|
6
|
+
|
7
|
+
- Add missing Mutex API methods (#76)
|
8
|
+
- Fix `IO.foreach` and `IO#each_line` (#74)
|
9
|
+
- Fix `SSLServer#accept_loop` (#59)
|
10
|
+
- Update liburing
|
11
|
+
|
1
12
|
## 0.98 2023-03-08
|
2
13
|
|
3
14
|
- Add basic support for UDP sockets
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,26 @@
|
|
1
|
-
<
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<
|
13
|
-
|
14
|
-
<img src="https://badge.fury.io/rb/polyphony.svg" alt="Ruby gem">
|
15
|
-
</a>
|
16
|
-
<a href="https://github.com/digital-fabric/polyphony/actions?query=workflow%3ATests">
|
17
|
-
<img src="https://github.com/digital-fabric/polyphony/workflows/Tests/badge.svg" alt="Tests">
|
18
|
-
</a>
|
19
|
-
<a href="https://github.com/digital-fabric/polyphony/blob/master/LICENSE">
|
20
|
-
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License">
|
21
|
-
</a>
|
22
|
-
</p>
|
23
|
-
|
24
|
-
[DOCS](https://digital-fabric.github.io/polyphony/) |
|
25
|
-
[EXAMPLES](examples)
|
1
|
+
<img src="assets/polyphony-logo.png" alt="Polyphony">
|
2
|
+
|
3
|
+
# Polyphony: Fine-Grained Concurrency for Ruby
|
4
|
+
|
5
|
+
<a href="http://rubygems.org/gems/polyphony">
|
6
|
+
<img src="https://badge.fury.io/rb/polyphony.svg" alt="Ruby gem">
|
7
|
+
</a>
|
8
|
+
<a href="https://github.com/digital-fabric/polyphony/actions?query=workflow%3ATests">
|
9
|
+
<img src="https://github.com/digital-fabric/polyphony/workflows/Tests/badge.svg" alt="Tests">
|
10
|
+
</a>
|
11
|
+
<a href="https://github.com/digital-fabric/polyphony/blob/master/LICENSE">
|
12
|
+
<img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT License">
|
13
|
+
</a>
|
26
14
|
|
27
15
|
> Polyphony \| pəˈlɪf\(ə\)ni \|
|
16
|
+
>
|
28
17
|
> 1. _Music_ the style of simultaneously combining a number of parts, each
|
29
18
|
> forming an individual melody and harmonizing with each other.
|
19
|
+
>
|
30
20
|
> 2. _Programming_ a Ruby gem for concurrent programming focusing on performance
|
31
21
|
> and developer happiness.
|
32
22
|
|
33
|
-
## What is Polyphony
|
23
|
+
## What is Polyphony?
|
34
24
|
|
35
25
|
Polyphony is a library for building concurrent applications in Ruby. Polyphony
|
36
26
|
harnesses the power of [Ruby fibers](https://ruby-doc.org/core-2.5.1/Fiber.html)
|
@@ -54,10 +44,54 @@ the hood, Polyphony uses
|
|
54
44
|
* Competitive performance and scalability characteristics, in terms of both
|
55
45
|
throughput and memory consumption.
|
56
46
|
|
57
|
-
##
|
47
|
+
## Installing
|
48
|
+
|
49
|
+
### System Requirements
|
50
|
+
|
51
|
+
In order to use Polyphony you need to have:
|
52
|
+
|
53
|
+
- Linux or MacOS (support for Windows will come at a later stage)
|
54
|
+
- Ruby (MRI) 3.0 or newer
|
55
|
+
|
56
|
+
### Installing the Polyphony Gem
|
57
|
+
|
58
|
+
Add this line to your application's Gemfile:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
gem 'polyphony'
|
62
|
+
```
|
63
|
+
|
64
|
+
And then execute:
|
65
|
+
|
66
|
+
```bash
|
67
|
+
$ bundle
|
68
|
+
```
|
69
|
+
|
70
|
+
Or install it yourself as:
|
71
|
+
|
72
|
+
```bash
|
73
|
+
$ gem install polyphony
|
74
|
+
```
|
75
|
+
|
76
|
+
## Usage
|
77
|
+
|
78
|
+
- [Overview](docs/overview.md)
|
79
|
+
- [Tutorial](docs/tutorial.md)
|
80
|
+
- [FAQ](docs/faq.md)
|
81
|
+
|
82
|
+
## Technical Discussion
|
83
|
+
|
84
|
+
- [Concurrency the Easy Way](docs/concurrency.md)
|
85
|
+
- [How Fibers are Scheduled](docs/fiber-scheduling.md)
|
86
|
+
- [Exception Handling](docs/exception-handling.md)
|
87
|
+
- [Extending Polyphony](docs/extending.md)
|
88
|
+
- [Polyphony's Design](docs/design-principles.md)
|
89
|
+
|
90
|
+
## Examples
|
58
91
|
|
59
|
-
|
60
|
-
|
92
|
+
For examples of specific use cases you can consult the [bundled
|
93
|
+
examples](https://github.com/digital-fabric/polyphony/tree/master/examples) in
|
94
|
+
Polyphony's GitHub repository.
|
61
95
|
|
62
96
|
## Contributing to Polyphony
|
63
97
|
|
data/Rakefile
CHANGED
@@ -19,16 +19,12 @@ task :stress_test do
|
|
19
19
|
exec 'ruby test/stress.rb'
|
20
20
|
end
|
21
21
|
|
22
|
-
task :docs do
|
23
|
-
exec 'RUBYOPT=-W0 jekyll serve -s docs -H ec2-18-156-117-172.eu-central-1.compute.amazonaws.com'
|
24
|
-
end
|
25
|
-
|
26
22
|
CLEAN.include "**/*.o", "**/*.so", "**/*.so.*", "**/*.a", "**/*.bundle", "**/*.jar", "pkg", "tmp"
|
27
23
|
|
28
24
|
task :release do
|
29
25
|
require_relative './lib/polyphony/version'
|
30
26
|
version = Polyphony::VERSION
|
31
|
-
|
27
|
+
|
32
28
|
puts 'Building polyphony...'
|
33
29
|
`gem build polyphony.gemspec`
|
34
30
|
|
data/TODO.md
CHANGED
@@ -11,9 +11,6 @@
|
|
11
11
|
- Add support for IPv6:
|
12
12
|
https://www.reddit.com/r/ruby/comments/lyen23/understanding_ipv6_and_why_its_important_to_you/
|
13
13
|
|
14
|
-
- Add support for UDP sockets
|
15
|
-
|
16
|
-
- Check segfault when resetting a `cancel_after` timeout lots of times at very high rate
|
17
14
|
- Check why `throttled_loop` inside of `move_on_after` fails to stop
|
18
15
|
|
19
16
|
- Override stock `::SizedQueue` impl with Queue with capacity
|
@@ -165,7 +162,6 @@
|
|
165
162
|
- test performance
|
166
163
|
- proceed from there
|
167
164
|
|
168
|
-
|
169
165
|
### Sinatra / Sidekiq
|
170
166
|
|
171
167
|
- Pull out redis/postgres code, put into new `polyphony-xxx` gems
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Concurrency the Easy Way
|
4
|
-
nav_order: 1
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/concurrency/
|
7
|
-
prev_title: Tutorial
|
8
|
-
next_title: How Fibers are Scheduled
|
9
|
-
---
|
1
|
+
# @title Concurrency the Easy Way
|
2
|
+
|
10
3
|
# Concurrency the Easy Way
|
11
4
|
|
12
5
|
Concurrency is a major consideration for modern programmers. Applications and
|
@@ -1,12 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
nav_order: 5
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/design-principles/
|
7
|
-
prev_title: Extending Polyphony
|
8
|
-
---
|
9
|
-
# The Design of Polyphony
|
1
|
+
# @title Polyphony's Design
|
2
|
+
|
3
|
+
# Polyphony's Design
|
10
4
|
|
11
5
|
Polyphony is a new gem that aims to enable developing high-performance
|
12
6
|
concurrent applications in Ruby using a fluent, compact syntax and API.
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Exception Handling
|
4
|
-
nav_order: 3
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/exception-handling/
|
7
|
-
prev_title: How Fibers are Scheduled
|
8
|
-
next_title: Extending Polyphony
|
9
|
-
---
|
1
|
+
# @title Exception Handling
|
2
|
+
|
10
3
|
# Exception Handling
|
11
4
|
|
12
5
|
Ruby employs a pretty robust exception handling mechanism. An raised exception
|
@@ -1,12 +1,5 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
title: Extending Polyphony
|
4
|
-
nav_order: 4
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/extending/
|
7
|
-
prev_title: Exception Handling
|
8
|
-
next_title: The Design of Polyphony
|
9
|
-
---
|
1
|
+
# @title Extending Polyphony
|
2
|
+
|
10
3
|
# Extending Polyphony
|
11
4
|
|
12
5
|
Polyphony was designed to ease the transition from blocking APIs and
|
data/docs/faq.md
CHANGED
@@ -1,19 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Frequently Asked Questions
|
4
|
-
nav_order: 100
|
5
|
-
---
|
1
|
+
# @title FAQ
|
6
2
|
|
7
3
|
# Frequently Asked Questions
|
8
|
-
{: .no_toc }
|
9
|
-
|
10
|
-
## Table of contents
|
11
|
-
{: .no_toc .text-delta }
|
12
|
-
|
13
|
-
- TOC
|
14
|
-
{:toc}
|
15
|
-
|
16
|
-
---
|
17
4
|
|
18
5
|
## Why not just use callbacks instead of fibers?
|
19
6
|
|
@@ -191,5 +178,5 @@ Feel free to create issues and contribute pull requests.
|
|
191
178
|
## Who is behind this project?
|
192
179
|
|
193
180
|
I'm Sharon Rosner, an independent software developer living in France. Here's my
|
194
|
-
[github profile](https://github.com/
|
195
|
-
[noteflakes
|
181
|
+
[github profile](https://github.com/noteflakes). You can contact me by writing to
|
182
|
+
[sharon@noteflakes.com](mailto:sharon@noteflakes.com).
|
@@ -1,12 +1,4 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: How Fibers are Scheduled
|
4
|
-
nav_order: 2
|
5
|
-
parent: Main Concepts
|
6
|
-
permalink: /main-concepts/fiber-scheduling/
|
7
|
-
prev_title: Concurrency the Easy Way
|
8
|
-
next_title: Exception Handling
|
9
|
-
---
|
1
|
+
# @title How Fibers are Scheduled
|
10
2
|
|
11
3
|
# How Fibers are Scheduled
|
12
4
|
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'yard'
|
2
|
+
|
3
|
+
# shamelessly copied from https://github.com/troessner/reek/blob/master/docs/yard_plugin.rb
|
4
|
+
|
5
|
+
# Template helper to modify processing of links in HTML generated from our
|
6
|
+
# markdown files.
|
7
|
+
module LocalLinkHelper
|
8
|
+
# Rewrites links to (assumed local) markdown files so they're processed as
|
9
|
+
# {file: } directives.
|
10
|
+
def resolve_links(text)
|
11
|
+
text = text.gsub(%r{<a href="(docs/[^"]*.md)">([^<]*)</a>}, '{file:/\1 \2}')
|
12
|
+
super text
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
YARD::Templates::Template.extra_includes << LocalLinkHelper
|
@@ -1,20 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Overview
|
4
|
-
parent: Getting Started
|
5
|
-
nav_order: 2
|
6
|
-
---
|
1
|
+
# @title Overview
|
7
2
|
|
8
3
|
# Polyphony - an Overview
|
9
|
-
{: .no_toc }
|
10
|
-
|
11
|
-
## Table of contents
|
12
|
-
{: .no_toc .text-delta }
|
13
|
-
|
14
|
-
- TOC
|
15
|
-
{:toc}
|
16
|
-
|
17
|
-
---
|
18
4
|
|
19
5
|
## Introduction
|
20
6
|
|
@@ -34,21 +20,6 @@ support for HTTP 1 & 2, WebSockets, TLS/SSL termination and more. Polyphony also
|
|
34
20
|
provides fiber-aware adapters for connecting to PostgreSQL and Redis servers.
|
35
21
|
More adapters are being actively developed.
|
36
22
|
|
37
|
-
### Features
|
38
|
-
{: .no_toc }
|
39
|
-
|
40
|
-
- Co-operative scheduling of concurrent tasks using Ruby fibers.
|
41
|
-
- High-performance event reactor for handling I/O, timer, and other events.
|
42
|
-
- Natural, sequential programming style that makes it easy to reason about
|
43
|
-
concurrent code.
|
44
|
-
- Abstractions and constructs for controlling the execution of concurrent code:
|
45
|
-
supervisors, cancel scopes, throttling, resource pools etc.
|
46
|
-
- Code can use native networking classes and libraries, growing support for
|
47
|
-
third-party gems such as pg and redis.
|
48
|
-
- Use stdlib classes such as TCPServer and TCPSocket and Net::HTTP.
|
49
|
-
- Impressive performance and scalability characteristics, in terms of both
|
50
|
-
throughput and memory consumption (see below)
|
51
|
-
|
52
23
|
## Taking Polyphony for a Spin
|
53
24
|
|
54
25
|
Polyphony is different from other reactor-based solutions for Ruby in that
|
@@ -1,20 +1,6 @@
|
|
1
|
-
|
2
|
-
layout: page
|
3
|
-
title: Tutorial
|
4
|
-
parent: Getting Started
|
5
|
-
nav_order: 3
|
6
|
-
---
|
1
|
+
# @title Tutorial
|
7
2
|
|
8
3
|
# Tutorial
|
9
|
-
{: .no_toc }
|
10
|
-
|
11
|
-
## Table of contents
|
12
|
-
{: .no_toc .text-delta }
|
13
|
-
|
14
|
-
- TOC
|
15
|
-
{:toc}
|
16
|
-
|
17
|
-
---
|
18
4
|
|
19
5
|
Polyphony is a new Ruby library aimed at making writing concurrent Ruby apps
|
20
6
|
easy and fun. In this article, we'll introduce Polyphony's fiber-based
|
@@ -108,7 +94,7 @@ The above program does nothing exceptional, it just sleeps for 1 second and
|
|
108
94
|
prints a bunch of messages. But it is enough to demonstrate how concurrency
|
109
95
|
works in Polyphony. Here's a flow chart of the transfer of control:
|
110
96
|
|
111
|
-
<
|
97
|
+
<img src="../assets/sleeping-fiber.svg">
|
112
98
|
|
113
99
|
Here's the actual sequence of execution (in pseudo-code)
|
114
100
|
|
@@ -203,7 +189,7 @@ innocent call to `#spin`.
|
|
203
189
|
|
204
190
|
Here's a flow chart showing the transfer of control between the different fibers:
|
205
191
|
|
206
|
-
<
|
192
|
+
<img src="../assets/echo-fibers.svg">
|
207
193
|
|
208
194
|
Let's consider the advantage of the Polyphony concurrency model:
|
209
195
|
|
@@ -346,14 +332,3 @@ Polyphony currently provides support for any library that uses Ruby's stock
|
|
346
332
|
`redis` and `irb` gems. It also includes an implementation of an integrated HTTP
|
347
333
|
1 / HTTP 2 / websockets web server with support for TLS termination, ALPN
|
348
334
|
protocol selection and preliminary rack support.
|
349
|
-
|
350
|
-
## Fibers are the Future!
|
351
|
-
|
352
|
-
Implementing concurrency at the level of fibers opens up so many new
|
353
|
-
possibilities for Ruby. Polyphony has the performance characteristics and
|
354
|
-
provides the necessary tools for transforming how concurrent Ruby apps are
|
355
|
-
written. Polyphony is still new, and the present documentation is far from being
|
356
|
-
complete. To learn more about Polyphony, read the [technical
|
357
|
-
overview](../../main-concepts/design-principles/). For more examples please
|
358
|
-
consult the [Github
|
359
|
-
repository](https://github.com/digital-fabric/polyphony/tree/master/examples).
|
data/examples/io/echo_server.rb
CHANGED
@@ -5,8 +5,8 @@ require 'polyphony'
|
|
5
5
|
|
6
6
|
spin_loop(interval: 5) { p Thread.backend.stats }
|
7
7
|
|
8
|
-
server = TCPServer.open('127.0.0.1', 1234)
|
9
8
|
puts "Pid: #{Process.pid}"
|
9
|
+
server = TCPServer.open('127.0.0.1', 1234)
|
10
10
|
puts 'Echoing on port 1234...'
|
11
11
|
begin
|
12
12
|
while (client = server.accept)
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
puts "Pid: #{Process.pid}"
|
6
|
+
server = TCPServer.open('127.0.0.1', 1234)
|
7
|
+
puts 'Echoing on port 1234...'
|
8
|
+
begin
|
9
|
+
while (client = server.accept)
|
10
|
+
Thread.new do
|
11
|
+
while (data = client.gets)
|
12
|
+
# client.send("you said: #{data.chomp}!\n", 0)
|
13
|
+
client.write('you said: ', data.chomp, "!\n")
|
14
|
+
end
|
15
|
+
rescue Errno::ECONNRESET
|
16
|
+
'Connection reset...'
|
17
|
+
ensure
|
18
|
+
puts "Closing client socket"
|
19
|
+
client.shutdown
|
20
|
+
client.close
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ensure
|
24
|
+
puts "Closing server"
|
25
|
+
server.close
|
26
|
+
end
|
@@ -27,15 +27,21 @@ server = Polyphony::Net.tcp_listen('localhost', 1234, opts)
|
|
27
27
|
|
28
28
|
puts 'Serving HTTPS on port 1234'
|
29
29
|
|
30
|
-
|
31
|
-
server.accept_loop do |socket|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
begin
|
31
|
+
server.accept_loop(false) do |socket|
|
32
|
+
spin do
|
33
|
+
while (data = socket.gets("\n", 8192))
|
34
|
+
if data.chomp.empty?
|
35
|
+
socket << "HTTP/1.1 200 OK\nConnection: close\nContent-Length: 4\n\nfoo\n"
|
36
|
+
break
|
37
|
+
end
|
38
38
|
end
|
39
|
+
rescue OpenSSL::SSL::SSLError
|
40
|
+
# ignore
|
39
41
|
end
|
40
42
|
end
|
43
|
+
rescue => e
|
44
|
+
puts '*' * 40
|
45
|
+
p e
|
46
|
+
puts e.backtrace.join("\n")
|
41
47
|
end
|