polyphony 0.98 → 0.99.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/.github/FUNDING.yml +1 -1
  3. data/.rubocop.yml +3 -3
  4. data/.yardopts +30 -0
  5. data/CHANGELOG.md +11 -0
  6. data/LICENSE +1 -1
  7. data/README.md +63 -29
  8. data/Rakefile +1 -5
  9. data/TODO.md +0 -4
  10. data/docs/{main-concepts/concurrency.md → concurrency.md} +2 -9
  11. data/docs/{main-concepts/design-principles.md → design-principles.md} +3 -9
  12. data/docs/{main-concepts/exception-handling.md → exception-handling.md} +2 -9
  13. data/docs/{main-concepts/extending.md → extending.md} +2 -9
  14. data/docs/faq.md +3 -16
  15. data/docs/{main-concepts/fiber-scheduling.md → fiber-scheduling.md} +1 -9
  16. data/docs/link_rewriter.rb +16 -0
  17. data/docs/{getting-started/overview.md → overview.md} +1 -30
  18. data/docs/{getting-started/tutorial.md → tutorial.md} +3 -28
  19. data/docs/{_posts/2020-07-26-polyphony-0.44.md → whats-new.md} +3 -1
  20. data/examples/adapters/redis_client.rb +3 -2
  21. data/examples/io/echo_server.rb +1 -1
  22. data/examples/io/echo_server_plain_ruby.rb +26 -0
  23. data/examples/io/https_server_sni_2.rb +14 -8
  24. data/ext/polyphony/backend_io_uring.c +154 -9
  25. data/ext/polyphony/backend_io_uring_context.c +21 -12
  26. data/ext/polyphony/backend_io_uring_context.h +12 -7
  27. data/ext/polyphony/backend_libev.c +1 -1
  28. data/ext/polyphony/extconf.rb +25 -8
  29. data/ext/polyphony/fiber.c +79 -2
  30. data/ext/polyphony/io_extensions.c +53 -0
  31. data/ext/polyphony/libev.h +0 -2
  32. data/ext/polyphony/pipe.c +42 -2
  33. data/ext/polyphony/polyphony.c +345 -31
  34. data/ext/polyphony/polyphony.h +9 -2
  35. data/ext/polyphony/queue.c +181 -0
  36. data/ext/polyphony/ring_buffer.c +0 -1
  37. data/ext/polyphony/runqueue.c +8 -1
  38. data/ext/polyphony/runqueue_ring_buffer.c +13 -0
  39. data/ext/polyphony/runqueue_ring_buffer.h +2 -1
  40. data/ext/polyphony/socket_extensions.c +6 -0
  41. data/ext/polyphony/thread.c +34 -2
  42. data/lib/polyphony/adapters/process.rb +11 -1
  43. data/lib/polyphony/adapters/sequel.rb +1 -1
  44. data/lib/polyphony/core/channel.rb +2 -0
  45. data/lib/polyphony/core/debug.rb +1 -1
  46. data/lib/polyphony/core/global_api.rb +25 -24
  47. data/lib/polyphony/core/resource_pool.rb +7 -6
  48. data/lib/polyphony/core/sync.rb +55 -2
  49. data/lib/polyphony/core/thread_pool.rb +3 -3
  50. data/lib/polyphony/core/timer.rb +8 -8
  51. data/lib/polyphony/extensions/exception.rb +2 -0
  52. data/lib/polyphony/extensions/fiber.rb +15 -13
  53. data/lib/polyphony/extensions/io.rb +161 -16
  54. data/lib/polyphony/extensions/kernel.rb +20 -2
  55. data/lib/polyphony/extensions/openssl.rb +101 -12
  56. data/lib/polyphony/extensions/pipe.rb +103 -7
  57. data/lib/polyphony/extensions/process.rb +13 -1
  58. data/lib/polyphony/extensions/socket.rb +93 -27
  59. data/lib/polyphony/extensions/thread.rb +9 -1
  60. data/lib/polyphony/extensions/timeout.rb +1 -1
  61. data/lib/polyphony/version.rb +2 -1
  62. data/lib/polyphony.rb +27 -7
  63. data/polyphony.gemspec +1 -8
  64. data/test/stress.rb +1 -1
  65. data/test/test_global_api.rb +45 -7
  66. data/test/test_io.rb +6 -7
  67. data/test/test_socket.rb +157 -0
  68. data/test/test_sync.rb +42 -1
  69. data/test/test_timer.rb +5 -5
  70. data/vendor/liburing/.github/workflows/build.yml +7 -16
  71. data/vendor/liburing/.gitignore +5 -0
  72. data/vendor/liburing/CHANGELOG +23 -1
  73. data/vendor/liburing/Makefile +4 -3
  74. data/vendor/liburing/Makefile.common +1 -0
  75. data/vendor/liburing/README +48 -0
  76. data/vendor/liburing/configure +76 -6
  77. data/vendor/liburing/debian/changelog +11 -0
  78. data/vendor/liburing/debian/control +7 -16
  79. data/vendor/liburing/debian/liburing-dev.manpages +3 -6
  80. data/vendor/liburing/debian/liburing2.install +1 -0
  81. data/vendor/liburing/debian/liburing2.symbols +56 -0
  82. data/vendor/liburing/debian/rules +15 -68
  83. data/vendor/liburing/examples/Makefile +4 -0
  84. data/vendor/liburing/examples/io_uring-close-test.c +123 -0
  85. data/vendor/liburing/examples/io_uring-udp.c +1 -1
  86. data/vendor/liburing/examples/send-zerocopy.c +315 -56
  87. data/vendor/liburing/examples/ucontext-cp.c +2 -17
  88. data/vendor/liburing/liburing-ffi.pc.in +12 -0
  89. data/vendor/liburing/liburing.pc.in +1 -1
  90. data/vendor/liburing/liburing.spec +1 -1
  91. data/vendor/liburing/make-debs.sh +3 -3
  92. data/vendor/liburing/man/IO_URING_CHECK_VERSION.3 +1 -0
  93. data/vendor/liburing/man/IO_URING_VERSION_MAJOR.3 +1 -0
  94. data/vendor/liburing/man/IO_URING_VERSION_MINOR.3 +1 -0
  95. data/vendor/liburing/man/io_uring_buf_ring_add.3 +6 -6
  96. data/vendor/liburing/man/io_uring_check_version.3 +72 -0
  97. data/vendor/liburing/man/io_uring_close_ring_fd.3 +43 -0
  98. data/vendor/liburing/man/io_uring_major_version.3 +1 -0
  99. data/vendor/liburing/man/io_uring_minor_version.3 +1 -0
  100. data/vendor/liburing/man/io_uring_prep_accept.3 +1 -1
  101. data/vendor/liburing/man/io_uring_prep_fgetxattr.3 +1 -0
  102. data/vendor/liburing/man/io_uring_prep_fsetxattr.3 +1 -0
  103. data/vendor/liburing/man/io_uring_prep_getxattr.3 +61 -0
  104. data/vendor/liburing/man/io_uring_prep_link_timeout.3 +94 -0
  105. data/vendor/liburing/man/io_uring_prep_msg_ring.3 +22 -2
  106. data/vendor/liburing/man/io_uring_prep_msg_ring_cqe_flags.3 +1 -0
  107. data/vendor/liburing/man/io_uring_prep_poll_add.3 +1 -1
  108. data/vendor/liburing/man/io_uring_prep_provide_buffers.3 +18 -9
  109. data/vendor/liburing/man/io_uring_prep_readv.3 +3 -3
  110. data/vendor/liburing/man/io_uring_prep_readv2.3 +3 -3
  111. data/vendor/liburing/man/io_uring_prep_recv.3 +5 -5
  112. data/vendor/liburing/man/io_uring_prep_recvmsg.3 +4 -4
  113. data/vendor/liburing/man/io_uring_prep_send.3 +9 -0
  114. data/vendor/liburing/man/io_uring_prep_send_set_addr.3 +38 -0
  115. data/vendor/liburing/man/io_uring_prep_send_zc.3 +39 -7
  116. data/vendor/liburing/man/io_uring_prep_send_zc_fixed.3 +1 -0
  117. data/vendor/liburing/man/io_uring_prep_sendmsg.3 +20 -0
  118. data/vendor/liburing/man/io_uring_prep_sendmsg_zc.3 +1 -0
  119. data/vendor/liburing/man/io_uring_prep_setxattr.3 +64 -0
  120. data/vendor/liburing/man/io_uring_prep_splice.3 +40 -0
  121. data/vendor/liburing/man/io_uring_prep_writev.3 +2 -2
  122. data/vendor/liburing/man/io_uring_prep_writev2.3 +2 -2
  123. data/vendor/liburing/man/io_uring_recvmsg_out.3 +13 -9
  124. data/vendor/liburing/man/io_uring_register.2 +15 -9
  125. data/vendor/liburing/man/io_uring_register_buf_ring.3 +4 -4
  126. data/vendor/liburing/man/io_uring_register_buffers.3 +49 -6
  127. data/vendor/liburing/man/io_uring_register_buffers_sparse.3 +1 -0
  128. data/vendor/liburing/man/io_uring_register_buffers_tags.3 +1 -0
  129. data/vendor/liburing/man/io_uring_register_buffers_update_tag.3 +1 -0
  130. data/vendor/liburing/man/io_uring_register_files.3 +60 -5
  131. data/vendor/liburing/man/io_uring_register_files_tags.3 +1 -0
  132. data/vendor/liburing/man/io_uring_register_files_update.3 +1 -0
  133. data/vendor/liburing/man/io_uring_register_files_update_tag.3 +1 -0
  134. data/vendor/liburing/man/io_uring_setup.2 +31 -2
  135. data/vendor/liburing/man/io_uring_wait_cqe_timeout.3 +1 -1
  136. data/vendor/liburing/src/Makefile +25 -3
  137. data/vendor/liburing/src/ffi.c +15 -0
  138. data/vendor/liburing/src/include/liburing/io_uring.h +30 -7
  139. data/vendor/liburing/src/include/liburing.h +190 -148
  140. data/vendor/liburing/src/int_flags.h +1 -0
  141. data/vendor/liburing/src/lib.h +5 -16
  142. data/vendor/liburing/src/liburing-ffi.map +172 -0
  143. data/vendor/liburing/src/liburing.map +11 -0
  144. data/vendor/liburing/src/nolibc.c +9 -2
  145. data/vendor/liburing/src/queue.c +2 -2
  146. data/vendor/liburing/src/register.c +66 -96
  147. data/vendor/liburing/src/setup.c +5 -4
  148. data/vendor/liburing/src/version.c +21 -0
  149. data/vendor/liburing/test/232c93d07b74.c +3 -3
  150. data/vendor/liburing/test/35fa71a030ca.c +3 -3
  151. data/vendor/liburing/test/500f9fbadef8.c +2 -0
  152. data/vendor/liburing/test/917257daa0fe.c +1 -1
  153. data/vendor/liburing/test/Makefile +27 -7
  154. data/vendor/liburing/test/a0908ae19763.c +2 -2
  155. data/vendor/liburing/test/a4c0b3decb33.c +2 -2
  156. data/vendor/liburing/test/accept-link.c +4 -4
  157. data/vendor/liburing/test/accept-reuse.c +5 -7
  158. data/vendor/liburing/test/accept.c +34 -31
  159. data/vendor/liburing/test/b19062a56726.c +1 -1
  160. data/vendor/liburing/test/buf-ring.c +58 -4
  161. data/vendor/liburing/test/ce593a6c480a.c +2 -2
  162. data/vendor/liburing/test/close-opath.c +2 -1
  163. data/vendor/liburing/test/connect.c +8 -0
  164. data/vendor/liburing/test/cq-overflow.c +14 -8
  165. data/vendor/liburing/test/d4ae271dfaae.c +1 -1
  166. data/vendor/liburing/test/defer-taskrun.c +64 -9
  167. data/vendor/liburing/test/defer.c +1 -1
  168. data/vendor/liburing/test/double-poll-crash.c +3 -3
  169. data/vendor/liburing/test/eeed8b54e0df.c +8 -3
  170. data/vendor/liburing/test/eploop.c +74 -0
  171. data/vendor/liburing/test/eventfd-ring.c +1 -1
  172. data/vendor/liburing/test/eventfd.c +1 -1
  173. data/vendor/liburing/test/evloop.c +73 -0
  174. data/vendor/liburing/test/exit-no-cleanup.c +1 -1
  175. data/vendor/liburing/test/fadvise.c +1 -1
  176. data/vendor/liburing/test/fc2a85cb02ef.c +3 -3
  177. data/vendor/liburing/test/fd-pass.c +35 -16
  178. data/vendor/liburing/test/file-register.c +61 -0
  179. data/vendor/liburing/test/file-verify.c +2 -2
  180. data/vendor/liburing/test/files-exit-hang-timeout.c +2 -2
  181. data/vendor/liburing/test/fixed-link.c +1 -1
  182. data/vendor/liburing/test/fsnotify.c +118 -0
  183. data/vendor/liburing/test/hardlink.c +1 -1
  184. data/vendor/liburing/test/helpers.c +54 -2
  185. data/vendor/liburing/test/helpers.h +4 -0
  186. data/vendor/liburing/test/io-cancel.c +3 -1
  187. data/vendor/liburing/test/io_uring_passthrough.c +39 -8
  188. data/vendor/liburing/test/io_uring_setup.c +3 -80
  189. data/vendor/liburing/test/iopoll-overflow.c +118 -0
  190. data/vendor/liburing/test/iopoll.c +90 -4
  191. data/vendor/liburing/test/lfs-openat-write.c +7 -9
  192. data/vendor/liburing/test/lfs-openat.c +6 -8
  193. data/vendor/liburing/test/link_drain.c +31 -5
  194. data/vendor/liburing/test/madvise.c +1 -1
  195. data/vendor/liburing/test/msg-ring-flags.c +192 -0
  196. data/vendor/liburing/test/msg-ring-overflow.c +159 -0
  197. data/vendor/liburing/test/msg-ring.c +173 -13
  198. data/vendor/liburing/test/multicqes_drain.c +22 -19
  199. data/vendor/liburing/test/nvme.h +4 -3
  200. data/vendor/liburing/test/pipe-bug.c +95 -0
  201. data/vendor/liburing/test/poll-link.c +3 -3
  202. data/vendor/liburing/test/poll-many.c +41 -19
  203. data/vendor/liburing/test/poll-mshot-overflow.c +105 -2
  204. data/vendor/liburing/test/poll-race-mshot.c +292 -0
  205. data/vendor/liburing/test/poll-race.c +105 -0
  206. data/vendor/liburing/test/poll.c +244 -26
  207. data/vendor/liburing/test/pollfree.c +5 -5
  208. data/vendor/liburing/test/read-before-exit.c +20 -3
  209. data/vendor/liburing/test/read-write.c +2 -0
  210. data/vendor/liburing/test/recv-multishot.c +96 -3
  211. data/vendor/liburing/test/reg-reg-ring.c +90 -0
  212. data/vendor/liburing/test/rename.c +1 -1
  213. data/vendor/liburing/test/ring-leak.c +0 -1
  214. data/vendor/liburing/test/ring-leak2.c +1 -1
  215. data/vendor/liburing/test/ringbuf-read.c +10 -6
  216. data/vendor/liburing/test/send-zerocopy.c +273 -103
  217. data/vendor/liburing/test/send_recv.c +7 -4
  218. data/vendor/liburing/test/sendmsg_fs_cve.c +2 -2
  219. data/vendor/liburing/test/single-issuer.c +7 -9
  220. data/vendor/liburing/test/skip-cqe.c +3 -4
  221. data/vendor/liburing/test/socket.c +0 -1
  222. data/vendor/liburing/test/sq-poll-dup.c +10 -3
  223. data/vendor/liburing/test/sq-poll-kthread.c +1 -1
  224. data/vendor/liburing/test/sq-poll-share.c +3 -2
  225. data/vendor/liburing/test/sqpoll-cancel-hang.c +17 -6
  226. data/vendor/liburing/test/sqpoll-disable-exit.c +4 -4
  227. data/vendor/liburing/test/symlink.c +2 -1
  228. data/vendor/liburing/test/test.h +2 -1
  229. data/vendor/liburing/test/timeout-new.c +11 -7
  230. data/vendor/liburing/test/timeout.c +1 -2
  231. data/vendor/liburing/test/unlink.c +1 -1
  232. data/vendor/liburing/test/version.c +25 -0
  233. data/vendor/liburing/test/wakeup-hang.c +1 -1
  234. data/vendor/liburing/test/xattr.c +8 -4
  235. metadata +57 -44
  236. data/docs/_config.yml +0 -64
  237. data/docs/_includes/head.html +0 -40
  238. data/docs/_includes/title.html +0 -1
  239. data/docs/_sass/custom/custom.scss +0 -10
  240. data/docs/_sass/overrides.scss +0 -0
  241. data/docs/api-reference/exception.md +0 -31
  242. data/docs/api-reference/fiber.md +0 -425
  243. data/docs/api-reference/index.md +0 -9
  244. data/docs/api-reference/io.md +0 -36
  245. data/docs/api-reference/object.md +0 -99
  246. data/docs/api-reference/polyphony-baseexception.md +0 -33
  247. data/docs/api-reference/polyphony-cancel.md +0 -26
  248. data/docs/api-reference/polyphony-moveon.md +0 -24
  249. data/docs/api-reference/polyphony-net.md +0 -20
  250. data/docs/api-reference/polyphony-process.md +0 -28
  251. data/docs/api-reference/polyphony-resourcepool.md +0 -59
  252. data/docs/api-reference/polyphony-restart.md +0 -18
  253. data/docs/api-reference/polyphony-terminate.md +0 -18
  254. data/docs/api-reference/polyphony-threadpool.md +0 -67
  255. data/docs/api-reference/polyphony-throttler.md +0 -77
  256. data/docs/api-reference/polyphony.md +0 -36
  257. data/docs/api-reference/thread.md +0 -88
  258. data/docs/favicon.ico +0 -0
  259. data/docs/getting-started/index.md +0 -10
  260. data/docs/getting-started/installing.md +0 -34
  261. data/vendor/liburing/debian/compat +0 -1
  262. data/vendor/liburing/debian/liburing1-udeb.install +0 -1
  263. data/vendor/liburing/debian/liburing1.install +0 -1
  264. data/vendor/liburing/debian/liburing1.symbols +0 -32
  265. /data/{docs/assets/img → assets}/echo-fibers.svg +0 -0
  266. /data/{docs → assets}/polyphony-logo.png +0 -0
  267. /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: bf93e3d5dfd0a5e3a4a70ee66d62caddc1ea22e63cf1ce44a212a75f18c2ac76
