async 2.22.0 → 2.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ef8aa467e82d3ddcd2c24a823ffba2e2b9e1680d005fade667ef36c882588dd1
4
- data.tar.gz: c2df7e4669fe9d2f0bb8d6c6f7de673d1a89e41d8ffc99bf702f79cefbce7a3e
3
+ metadata.gz: 36ac96ecf26e32e4804f8e89909dcb7b5f8cdfbed24a4da1a189d027586bd0b1
4
+ data.tar.gz: 35fb378abd8183a2a4950a2b57fd4ba6360c740b51a12ff3e67af5a2c443583c
5
5
  SHA512:
6
- metadata.gz: 2a98aaf33872cafab28e41acf187425926a3e0423ee5017bfd42fef66e64f55ad0ec6d6d1a053987813a3f190471e4521bac7c8895fb1ee352b8e984cf1dd326
7
- data.tar.gz: 64205b564a8de8aeb22d0ae6834ea9dfd114439336e7bd076de489da0e045f002a9d90f51f72414c36ed006a599cd536d27ff852b5f8f9541f3c656c3d9e7035
6
+ metadata.gz: 5ff90e092ac86b1dd3e5991e48d44d2b6a9abaa1b72d785d3e9419630f3f8fadd241ab21837bbd5ddd4038792e3ac970bf2aa4b2f67f5a473d4be1caa067f1d5
7
+ data.tar.gz: 5b71b8eae39aee81b3918f1012c76a4306529292626bf6dc95e79ecebcfa53cda304840655eee56c3392b5a912478ff3178ab4624a2f519ad02d6ce70098f1e2
checksums.yaml.gz.sig CHANGED
Binary file
@@ -15,9 +15,17 @@ require "console"
15
15
  require "resolv"
16
16
 
17
17
  module Async
18
+ begin
19
+ require "fiber/profiler"
20
+ Profiler = Fiber::Profiler
21
+ rescue LoadError
22
+ # Fiber::Profiler is not available.
23
+ Profiler = nil
24
+ end
25
+
18
26
  # Handles scheduling of fibers. Implements the fiber scheduler interface.
19
27
  class Scheduler < Node
20
- DEFAULT_WORKER_POOL = ENV.fetch("ASYNC_SCHEDULER_DEFAULT_WORKER_POOL", nil).then do |value|
28
+ WORKER_POOL = ENV.fetch("ASYNC_SCHEDULER_WORKER_POOL", nil).then do |value|
21
29
  value == "true" ? true : nil
22
30
  end
23
31
 
@@ -42,10 +50,12 @@ module Async
42
50
  # @public Since *Async v1*.
43
51
  # @parameter parent [Node | Nil] The parent node to use for task hierarchy.
44
52
  # @parameter selector [IO::Event::Selector] The selector to use for event handling.
45
- def initialize(parent = nil, selector: nil, worker_pool: DEFAULT_WORKER_POOL)
53
+ def initialize(parent = nil, selector: nil, profiler: Profiler&.default, worker_pool: WORKER_POOL)
46
54
  super(parent)
47
55
 
48
56
  @selector = selector || ::IO::Event::Selector.new(Fiber.current)
57
+ @profiler = profiler
58
+
49
59
  @interrupted = false
50
60
 
51
61
  @blocked = 0
@@ -492,13 +502,19 @@ module Async
492
502
  def run(...)
493
503
  Kernel.raise ClosedError if @selector.nil?
494
504
 
495
- initial_task = self.async(...) if block_given?
496
-
497
- self.run_loop do
498
- run_once
505
+ begin
506
+ @profiler&.start
507
+
508
+ initial_task = self.async(...) if block_given?
509
+
510
+ self.run_loop do
511
+ run_once
512
+ end
513
+
514
+ return initial_task
515
+ ensure
516
+ @profiler&.stop
499
517
  end
500
-
501
- return initial_task
502
518
  end
503
519
 
504
520
  # Start an asynchronous task within the specified reactor. The task will be executed until the first blocking call, at which point it will yield and and this method will return.
data/lib/async/task.rb CHANGED
@@ -298,7 +298,7 @@ module Async
298
298
  begin
299
299
  # There is a chance that this will stop the fiber that originally called stop. If that happens, the exception handling in `#stopped` will rescue the exception and re-raise it later.
300
300
  Fiber.scheduler.raise(@fiber, Stop)
301
- rescue FiberError => error
301
+ rescue FiberError
302
302
  # In some cases, this can cause a FiberError (it might be resumed already), so we schedule it to be stopped later:
303
303
  Fiber.scheduler.push(Stop::Later.new(self))
304
304
  end
data/lib/async/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.22.0"
7
+ VERSION = "2.23.1"
8
8
  end
@@ -14,8 +14,6 @@ Metrics::Provider(Async::Task) do
14
14
  ASYNC_TASK_SCHEDULED.emit(1)
15
15
 
16
16
  super(&block)
17
- rescue => error
18
- raise
19
17
  ensure
20
18
  ASYNC_TASK_FINISHED.emit(1)
21
19
  end
data/readme.md CHANGED
@@ -7,7 +7,6 @@ Async is a composable asynchronous I/O framework for Ruby based on [io-event](ht
7
7
  > beautifully designed." *– [janko](https://github.com/janko)*
8
8
 
9
9
  [![Development Status](https://github.com/socketry/async/workflows/Test/badge.svg)](https://github.com/socketry/async/actions?workflow=Test)
10
- [<img src="https://api.gitsponsors.com/api/badge/img?id=87380483" height="20"/>](https://api.gitsponsors.com/api/badge/link?p=U4gCxvzG7eUksiJSe0MSlPHWWhBYryqj6i48tx5L7/r/2NgkAToKb6dEm31bAftU3H+7BVwk3VhUBtE4GHqHJTPfWPR6xo2BQVoT15rFAGAsLFgdT2kKopIfCGV/QDOm7BrkodS2//R7NUMksAdaCQ==)
11
10
 
12
11
  ## Features
13
12
 
@@ -36,6 +35,11 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
36
35
 
37
36
  Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
38
37
 
38
+ ### v2.23.0
39
+
40
+ - Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
41
+ - [Fiber Stall Profiler](https://socketry.github.io/async/releases/index#fiber-stall-profiler)
42
+
39
43
  ### v2.21.1
40
44
 
41
45
  - [Worker Pool](https://socketry.github.io/async/releases/index#worker-pool)
data/releases.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Releases
2
2
 
3
+ ## v2.23.0
4
+
5
+ - Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
6
+
7
+ ### Fiber Stall Profiler
8
+
9
+ After several iterations of experimentation, we are officially introducing the fiber stall profiler, implemented using the optional `fiber-profiler` gem. This gem is not included by default, but can be added to your project:
10
+
11
+ ``` bash
12
+ $ bundle add fiber-profiler
13
+ ```
14
+
15
+ After adding the gem, you can enable the fiber stall profiler by setting the `FIBER_PROFILER_CAPTURE=true` environment variable:
16
+
17
+ ``` bash
18
+ $ FIBER_PROFILER_CAPTURE=true bundle exec ruby -rasync -e 'Async{Fiber.blocking{sleep 0.1}}'
19
+ Fiber stalled for 0.105 seconds
20
+ -e:1 in c-call '#<Class:Fiber>#blocking' (0.105s)
21
+ -e:1 in c-call 'Kernel#sleep' (0.105s)
22
+ Skipped 1 calls that were too short to be meaningful.
23
+ ```
24
+
25
+ The fiber profiler will help you find problems with your code that cause the event loop to stall, which can be a common source of performance issues in asynchronous code.
26
+
3
27
  ## v2.21.1
4
28
 
5
29
  ### Worker Pool
@@ -8,7 +32,7 @@ Ruby 3.4 will feature a new fiber scheduler hook, `blocking_operation_wait` whic
8
32
 
9
33
  The Async scheduler optionally supports this feature using a worker pool, by using the following environment variable:
10
34
 
11
- ASYNC_SCHEDULER_DEFAULT_WORKER_POOL=true
35
+ ASYNC_SCHEDULER_WORKER_POOL=true
12
36
 
13
37
  This will cause the scheduler to use a worker pool for general blocking operations, rather than blocking the event loop.
14
38
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.22.0
4
+ version: 2.23.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -62,7 +62,7 @@ cert_chain:
62
62
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
63
63
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
64
64
  -----END CERTIFICATE-----
65
- date: 2025-02-07 00:00:00.000000000 Z
65
+ date: 2025-03-10 00:00:00.000000000 Z
66
66
  dependencies:
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: console
@@ -98,14 +98,14 @@ dependencies:
98
98
  requirements:
99
99
  - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: '1.7'
101
+ version: '1.9'
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
106
  - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: '1.7'
108
+ version: '1.9'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: traces
111
111
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file