Skip to content

Commit 611fac9

Browse files
Merge pull request #451 from ruby/mvh-knuecleotide-refactor
Redesign the Ractor/Knucleotide benchmark
2 parents e1e2ae3 + 7343ad5 commit 611fac9

File tree

18 files changed

+285
-180
lines changed

18 files changed

+285
-180
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
strategy:
6565
fail-fast: false
6666
matrix:
67-
ruby: [ruby, head]
67+
ruby: [head]
6868
if: ${{ github.event_name != 'schedule' || github.repository == 'ruby/ruby-bench' }}
6969
steps:
7070
- uses: actions/checkout@v3
@@ -85,7 +85,7 @@ jobs:
8585
strategy:
8686
fail-fast: false
8787
matrix:
88-
ruby: [ruby, head]
88+
ruby: [head]
8989
if: ${{ github.event_name != 'schedule' || github.repository == 'ruby/ruby-bench' }}
9090
steps:
9191
- uses: actions/checkout@v3

benchmarks.yml

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ graphql-native:
9191
desc: GraphQL gem parsing a large file, but using a native parser
9292
knucleotide:
9393
desc: k-nucleotide from the Computer Language Benchmarks Game - counts nucleotide frequencies using hash tables in parallel using Process.fork
94+
knucleotide-ractor:
95+
desc: k-nucleotide from the Computer Language Benchmarks Game - counts nucleotide frequencies using hash tables in parallel using Ractors
96+
ractor: true
97+
ractor_only: true
98+
default_harness: harness
9499
lee:
95100
desc: lee is a circuit-board layout solver, deployed in a plausibly reality-like way
96101
matmul:
@@ -231,13 +236,20 @@ throw:
231236
ractor: true
232237

233238
#
234-
# Ractor-only benchmarks
239+
# Ractor scaling benchmarks
235240
#
236-
ractor/knucleotide:
237-
desc: k-nucleotide from the Computer Language Benchmarks Game - counts nucleotide frequencies using hash tables. Counts groups in parallel using Ractors.
238-
ractor/gvl_release_acquire:
241+
gvl_release_acquire:
239242
desc: microbenchmark designed to test how fast the gvl can be acquired and released between ractors.
240-
ractor/json_parse_float:
243+
ractor: true
244+
ractor_only: true
245+
default_harness: harness-ractor
246+
json_parse_float:
241247
desc: test the performance of parsing multiple lists of json floats with ractors.
242-
ractor/json_parse_string:
248+
ractor: true
249+
ractor_only: true
250+
default_harness: harness-ractor
251+
json_parse_string:
243252
desc: test the performance of parsing multiple lists of strings with ractors.
253+
ractor: true
254+
ractor_only: true
255+
default_harness: harness-ractor
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

benchmarks-ractor/knucleotide/benchmark.rb renamed to benchmarks/knucleotide-ractor/benchmark.rb

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
33
#
44
# k-nucleotide benchmark - Ractor implementation
5-
# Mirrors the Process.fork version structure as closely as possible
5+
# Mirrors the Process.fork version: spawns 7 ractors (one per task)
66

7-
require_relative "../../harness/loader"
7+
Warning[:experimental] = false
8+
9+
require_relative '../../harness/loader'
810

911
def frequency(seq, length)
1012
frequencies = Hash.new(0)
@@ -25,9 +27,9 @@ def sort_by_freq(seq, length)
2527
table.sort { |a, b|
2628
cmp = b[1] <=> a[1]
2729
cmp == 0 ? a[0] <=> b[0] : cmp
28-
}.map! { |seq, count|
30+
}.map { |seq, count|
2931
"#{seq} #{'%.3f' % ((count * 100.0) / n)}"
30-
}.join("\n") << "\n\n"
32+
}.join("\n") + "\n\n"
3133
end
3234

3335
def find_seq(seq, s)
@@ -48,19 +50,22 @@ def generate_test_sequence(size)
4850
full_copies.times { sequence << alu }
4951
sequence << alu[0, remainder] if remainder > 0
5052

51-
sequence.upcase.freeze
53+
sequence.upcase
5254
end
5355

54-
# Make sequence shareable for Ractors
55-
TEST_SEQUENCE = make_shareable(generate_test_sequence(100_000))
56+
TEST_SEQUENCE = Ractor.make_shareable(generate_test_sequence(100_000))
5657

57-
run_benchmark(5) do |num_ractors, ractor_args|
58+
run_benchmark(5) do
5859
freqs = [1, 2]
5960
nucleos = %w(GGT GGTA GGTATT GGTATTTTAATT GGTATTTTAATTTATAGT)
6061

61-
# Sequential version - mirrors Process version but without Workers
62-
results = []
63-
freqs.each { |i| results << sort_by_freq(TEST_SEQUENCE, i) }
64-
nucleos.each { |s| results << find_seq(TEST_SEQUENCE, s) }
62+
ractors = freqs.map { |i|
63+
Ractor.new(TEST_SEQUENCE, i) { |seq, len| sort_by_freq(seq, len) }
64+
}
65+
ractors += nucleos.map { |s|
66+
Ractor.new(TEST_SEQUENCE, s) { |seq, nucleo| find_seq(seq, nucleo) }
67+
}
68+
69+
results = ractors.map(&:value)
6570
results
6671
end

0 commit comments

Comments
 (0)