4
- data.tar.gz: 121f84bb920ccc6822cb43b772a68dd92b2f2d81ebf9e1a510c081481dd1e3b1
3
+ metadata.gz: 3f9f6713f2080b0ad929afc680c52a88ad737701575c30433e9ec4c759258dd7
4
+ data.tar.gz: c7f3fd09e72c34269624d52d8dc77e9f5645cfa2d65743afe51e07db850598e3
5
5
  SHA512:
6
- metadata.gz: 286d3cb30ecd19b8f046fe43761f6d2f243f3e3a8134d01ebe14fdfdf11d6d879000f51ba66c705b0ad425e3c6a51dff02781b47e8cf75e52bc4f0439dfffc0e
7
- data.tar.gz: 7caf9e3b7294ece38c964dc0366011b07d8977f95ec8c92a22763b9ecccc33080de40b5ab19bb66223eb4bb27be0847c92879a173dceee1b3fda9e1b03b0cdcd
6
+ metadata.gz: d3472d5ffee0ce36370701c98d28d33d9c76e7ac21a6635e4dff063a6d28e313cd518290dbd0904c496ec29471cab39922daf2473f6b9a168588d0ef861f5ff2
7
+ data.tar.gz: 2a230e7c9b2a95e24992d4a844b92a7af243da5113f355945ce8f585a415dafbde0e2f1fe2fcd1ba434bda94992a3cdf906e37ab78c01caa355e131c8103c87b
data/.github/FUNDING.yml CHANGED
@@ -1 +1 @@
1
- github: ciconia
1
+ github: noteflakes
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.6
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
- Style/MethodMissingSuper:
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/extensions/core.rb
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
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Sharon Rosner
3
+ Copyright (c) 2023 Sharon Rosner
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,36 +1,26 @@
1
- <h1 align="center">
2
- <a href="https://digital-fabric.github.io/polyphony/">
3
- <img src="docs/polyphony-logo.png" alt="Polyphony">
4
- </a>
5
- <br>
6
- Polyphony
7
- <br>
8
- </h1>
9
-
10
- <h4 align="center">Fine-Grained Concurrency for Ruby</h4>
11
-
12
- <p align="center">
13
- <a href="http://rubygems.org/gems/polyphony">
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
- ## Documentation
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
- The complete documentation for Polyphony could be found on the
60
- [Polyphony website](https://digital-fabric.github.io/polyphony).
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
- layout: page
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
- layout: page
3
- title: The Design of Polyphony
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
- layout: page
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
- layout: page
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/ciconia). You can contact me by writing to
195
- [noteflakes@gmail.com](mailto:ciconia@gmail.com).
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
- <p class="img-figure"><img src="../../assets/img/sleeping-fiber.svg"></p>
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
- <p class="img-figure"><img src="../../assets/img/echo-fibers.svg"></p>
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).
@@ -1,4 +1,6 @@
1
- # Polyphony 0.44.1
1
+ # @title What's New?
2
+
3
+ # What's New in 0.44?
2
4
 
3
5
  ## More performance, more compatibility, more robustness
4
6
 
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/setup'
4
- require 'polyphony/adapters/redis'
3
+ # require 'bundler/setup'
4
+ require './lib/polyphony/adapters/redis'
5
+ require 'redis'
5
6
 
6
7
  ::Exception.__disable_sanitized_backtrace__ = true
7
8
 
@@ -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
- # server.accept_loop do |socket|
31
- server.accept_loop do |socket|
32
- # while (socket = (server.accept)
33
- spin do
34
- while (data = socket.gets("\n", 8192))
35
- if data.chomp.empty?
36
- socket << "HTTP/1.1 200 OK\nConnection: close\nContent-Length: 4\n\nfoo\n"
37
- break
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