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
@@ -1,59 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony::ResourcePool
4
- parent: API Reference
5
- permalink: /api-reference/polyphony-resourcepool/
6
- ---
7
- # Polyphony::ResourcePool
8
-
9
- `Polyphony::ResourcePool` implements a general purpose resource pool for
10
- limiting concurrent access to a resource or multiple copies thereof. A resource
11
- pool might be used for example to limit the number of concurrent database
12
- connections.
13
-
14
- ## Class methods
15
-
16
- ## Instance methods
17
-
18
- ### #acquire({ block })
19
-
20
- Acquires a resource and passes it to the given block. The resource will be used
21
- exclusively by the given block, and then returned to the pool. This method
22
- blocks until the given block has completed running. If no resource is available,
23
- this method blocks until a resource has been released.
24
-
25
- ```ruby
26
- db_connections = Polyphony::ResourcePool.new(limit: 5) { PG.connect(opts) }
27
-
28
- def query_records(sql)
29
- db_connections.acquire do |db|
30
- db.query(sql).to_a
31
- end
32
- end
33
- ```
34
-
35
- ### #available → count
36
-
37
- Returns the number of resources currently available in the resource pool.
38
-
39
- ### #initialize(limit: number, { block })
40
-
41
- Initializes a new resource pool with the given maximum number of concurrent
42
- resources. The given block is used to create the resource.
43
-
44
- ```ruby
45
- require 'postgres'
46
-
47
- opts = { host: '/tmp', user: 'admin', dbname: 'mydb' }
48
- db_connections = Polyphony::ResourcePool.new(limit: 5) { PG.connect(opts) }
49
- ```
50
-
51
- ### #limit → count
52
-
53
- Returns the size limit of the resource pool.
54
-
55
- ### #size → count
56
-
57
- Returns the total number of allocated resources in the resource pool. This
58
- includes both available and unavailable resources.
59
-
@@ -1,18 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony::Restart
4
- parent: API Reference
5
- permalink: /api-reference/polyphony-restart/
6
- ---
7
- # Polyphony::Restart
8
-
9
- `Polyphony::Restart` is an exception class used to restart a fiber. Applications
10
- will not normally raise a `Polyphony::Restart` exception, but would rather use
11
- `Fiber#restart`.
12
-
13
- ```ruby
14
- f = spin { do_something_slow }
15
- ...
16
- f.restart
17
- ...
18
- ```
@@ -1,18 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony::Terminate
4
- parent: API Reference
5
- permalink: /api-reference/polyphony-terminate/
6
- ---
7
- # Polyphony::Terminate
8
-
9
- `Polyphony::Terminate` is an exception class used to terminate a fiber without
10
- propagating the exception. It should never be rescued. A `Polyphony::Terminate`
11
- exception is normally raised using APIs such as `Fiber#terminate` or
12
- `Fiber#terminate_all_children`.
13
-
14
- ```ruby
15
- f = spin { do_something_slow }
16
- ...
17
- f.terminate
18
- ```
@@ -1,67 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony::ThreadPool
4
- parent: API Reference
5
- permalink: /api-reference/polyphony-threadpool/
6
- ---
7
- # Polyphony::ThreadPool
8
-
9
- `Polyphony::ThreadPool` implements a general purpose thread pool, normally used
10
- for the execution of non-fiber aware operations, such as C-extension based
11
- third-party libraries or other system call blocking APIs. The Polyphony
12
- implementation of a thread pool allows limiting the number of threads used for
13
- performing a recurring operation across one or more fibers.
14
-
15
- A default thread pool is available for quick access to this feature.
16
-
17
- ## Class methods
18
-
19
- ### #process({ block }) → object
20
-
21
- Runs the given block on the default thread pool. The default pool will be
22
- created on the first call to `#process`. This method will block until the
23
- operation has completed. The return value is that of the given block. Any
24
- uncaught exception will be propagated to the callsite.
25
-
26
- ```ruby
27
- result = Polyphony::ThreadPool.process { lengthy_op }
28
- ```
29
-
30
- ## Instance methods
31
-
32
- ### #busy? → true or false
33
-
34
- Returns true if operations are currently being run on the thread pool.
35
-
36
- ### cast({ block }) → pool
37
-
38
- Runs the given block on one of the threads in the pool in a fire-and-forget
39
- manner, without waiting for the operation to complete. Using `#cast` to run an
40
- operation means there's no way of knowing if the operation has completed or if
41
- any exception has been raised, other than inside the block.
42
-
43
- ```ruby
44
- my_pool.cast { puts 'Hello world' }
45
- do_something_else
46
- ```
47
-
48
- ### #initialize(size = Etc.nprocessors)
49
-
50
- Initializes a new instance of `Polyphony::ThreadPool` with the given maximum
51
- number of threads. The default size is the number of available processors
52
- (number of CPU cores).
53
-
54
- ```ruby
55
- my_pool = Polyphony::ThreadPool.new(3)
56
- ```
57
-
58
- ### #process({ block }) → object
59
-
60
- Runs the given block on one of the threads in the thread pool and blocks until
61
- the operation has completed. The return value is that of the given block. Any
62
- uncaught exception will be propagated to the callsite.
63
-
64
- ```ruby
65
- pool = Polyphony::ThreadPool.new(3)
66
- result = pool.process { lengthy_op }
67
- ```
@@ -1,77 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony::Throttler
4
- parent: API Reference
5
- permalink: /api-reference/polyphony-throttler/
6
- ---
7
- # Polyphony::Throttler
8
-
9
- `Polyphony::Throttler` implements general purpose operation throttling, or rate
10
- limiting. A `Polyphony::Throttler` instance may be used to limit the rate of an
11
- arbitrary operation in a single fiber, or across multiple fibers. For example,
12
- an HTTP server can limit the number of requests per second across for each
13
- client, or for all clients.
14
-
15
- A throttler is invoked using its `#call` method, e.g.:
16
-
17
- ```ruby
18
- # throttle rate: one per second
19
- throttler = Polyphony::Throttler.new(1)
20
-
21
- 10.times do |i|
22
- spin_loop { throttler.call { p [i, Time.now] } }
23
- end
24
- ```
25
-
26
- If many throttler instances are created over the application's lifetime, they
27
- should be stopped using the `#stop` method in order to prevent memory leaks.
28
- This is best done using an `ensure` block:
29
-
30
- ```ruby
31
- def start_server
32
- throttler = Polyphony::Throttler.new(1000)
33
- MyServer.start do |req|
34
- throttler.call { handle_request(req) }
35
- end
36
- ensure
37
- throttler.stop
38
- end
39
- ```
40
-
41
- ## Instance methods
42
-
43
- ### #initialize(rate)<br>#initialize(interval: interval)<br>#initialize(rate: rate)
44
-
45
- Initializes the throttler with the given rate. The rate can be specified either
46
- as a number signifying the maximum rate per second, or as a keyword argument. If
47
- the rate is specified using the `interval:` keyword argument, the value given is
48
- the minimum interval between consecutive invocations.
49
-
50
- ```ruby
51
- # These are all equivalent
52
- Polyphony::Throttler.new(10)
53
- Polyphony::Throttler.new(rate: 10)
54
- Polyphony::Throttler.new(interval: 0.1)
55
- ```
56
-
57
- ### #call({ block }) → object
58
-
59
- Invokes the throttler with the given block. This method will sleep for an
60
- interval of time required to throttle the execution of the given block. The
61
- return value is the return value of the given block.
62
-
63
- ### #stop → throttler
64
-
65
- Stops the timer associated with the throttler. This method should be called when
66
- the throttler is no longer needed. This is best done from an `ensure` block.
67
-
68
- ```ruby
69
- def start_server
70
- throttler = Polyphony::Throttler.new(1000)
71
- MyServer.start do |req|
72
- throttler.call { handle_request(req) }
73
- end
74
- ensure
75
- throttler.stop
76
- end
77
- ```
@@ -1,36 +0,0 @@
1
- ---
2
- layout: page
3
- title: Polyphony
4
- parent: API Reference
5
- permalink: /api-reference/polyphony/
6
- ---
7
- # Polyphony
8
-
9
- The `Polyphony` module acts as a namespace containing general Polyphony
10
- functionalities.
11
-
12
- ## Class Methods
13
-
14
- ### #emit_signal_exception(exception, fiber = Thread.main.main_fiber) → thread
15
-
16
- Emits an exception to the given fiber from a signal handler.
17
-
18
- ### #fork({ block }) → pid
19
-
20
- Forks a child process running the given block. Due to the way Ruby implements
21
- fibers, along with how signals interact with them, Polyphony-based applications
22
- should use `Polyphony#fork` rather than `Kernel#fork`. In order to continue
23
- handling fiber scheduling and signal handling correctly, the child process does
24
- the following:
25
-
26
- - A new fiber is created using `Fiber#new` and control is transferred to it.
27
- - Notify the event loop that a fork has occurred (by calling `ev_loop_fork`).
28
- - Setup the current fiber as the main thread's main fiber.
29
- - Setup fiber scheduling for the main thread.
30
- - Install fiber-aware signal handlers for the `TERM` and `INT` signals.
31
- - Run the block.
32
- - Correctly handle uncaught exceptions, including `SystemExit` and `Interrupt`.
33
-
34
- ### #watch_process(cmd = nil, { block })
35
-
36
- Alternative for [`Polyphony::Process.watch`](../polyphony-process/#watchcmd--nil--block-).
@@ -1,88 +0,0 @@
1
- ---
2
- layout: page
3
- title: ::Thread
4
- parent: API Reference
5
- permalink: /api-reference/thread/
6
- ---
7
- # ::Thread
8
-
9
- [Ruby core Thread documentation](https://ruby-doc.org/core-2.7.0/Thread.html)
10
-
11
- Polyphony enhances the core `Thread` class with APIs for switching and
12
- scheduling fibers, and reimplements some of its APIs such as `Thread#raise`
13
- using fibers which, incidentally, make it safe.
14
-
15
- Each thread has its own run queue and its own system backend. While running
16
- multiple threads does not result in true parallelism in MRI Ruby, sometimes
17
- multithreading is inevitable, for instance when using third-party gems that
18
- spawn threads, or when calling blocking APIs that are not fiber-aware.
19
-
20
- ## Class Methods
21
-
22
- ## Instance methods
23
-
24
- ### #&lt;&lt;(object) → fiber<br>#send(object) → fiber
25
-
26
- Sends a message to the thread's main fiber. For further details see
27
- [`Fiber#<<`](../fiber/#object--fibersendobject--fiber).
28
-
29
- ### #fiber_scheduling_stats → stats
30
-
31
- Returns statistics relating to fiber scheduling for the thread with the
32
- following entries:
33
-
34
- - `:scheduled_fibers` - number of fibers currently in the run queue
35
- - `:pending_watchers` - number of currently pending event watchers
36
-
37
- ### #join → object<br>#await → object
38
-
39
- Waits for the thread to finish running. If the thread has terminated with an
40
- uncaught exception, it will be reraised in the context of the calling fiber. If
41
- no excecption is raised, returns the thread's result.
42
-
43
- ```ruby
44
- t = Thread.new { sleep 1 }
45
- t.join
46
- ```
47
-
48
- ### #main_fiber → fiber
49
-
50
- Returns the main fiber for the thread.
51
-
52
- ### #result → object
53
-
54
- Returns the result of the thread's main fiber.
55
-
56
- ```ruby
57
- t = Thread.new { 'foo' }
58
- t.join
59
- t.result #=> 'foo'
60
- ```
61
-
62
- ### #switch_fiber
63
-
64
- invokes a switchpoint, selecting and resuming the next fiber to run. The
65
- switching algorithm works as follows:
66
-
67
- - If the run queue is not empty, conditionally run the event loop a single time
68
- in order to prevent event starvation when there's always runnable fibers
69
- waiting to be resumed.
70
- - If the run queue is empty, run the event loop until a fiber is put on the run
71
- queue.
72
- - Switch to the first fiber in the run queue.
73
-
74
- This method is normally not called directly by the application. Calling
75
- `Thread#switch_fiber` means the current fiber has no more work to do and would
76
- like yield to other fibers. Note that if the current fiber needs to resume at a
77
- later time, it should be scheduled before calling `Thread#switch_fiber`.
78
-
79
- ```ruby
80
- # schedule current fiber to be resumed later
81
- Fiber.current.schedule
82
-
83
- # switch to another fiber
84
- Thread.current.switch_fiber
85
-
86
- # the fiber is resumed
87
- resume_work
88
- ```
data/docs/favicon.ico DELETED
Binary file
@@ -1,10 +0,0 @@
1
- ---
2
- layout: page
3
- title: Getting Started
4
- description: Getting started with Polyphony
5
- has_children: true
6
- nav_order: 2
7
- ---
8
-
9
- # Getting Started
10
- {: .no_toc }
@@ -1,34 +0,0 @@
1
- ---
2
- layout: page
3
- title: Installing Polyphony
4
- parent: Getting Started
5
- nav_order: 1
6
- ---
7
- # Installing Polyphony
8
-
9
- ## System Requirements
10
-
11
- In order to use Polyphony you need to have:
12
-
13
- - Linux or MacOS (support for Windows will come at a later stage)
14
- - Ruby (MRI) 2.6 or newer
15
-
16
- ## Installing the Polyphony Gem
17
-
18
- Add this line to your application's Gemfile:
19
-
20
- ```ruby
21
- gem 'polyphony'
22
- ```
23
-
24
- And then execute:
25
-
26
- ```bash
27
- $ bundle
28
- ```
29
-
30
- Or install it yourself as:
31
-
32
- ```bash
33
- $ gem install polyphony
34
- ```
@@ -1 +0,0 @@
1
- 9
@@ -1 +0,0 @@
1
- lib/*/lib*.so.*
@@ -1 +0,0 @@
1
- lib/*/lib*.so.*
@@ -1,32 +0,0 @@
1
- liburing.so.1 liburing1 #MINVER#
2
- (symver)LIBURING_0.1 0.1-1
3
- io_uring_get_sqe@LIBURING_0.1 0.1-1
4
- io_uring_queue_exit@LIBURING_0.1 0.1-1
5
- io_uring_queue_init@LIBURING_0.1 0.1-1
6
- io_uring_queue_mmap@LIBURING_0.1 0.1-1
7
- io_uring_register_buffers@LIBURING_0.1 0.1-1
8
- io_uring_register_eventfd@LIBURING_0.1 0.1-1
9
- io_uring_register_eventfd_async@LIBURING_0.6 0.6-1
10
- io_uring_register_files@LIBURING_0.1 0.1-1
11
- io_uring_submit@LIBURING_0.1 0.1-1
12
- io_uring_submit_and_wait@LIBURING_0.1 0.1-1
13
- io_uring_unregister_buffers@LIBURING_0.1 0.1-1
14
- io_uring_unregister_files@LIBURING_0.1 0.1-1
15
- (symver)LIBURING_0.2 0.2-1
16
- __io_uring_get_cqe@LIBURING_0.2 0.2-1
17
- io_uring_queue_init_params@LIBURING_0.2 0.2-1
18
- io_uring_register_files_update@LIBURING_0.2 0.2-1
19
- io_uring_peek_batch_cqe@LIBURING_0.2 0.2-1
20
- io_uring_wait_cqe_timeout@LIBURING_0.2 0.2-1
21
- io_uring_wait_cqes@LIBURING_0.2 0.2-1
22
- (symver)LIBURING_0.3 0.3-1
23
- (symver)LIBURING_0.4 0.4-1
24
- (symver)LIBURING_0.5 0.5-1
25
- (symver)LIBURING_0.6 0.6-1
26
- (symver)LIBURING_0.7 0.7-1
27
- io_uring_get_probe@LIBURING_0.4 0.4-1
28
- io_uring_get_probe_ring@LIBURING_0.4 0.4-1
29
- io_uring_register_personality@LIBURING_0.4 0.4-1
30
- io_uring_register_probe@LIBURING_0.4 0.4-1
31
- io_uring_ring_dontfork@LIBURING_0.4 0.4-1
32
- io_uring_unregister_personality@LIBURING_0.4 0.4-1
File without changes
File without changes
File without changes