Skip to content

Commit 5287826

Browse files
committed
Async now gives each object its own thread.
1 parent 455203e commit 5287826

File tree

5 files changed

+301
-143
lines changed

5 files changed

+301
-143
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
### Upcoming Release v1.0.0.pre2 (TBD)
22

33
* Simplification of `RubySingleThreadExecutor`
4+
* `Async` improvements
5+
- Each object uses its own `SingleThreadExecutor` instead of the global thread pool.
6+
- No longers supports executor injection
7+
- Much better documentation
48

59
## Current Release v1.0.0.pre1 (19 Aug 2015)
610

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ This library contains a variety of concurrency abstractions at high and low leve
6161

6262
#### General-purpose Concurrency Abstractions
6363

64-
* [Async](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html): A mixin module that provides simple asynchronous behavior to any standard class/object or object.
64+
* [Async](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Async.html): A mixin module that provides simple asynchronous behavior to a class. Loosely based on Erlang's [gen_server](http://www.erlang.org/doc/man/gen_server.html).
6565
* [Future](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Future.html): An asynchronous operation that produces a value.
6666
* [Dataflow](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent.html#dataflow-class_method): Built on Futures, Dataflow allows you to create a task that will be scheduled when all of its data dependencies are available.
6767
* [Promise](http://ruby-concurrency.github.io/concurrent-ruby/Concurrent/Promise.html): Similar to Futures, with more features.

examples/benchmark_async.rb

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env ruby
2+
3+
$: << File.expand_path('../../lib', __FILE__)
4+
5+
require 'benchmark'
6+
require 'benchmark/ips'
7+
8+
require 'concurrent'
9+
require 'celluloid'
10+
11+
class CelluloidClass
12+
include Celluloid
13+
def foo
14+
end
15+
def bar(latch)
16+
latch.count_down
17+
end
18+
end
19+
20+
class AsyncClass
21+
include Concurrent::Async
22+
def foo
23+
end
24+
def bar(latch)
25+
latch.count_down
26+
end
27+
end
28+
29+
IPS_NUM = 100
30+
BMBM_NUM = 100_000
31+
32+
Benchmark.ips do |bm|
33+
latch = Concurrent::CountDownLatch.new(1)
34+
celluloid = CelluloidClass.new
35+
bm.report('celluloid') do
36+
IPS_NUM.times { celluloid.async.foo }
37+
celluloid.bar(latch)
38+
latch.wait
39+
end
40+
41+
async = AsyncClass.new
42+
latch = Concurrent::CountDownLatch.new(1)
43+
bm.report('async') do
44+
IPS_NUM.times { async.async.foo }
45+
async.bar(latch)
46+
latch.wait
47+
end
48+
49+
bm.compare!
50+
end
51+
52+
#Benchmark.bmbm do |bm|
53+
#bm.report('celluloid') do
54+
#end
55+
#bm.report('async') do
56+
#end
57+
#end

0 commit comments

Comments
 (0)