async 2.17.0 → 2.32.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/context/best-practices.md +188 -0
- data/context/debugging.md +63 -0
- data/context/getting-started.md +177 -0
- data/context/index.yaml +29 -0
- data/context/scheduler.md +109 -0
- data/context/tasks.md +448 -0
- data/context/thread-safety.md +651 -0
- data/lib/async/barrier.md +1 -2
- data/lib/async/barrier.rb +35 -12
- data/lib/async/clock.rb +11 -2
- data/lib/async/condition.md +1 -1
- data/lib/async/condition.rb +18 -34
- data/lib/async/console.rb +42 -0
- data/lib/async/deadline.rb +70 -0
- data/lib/async/idler.rb +2 -1
- data/lib/async/limited_queue.rb +13 -0
- data/lib/async/list.rb +16 -8
- data/lib/async/node.rb +5 -3
- data/lib/async/notification.rb +13 -9
- data/lib/async/priority_queue.rb +253 -0
- data/lib/async/promise.rb +188 -0
- data/lib/async/queue.rb +70 -82
- data/lib/async/reactor.rb +4 -2
- data/lib/async/scheduler.rb +233 -54
- data/lib/async/semaphore.rb +3 -3
- data/lib/async/stop.rb +82 -0
- data/lib/async/task.rb +111 -81
- data/lib/async/timeout.rb +88 -0
- data/lib/async/variable.rb +15 -4
- data/lib/async/version.rb +2 -2
- data/lib/async/waiter.rb +6 -1
- data/lib/kernel/async.rb +1 -1
- data/lib/kernel/sync.rb +14 -5
- data/lib/metrics/provider/async/task.rb +20 -0
- data/lib/metrics/provider/async.rb +6 -0
- data/lib/traces/provider/async/barrier.rb +17 -0
- data/lib/traces/provider/async/task.rb +40 -0
- data/lib/traces/provider/async.rb +7 -0
- data/license.md +8 -1
- data/readme.md +50 -7
- data/releases.md +357 -0
- data.tar.gz.sig +0 -0
- metadata +61 -20
- metadata.gz.sig +0 -0
- data/lib/async/waiter.md +0 -50
- data/lib/async/wrapper.rb +0 -65
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2024-2025, by Samuel Williams.
|
5
|
+
|
6
|
+
require_relative "../../../async/task"
|
7
|
+
require "traces/provider"
|
8
|
+
|
9
|
+
Traces::Provider(Async::Task) do
|
10
|
+
def schedule(&block)
|
11
|
+
# If we are not actively tracing anything, then we can skip this:
|
12
|
+
unless Traces.active?
|
13
|
+
return super(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
unless self.transient?
|
17
|
+
trace_context = Traces.current_context
|
18
|
+
end
|
19
|
+
|
20
|
+
attributes = {
|
21
|
+
# We use the instance variable as it corresponds to the user-provided block.
|
22
|
+
"block" => @block.to_s,
|
23
|
+
"transient" => self.transient?,
|
24
|
+
}
|
25
|
+
|
26
|
+
# Run the trace in the context of the child task:
|
27
|
+
super do
|
28
|
+
Traces.with_context(trace_context)
|
29
|
+
|
30
|
+
if annotation = self.annotation
|
31
|
+
attributes["annotation"] = annotation
|
32
|
+
end
|
33
|
+
|
34
|
+
Traces.trace("async.task", attributes: attributes) do
|
35
|
+
# Yes, this is correct, we already called super above:
|
36
|
+
yield
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/license.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# MIT License
|
2
2
|
|
3
|
-
Copyright, 2017-
|
3
|
+
Copyright, 2017-2025, by Samuel Williams.
|
4
4
|
Copyright, 2017, by Kent Gruber.
|
5
5
|
Copyright, 2017, by Devin Christensen.
|
6
6
|
Copyright, 2018, by Sokolov Yura.
|
@@ -27,6 +27,13 @@ Copyright, 2023, by Emil Tin.
|
|
27
27
|
Copyright, 2023, by Gert Goet.
|
28
28
|
Copyright, 2024, by Dimitar Peychinov.
|
29
29
|
Copyright, 2024, by Jamie McCarthy.
|
30
|
+
Copyright, 2025, by Jahfer Husain.
|
31
|
+
Copyright, 2025, by Mark Montroy.
|
32
|
+
Copyright, 2025, by Shigeru Nakajima.
|
33
|
+
Copyright, 2025, by Alan Wu.
|
34
|
+
Copyright, 2025, by Shopify Inc.
|
35
|
+
Copyright, 2025, by Josh Teeter.
|
36
|
+
Copyright, 2025, by Jatin Goyal.
|
30
37
|
|
31
38
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
32
39
|
of this software and associated documentation files (the "Software"), to deal
|
data/readme.md
CHANGED
@@ -21,25 +21,68 @@ Please see the [project documentation](https://socketry.github.io/async/) for mo
|
|
21
21
|
|
22
22
|
- [Getting Started](https://socketry.github.io/async/guides/getting-started/index) - This guide shows how to add async to your project and run code asynchronously.
|
23
23
|
|
24
|
-
- [
|
24
|
+
- [Scheduler](https://socketry.github.io/async/guides/scheduler/index) - This guide gives an overview of how the scheduler is implemented.
|
25
25
|
|
26
|
-
- [
|
27
|
-
|
28
|
-
- [Compatibility](https://socketry.github.io/async/guides/compatibility/index) - This guide gives an overview of the compatibility of Async with Ruby and other frameworks.
|
26
|
+
- [Tasks](https://socketry.github.io/async/guides/tasks/index) - This guide explains how asynchronous tasks work and how to use them.
|
29
27
|
|
30
28
|
- [Best Practices](https://socketry.github.io/async/guides/best-practices/index) - This guide gives an overview of best practices for using Async.
|
31
29
|
|
32
30
|
- [Debugging](https://socketry.github.io/async/guides/debugging/index) - This guide explains how to debug issues with programs that use Async.
|
33
31
|
|
32
|
+
- [Thread safety](https://socketry.github.io/async/guides/thread-safety/index) - This guide explains thread safety in Ruby, focusing on fibers and threads, common pitfalls, and best practices to avoid problems like data corruption, race conditions, and deadlocks.
|
33
|
+
|
34
34
|
## Releases
|
35
35
|
|
36
36
|
Please see the [project releases](https://socketry.github.io/async/releases/index) for all releases.
|
37
37
|
|
38
|
-
### v2.
|
38
|
+
### v2.32.0
|
39
|
+
|
40
|
+
- Introduce `Queue#waiting_count` and `PriorityQueue#waiting_count`. Generally for statistics/testing purposes only.
|
41
|
+
|
42
|
+
### v2.31.0
|
43
|
+
|
44
|
+
- Introduce `Async::Deadline` for precise timeout management in compound operations.
|
45
|
+
|
46
|
+
### v2.30.0
|
47
|
+
|
48
|
+
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
49
|
+
- Add timeout support to `Async::PriorityQueue#dequeue` and `Async::PriorityQueue#pop` methods.
|
50
|
+
- Add `closed?` method to `Async::PriorityQueue` for full queue interface compatibility.
|
51
|
+
- Support non-blocking operations using `timeout: 0` parameter.
|
52
|
+
|
53
|
+
### v2.29.0
|
54
|
+
|
55
|
+
This release introduces thread-safety as a core concept of Async. Many core classes now have thread-safe guarantees, allowing them to be used safely across multiple threads.
|
56
|
+
|
57
|
+
- Thread-safe `Async::Condition` and `Async::Notification`, implemented using `Thread::Queue`.
|
58
|
+
- Thread-safe `Async::Queue` and `Async::LimitedQueue`, implemented using `Thread::Queue` and `Thread::LimitedQueue` respectively.
|
59
|
+
- `Async::Variable` is deprecated in favor of `Async::Promise`.
|
60
|
+
- [Introduce `Async::Promise`](https://socketry.github.io/async/releases/index#introduce-async::promise)
|
61
|
+
- [Introduce `Async::PriorityQueue`](https://socketry.github.io/async/releases/index#introduce-async::priorityqueue)
|
62
|
+
|
63
|
+
### v2.28.1
|
64
|
+
|
65
|
+
- Fix race condition between `Async::Barrier#stop` and finish signalling.
|
66
|
+
|
67
|
+
### v2.28.0
|
68
|
+
|
69
|
+
- Use `Traces.current_context` and `Traces.with_context` for better integration with OpenTelemetry.
|
70
|
+
|
71
|
+
### v2.27.4
|
72
|
+
|
73
|
+
- Suppress excessive warning in `Async::Scheduler#async`.
|
74
|
+
|
75
|
+
### v2.27.3
|
76
|
+
|
77
|
+
- Ensure trace attributes are strings, fixes integration with OpenTelemetry.
|
78
|
+
|
79
|
+
### v2.27.2
|
80
|
+
|
81
|
+
- Fix `context/index.yaml` schema.
|
39
82
|
|
40
|
-
### v2.
|
83
|
+
### v2.27.1
|
41
84
|
|
42
|
-
-
|
85
|
+
- Updated documentation and agent context.
|
43
86
|
|
44
87
|
## See Also
|
45
88
|
|
data/releases.md
CHANGED
@@ -1,5 +1,362 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v2.32.0
|
4
|
+
|
5
|
+
- Introduce `Queue#waiting_count` and `PriorityQueue#waiting_count`. Generally for statistics/testing purposes only.
|
6
|
+
|
7
|
+
## v2.31.0
|
8
|
+
|
9
|
+
- Introduce `Async::Deadline` for precise timeout management in compound operations.
|
10
|
+
|
11
|
+
## v2.30.0
|
12
|
+
|
13
|
+
- Add timeout support to `Async::Queue#dequeue` and `Async::Queue#pop` methods.
|
14
|
+
- Add timeout support to `Async::PriorityQueue#dequeue` and `Async::PriorityQueue#pop` methods.
|
15
|
+
- Add `closed?` method to `Async::PriorityQueue` for full queue interface compatibility.
|
16
|
+
- Support non-blocking operations using `timeout: 0` parameter.
|
17
|
+
|
18
|
+
## v2.29.0
|
19
|
+
|
20
|
+
This release introduces thread-safety as a core concept of Async. Many core classes now have thread-safe guarantees, allowing them to be used safely across multiple threads.
|
21
|
+
|
22
|
+
- Thread-safe `Async::Condition` and `Async::Notification`, implemented using `Thread::Queue`.
|
23
|
+
- Thread-safe `Async::Queue` and `Async::LimitedQueue`, implemented using `Thread::Queue` and `Thread::LimitedQueue` respectively.
|
24
|
+
- `Async::Variable` is deprecated in favor of `Async::Promise`.
|
25
|
+
|
26
|
+
### Introduce `Async::Promise`
|
27
|
+
|
28
|
+
This release introduces the new `Async::Promise` class and refactors `Async::Task` to use promises for state management internally. This architectural improvement achieves the design goal that "a task should be a promise with attached computation and cancellation handling."
|
29
|
+
|
30
|
+
- **Thread-safe promise implementation** with immutable state transitions.
|
31
|
+
- **Consistent state management** using symbols: `:completed`, `:failed`, `:cancelled`.
|
32
|
+
- **Promise cancellation** with `cancel()` method and `Cancel` exception class.
|
33
|
+
- **Comprehensive test coverage** with 47 new test cases covering all edge cases.
|
34
|
+
|
35
|
+
<!-- end list -->
|
36
|
+
|
37
|
+
``` ruby
|
38
|
+
require 'async/promise'
|
39
|
+
|
40
|
+
# Basic promise usage - works independently of Async framework
|
41
|
+
promise = Async::Promise.new
|
42
|
+
|
43
|
+
# In another thread or fiber, resolve the promise
|
44
|
+
Thread.new do
|
45
|
+
sleep(1) # Simulate some work
|
46
|
+
promise.resolve("Hello, World!")
|
47
|
+
end
|
48
|
+
|
49
|
+
# Wait for the result
|
50
|
+
result = promise.wait
|
51
|
+
puts result # => "Hello, World!"
|
52
|
+
|
53
|
+
# Check promise state
|
54
|
+
puts promise.resolved? # => true
|
55
|
+
puts promise.completed? # => true
|
56
|
+
```
|
57
|
+
|
58
|
+
Promises bridge Thread and Fiber concurrency models - a promise resolved in one thread can be awaited in a fiber, and vice versa.
|
59
|
+
|
60
|
+
### Introduce `Async::PriorityQueue`
|
61
|
+
|
62
|
+
The new `Async::PriorityQueue` provides a thread-safe, fiber-aware queue where consumers can specify priority levels. Higher priority consumers are served first when items become available, with FIFO ordering maintained for equal priorities. This is useful for implementing priority-based task processing systems where critical operations need to be handled before lower priority work.
|
63
|
+
|
64
|
+
``` ruby
|
65
|
+
require 'async'
|
66
|
+
require 'async/priority_queue'
|
67
|
+
|
68
|
+
Async do
|
69
|
+
queue = Async::PriorityQueue.new
|
70
|
+
|
71
|
+
# Start consumers with different priorities
|
72
|
+
low_priority = async do
|
73
|
+
puts "Low priority consumer got: #{queue.dequeue(priority: 1)}"
|
74
|
+
end
|
75
|
+
|
76
|
+
medium_priority = async do
|
77
|
+
puts "Medium priority consumer got: #{queue.dequeue(priority: 5)}"
|
78
|
+
end
|
79
|
+
|
80
|
+
high_priority = async do
|
81
|
+
puts "High priority consumer got: #{queue.dequeue(priority: 10)}"
|
82
|
+
end
|
83
|
+
|
84
|
+
# Add items to the queue
|
85
|
+
queue.push("first item")
|
86
|
+
queue.push("second item")
|
87
|
+
queue.push("third item")
|
88
|
+
|
89
|
+
# Output:
|
90
|
+
# High priority consumer got: first item
|
91
|
+
# Medium priority consumer got: second item
|
92
|
+
# Low priority consumer got: third item
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
## v2.28.1
|
97
|
+
|
98
|
+
- Fix race condition between `Async::Barrier#stop` and finish signalling.
|
99
|
+
|
100
|
+
## v2.28.0
|
101
|
+
|
102
|
+
- Use `Traces.current_context` and `Traces.with_context` for better integration with OpenTelemetry.
|
103
|
+
|
104
|
+
## v2.27.4
|
105
|
+
|
106
|
+
- Suppress excessive warning in `Async::Scheduler#async`.
|
107
|
+
|
108
|
+
## v2.27.3
|
109
|
+
|
110
|
+
- Ensure trace attributes are strings, fixes integration with OpenTelemetry.
|
111
|
+
|
112
|
+
## v2.27.2
|
113
|
+
|
114
|
+
- Fix `context/index.yaml` schema.
|
115
|
+
|
116
|
+
## v2.27.1
|
117
|
+
|
118
|
+
- Updated documentation and agent context.
|
119
|
+
|
120
|
+
## v2.27.0
|
121
|
+
|
122
|
+
- `Async::Task#stop` supports an optional `cause:` argument (that defaults to `$!`), which allows you to specify the cause (exception) for stopping the task.
|
123
|
+
- Add thread-safety agent context.
|
124
|
+
|
125
|
+
## v2.26.0
|
126
|
+
|
127
|
+
- `Async::Notification#signal` now returns `true` if a task was signaled, `false` otherwise, providing better feedback for notification operations.
|
128
|
+
- `require "async/limited_queue"` is required to use `Async::LimitedQueue` without a deprecation warning. `Async::LimitedQueue` is not deprecated, but it's usage via `async/queue` is deprecated.
|
129
|
+
- `Async::Task#sleep` is deprecated with no replacement.
|
130
|
+
- `Async::Task.yield` is deprecated with no replacement.
|
131
|
+
- `Async::Scheduler#async` is deprecated, use `Async{}`, `Sync{}` or `Async::Task#async` instead.
|
132
|
+
- Agent context is now available, via the [`agent-context` gem](https://github.com/ioquatix/agent-context).
|
133
|
+
|
134
|
+
### `Async::Barrier` Improvements
|
135
|
+
|
136
|
+
`Async::Barrier` now provides more flexible and predictable behavior for waiting on task completion:
|
137
|
+
|
138
|
+
- **Completion-order waiting**: `barrier.wait` now processes tasks in the order they complete rather than the order they were created. This provides more predictable behavior when tasks have different execution times.
|
139
|
+
- **Block-based waiting**: `barrier.wait` now accepts an optional block that yields each task as it completes, allowing for custom handling of individual tasks:
|
140
|
+
|
141
|
+
<!-- end list -->
|
142
|
+
|
143
|
+
``` ruby
|
144
|
+
barrier = Async::Barrier.new
|
145
|
+
|
146
|
+
# Start several tasks
|
147
|
+
3.times do |i|
|
148
|
+
barrier.async do |task|
|
149
|
+
sleep(rand * 0.1) # Random completion time
|
150
|
+
"result_#{i}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Wait for all tasks, processing them as they complete
|
155
|
+
barrier.wait do |task|
|
156
|
+
result = task.wait
|
157
|
+
puts "Task completed with: #{result}"
|
158
|
+
end
|
159
|
+
```
|
160
|
+
|
161
|
+
- **Partial completion support**: The new block-based interface allows you to wait for only the first N tasks to complete:
|
162
|
+
|
163
|
+
<!-- end list -->
|
164
|
+
|
165
|
+
``` ruby
|
166
|
+
# Wait for only the first 3 tasks to complete
|
167
|
+
count = 0
|
168
|
+
barrier.wait do |task|
|
169
|
+
task.wait
|
170
|
+
count += 1
|
171
|
+
break if count >= 3
|
172
|
+
end
|
173
|
+
```
|
174
|
+
|
175
|
+
This makes `Async::Barrier` a superset of `Async::Waiter` functionality, providing more flexible task coordination patterns, and therrefore, `Async::Waiter` is now deprecated.
|
176
|
+
|
177
|
+
### Introduce `Async::Queue#close`
|
178
|
+
|
179
|
+
`Async::Queue` and `Async::LimitedQueue` can now be closed, which provides better resource management and error handling:
|
180
|
+
|
181
|
+
- **New `close` method**: Both queue types now have a `close` method that prevents further items from being added and signals any waiting tasks.
|
182
|
+
- **Consistent error handling**: All queue modification methods (`push`, `enqueue`, `<<`) now raise `Async::Queue::ClosedError` when called on a closed queue.
|
183
|
+
- **Waiting task signaling**: When a queue is closed, any tasks waiting on `dequeue` (for regular queues) or `enqueue` (for limited queues) are properly signaled and can complete.
|
184
|
+
|
185
|
+
<!-- end list -->
|
186
|
+
|
187
|
+
``` ruby
|
188
|
+
queue = Async::Queue.new
|
189
|
+
|
190
|
+
# Start a task waiting for items:
|
191
|
+
waiting_task = Async do
|
192
|
+
queue.dequeue
|
193
|
+
end
|
194
|
+
|
195
|
+
# Close the queue - this signals the waiting task
|
196
|
+
queue.close
|
197
|
+
|
198
|
+
# These will raise Async::Queue::ClosedError
|
199
|
+
queue.push(:item) # => raises ClosedError
|
200
|
+
queue.enqueue(:item) # => raises ClosedError
|
201
|
+
queue << :item # => raises ClosedError
|
202
|
+
|
203
|
+
# Dequeue returns nil when closed and empty
|
204
|
+
queue.dequeue # => nil
|
205
|
+
```
|
206
|
+
|
207
|
+
## v2.25.0
|
208
|
+
|
209
|
+
- Added support for `io_select` hook in the fiber scheduler, allowing non-blocking `IO.select` operations. This enables better integration with code that uses `IO.select` for multiplexing IO operations.
|
210
|
+
|
211
|
+
### Use `IO::Event::WorkerPool` for Blocking Operations
|
212
|
+
|
213
|
+
The `Async::WorkerPool` implementation has been removed in favor of using `IO::Event::WorkerPool` directly. This change simplifies the codebase by delegating worker pool functionality to the `io-event` gem, which provides a more efficient and well-tested implementation.
|
214
|
+
|
215
|
+
To enable the worker pool, you can set the `ASYNC_SCHEDULER_WORKER_POOL` environment variable to `true`. This will allow the scheduler to use a worker pool for blocking operations, which can help improve performance in applications that perform a lot of CPU-bound operations (e.g. `rb_nogvl`).
|
216
|
+
|
217
|
+
### Better handling of `IO#close` using `fiber_interrupt`
|
218
|
+
|
219
|
+
`IO#close` interrupts fibers that are waiting on the IO using the new `fiber_interrupt` hook introduced in Ruby 3.5/4.0. This means that if you close an IO while a fiber is waiting on it, the fiber will be interrupted and will raise an `IOError`. This is a change from previous versions of Ruby, where closing an IO would not interrupt fibers waiting on it, and would instead interrupt the entire event loop (essentially a bug).
|
220
|
+
|
221
|
+
``` ruby
|
222
|
+
r, w = IO.pipe
|
223
|
+
|
224
|
+
Async do
|
225
|
+
child = Async do
|
226
|
+
r.gets
|
227
|
+
end
|
228
|
+
|
229
|
+
r.close # This will interrupt the child fiber.
|
230
|
+
child.wait # This will raise an `IOError` because the IO was closed.
|
231
|
+
end
|
232
|
+
```
|
233
|
+
|
234
|
+
## v2.24.0
|
235
|
+
|
236
|
+
- Ruby v3.1 support is dropped.
|
237
|
+
- `Async::Wrapper` which was previously deprecated, is now removed.
|
238
|
+
|
239
|
+
### Flexible Timeouts
|
240
|
+
|
241
|
+
When `Async::Scheduler#with_timeout` is invoked with a block, it can receive a `Async::Timeout` instance. This allows you to adjust or cancel the timeout while the block is executing. This is useful for long-running tasks that may need to adjust their timeout based on external factors.
|
242
|
+
|
243
|
+
``` ruby
|
244
|
+
Async do
|
245
|
+
Async::Scheduler.with_timeout(5) do |timeout|
|
246
|
+
# Do some work that may take a while...
|
247
|
+
|
248
|
+
if some_condition
|
249
|
+
timeout.cancel! # Cancel the timeout
|
250
|
+
else
|
251
|
+
# Add 10 seconds to the current timeout:
|
252
|
+
timeout.adjust(10)
|
253
|
+
|
254
|
+
# Reduce the timeout by 10 seconds:
|
255
|
+
timeout.adjust(-10)
|
256
|
+
|
257
|
+
# Set the timeout to 10 seconds from now:
|
258
|
+
timeout.duration = 10
|
259
|
+
|
260
|
+
# Increase the current duration:
|
261
|
+
timeout.duration += 10
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
## v2.23.0
|
268
|
+
|
269
|
+
- Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
|
270
|
+
|
271
|
+
### Fiber Stall Profiler
|
272
|
+
|
273
|
+
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:
|
274
|
+
|
275
|
+
``` bash
|
276
|
+
$ bundle add fiber-profiler
|
277
|
+
```
|
278
|
+
|
279
|
+
After adding the gem, you can enable the fiber stall profiler by setting the `FIBER_PROFILER_CAPTURE=true` environment variable:
|
280
|
+
|
281
|
+
``` bash
|
282
|
+
$ FIBER_PROFILER_CAPTURE=true bundle exec ruby -rasync -e 'Async{Fiber.blocking{sleep 0.1}}'
|
283
|
+
Fiber stalled for 0.105 seconds
|
284
|
+
-e:1 in c-call '#<Class:Fiber>#blocking' (0.105s)
|
285
|
+
-e:1 in c-call 'Kernel#sleep' (0.105s)
|
286
|
+
Skipped 1 calls that were too short to be meaningful.
|
287
|
+
```
|
288
|
+
|
289
|
+
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.
|
290
|
+
|
291
|
+
## v2.21.1
|
292
|
+
|
293
|
+
### Worker Pool
|
294
|
+
|
295
|
+
Ruby 3.4 will feature a new fiber scheduler hook, `blocking_operation_wait` which allows the scheduler to redirect the work given to `rb_nogvl` to a worker pool.
|
296
|
+
|
297
|
+
The Async scheduler optionally supports this feature using a worker pool, by using the following environment variable:
|
298
|
+
|
299
|
+
ASYNC_SCHEDULER_WORKER_POOL=true
|
300
|
+
|
301
|
+
This will cause the scheduler to use a worker pool for general blocking operations, rather than blocking the event loop.
|
302
|
+
|
303
|
+
It should be noted that this isn't a net win, as the overhead of using a worker pool can be significant compared to the `rb_nogvl` work. As such, it is recommended to benchmark your application with and without the worker pool to determine if it is beneficial.
|
304
|
+
|
305
|
+
## v2.20.0
|
306
|
+
|
307
|
+
### Traces and Metrics Providers
|
308
|
+
|
309
|
+
Async now has [traces](https://github.com/socketry/traces) and [metrics](https://github.com/socketry/metrics) providers for various core classes. This allows you to emit traces and metrics to a suitable backend (including DataDog, New Relic, OpenTelemetry, etc.) for monitoring and debugging purposes.
|
310
|
+
|
311
|
+
To take advantage of this feature, you will need to introduce your own `config/traces.rb` and `config/metrics.rb`. Async's own repository includes these files for testing purposes, you could copy them into your own project and modify them as needed.
|
312
|
+
|
313
|
+
## v2.19.0
|
314
|
+
|
315
|
+
### `Async::Scheduler` Debugging
|
316
|
+
|
317
|
+
Occasionally on issues, I encounter people asking for help and I need more information. Pressing Ctrl-C to exit a hung program is common, but it usually doesn't provide enough information to diagnose the problem. Setting the `CONSOLE_LEVEL=debug` environment variable will now print additional information about the scheduler when you interrupt it, including a backtrace of the current tasks.
|
318
|
+
|
319
|
+
> CONSOLE_LEVEL=debug bundle exec ruby ./test.rb
|
320
|
+
^C 0.0s debug: Async::Reactor [oid=0x974] [ec=0x988] [pid=9116] [2024-11-08 14:12:03 +1300]
|
321
|
+
| Scheduler interrupted: Interrupt
|
322
|
+
| #<Async::Reactor:0x0000000000000974 1 children (running)>
|
323
|
+
| #<Async::Task:0x000000000000099c /Users/samuel/Developer/socketry/async/lib/async/scheduler.rb:185:in `transfer' (running)>
|
324
|
+
| → /Users/samuel/Developer/socketry/async/lib/async/scheduler.rb:185:in `transfer'
|
325
|
+
| /Users/samuel/Developer/socketry/async/lib/async/scheduler.rb:185:in `block'
|
326
|
+
| /Users/samuel/Developer/socketry/async/lib/async/scheduler.rb:207:in `kernel_sleep'
|
327
|
+
| /Users/samuel/Developer/socketry/async/test.rb:7:in `sleep'
|
328
|
+
| /Users/samuel/Developer/socketry/async/test.rb:7:in `sleepy'
|
329
|
+
| /Users/samuel/Developer/socketry/async/test.rb:12:in `block in <top (required)>'
|
330
|
+
| /Users/samuel/Developer/socketry/async/lib/async/task.rb:197:in `block in run'
|
331
|
+
| /Users/samuel/Developer/socketry/async/lib/async/task.rb:420:in `block in schedule'
|
332
|
+
/Users/samuel/Developer/socketry/async/lib/async/scheduler.rb:317:in `select': Interrupt
|
333
|
+
... (backtrace continues) ...
|
334
|
+
|
335
|
+
This gives better visibility into what the scheduler is doing, and should help diagnose issues.
|
336
|
+
|
337
|
+
### Console Shims
|
338
|
+
|
339
|
+
The `async` gem depends on `console` gem, because my goal was to have good logging by default without thinking about it too much. However, some users prefer to avoid using the `console` gem for logging, so I've added an experimental set of shims which should allow you to bypass the `console` gem entirely.
|
340
|
+
|
341
|
+
``` ruby
|
342
|
+
require 'async/console'
|
343
|
+
require 'async'
|
344
|
+
|
345
|
+
Async{raise "Boom"}
|
346
|
+
```
|
347
|
+
|
348
|
+
Will now use `Kernel#warn` to print the task failure warning:
|
349
|
+
|
350
|
+
#<Async::Task:0x00000000000012d4 /home/samuel/Developer/socketry/async/lib/async/task.rb:104:in `backtrace' (running)>
|
351
|
+
Task may have ended with unhandled exception.
|
352
|
+
(irb):4:in `block in <top (required)>': Boom (RuntimeError)
|
353
|
+
from /home/samuel/Developer/socketry/async/lib/async/task.rb:197:in `block in run'
|
354
|
+
from /home/samuel/Developer/socketry/async/lib/async/task.rb:420:in `block in schedule'
|
355
|
+
|
356
|
+
## v2.18.0
|
357
|
+
|
358
|
+
- Add support for `Sync(annotation:)`, so that you can annotate the block with a description of what it does, even if it doesn't create a new task.
|
359
|
+
|
3
360
|
## v2.17.0
|
4
361
|
|
5
362
|
- Introduce `Async::Queue#push` and `Async::Queue#pop` for compatibility with `::Queue`.
|
data.tar.gz.sig
CHANGED
Binary file
|