async 2.21.3 → 2.23.0

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: 2cc69a2f9c734662ef143958e58fc4c9af45d7a05a0910570457c328fb488fca
4
- data.tar.gz: b1149b22d3dc693e411efa942fe36841f7ce9120050b370addc309e270ba7965
3
+ metadata.gz: dedd26d802fb259e0eff2223a86a54f42b46753ab43014b091a83b97610346a0
4
+ data.tar.gz: 682ab4c4b3798df642e3937b902f4a0d0762ce0dfd91f5c2430205775b2bbe8a
5
5
  SHA512:
6
- metadata.gz: f8930f0303101bc429bc7cc9f9120e516699559af0ee1b73af95c957e9bc3c1cfd9dcca45ce14a99ed86d78fc4a2cce6eb77f64f46fbde2db61d028aa4c89739
7
- data.tar.gz: 359e97fb5805e6b7bef879aad71df0f72a53584b806c30f4a5a52e1f26f4dce1e9e21f20b01c5d79fb714857d53d78232c2c209ce959c806b81b358f63aa452b
6
+ metadata.gz: d45d3a428c1403b999be51a831e44206ed1636bbfd7603cee7c4e71d03ec2e2e3941b329deb30b18aa4b1021f0b0360726898017ee48933a2262ebaf6c1980df
7
+ data.tar.gz: da44d07b913e0efff2aff07ff545f5996806601b33ca69b707c5e462d0858ad85e613b5ad6b8d4d53cdd21dd1d80852acf5b71b7359b3b26c2ab10437730873c
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/async/barrier.md CHANGED
@@ -18,7 +18,7 @@ Sync do
18
18
  # Sleep sort the numbers:
19
19
  numbers.each do |number|
20
20
  barrier.async do |task|
21
- task.sleep(number)
21
+ sleep(number)
22
22
  sorted << number
23
23
  end
24
24
  end
data/lib/async/clock.rb CHANGED
@@ -61,5 +61,14 @@ module Async
61
61
 
62
62
  return total
63
63
  end
64
+
65
+ # Reset the total elapsed time. If the clock is currently running, reset the start time to now.
66
+ def reset!
67
+ @total = 0
68
+
69
+ if @started
70
+ @started = Clock.now
71
+ end
72
+ end
64
73
  end
65
74
  end
@@ -15,7 +15,7 @@ Sync do
15
15
  end
16
16
 
17
17
  Async do |task|
18
- task.sleep(1)
18
+ sleep(1)
19
19
  Console.info "Signalling condition..."
20
20
  condition.signal("Hello World")
21
21
  end
@@ -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/version.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  # Copyright, 2017-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
- VERSION = "2.21.3"
7
+ VERSION = "2.23.0"
8
8
  end
@@ -8,10 +8,13 @@ require "metrics/provider"
8
8
 
9
9
  Metrics::Provider(Async::Task) do
10
10
  ASYNC_TASK_SCHEDULED = Metrics.metric("async.task.scheduled", :counter, description: "The number of tasks scheduled.")
11
+ ASYNC_TASK_FINISHED = Metrics.metric("async.task.finished", :counter, description: "The number of tasks finished.")
11
12
 
12
13
  def schedule(&block)
13
14
  ASYNC_TASK_SCHEDULED.emit(1)
14
15
 
15
16
  super(&block)
17
+ ensure
18
+ ASYNC_TASK_FINISHED.emit(1)
16
19
  end
17
20
  end
data/readme.md CHANGED
@@ -24,7 +24,7 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
24
24
 
25
25
  - [Asynchronous Tasks](https://socketry.github.io/async/guides/asynchronous-tasks/index) - This guide explains how asynchronous tasks work and how to use them.
26
26
 
27
- - [Event Loop](https://socketry.github.io/async/guides/event-loop/index) - This guide gives an overview of how the event loop is implemented.
27
+ - [Scheduler](https://socketry.github.io/async/guides/scheduler/index) - This guide gives an overview of how the scheduler is implemented.
28
28
 
29
29
  - [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the compatibility of Async with Ruby and other frameworks.
30
30
 
@@ -36,6 +36,11 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
36
36
 
37
37
  Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
38
38
 
39
+ ### v2.23.0
40
+
41
+ - Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
42
+ - [Fiber Stall Profiler](https://socketry.github.io/async/releases/index#fiber-stall-profiler)
43
+
39
44
  ### v2.21.1
40
45
 
41
46
  - [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.21.3
4
+ version: 2.23.0
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-01-31 00:00:00.000000000 Z
65
+ date: 2025-02-13 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