Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ throw:
single_file: true
ractor: true

#
# Thread benchmarks
#
threads_io_with_cpu:
desc: Benchmark to test how long I/O takes to complete when there's a mix of IO-bound and CPU-bound threads.
category: thread
single_file: true

#
# Ractor scaling benchmarks
#
Expand Down
69 changes: 69 additions & 0 deletions benchmarks/threads_io_with_cpu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative '../harness/loader'

require "socket"
num_cpu_threads = 1
num_io_threads = 1

server_started = false

def start_tcp_server(&started)
Thread.new do
server = TCPServer.new('localhost', 0) # random open port
started.call(server.local_address.ip_port)

loop do
client = server.accept
client.close
# Don't get request or generate response, it makes the benchmark take too long
end
end
end

def open_tcp_connection(host, port)
TCPSocket.open(host, port) { }
end

def fib(n)
return n if n <= 1
fib(n - 1) + fib(n - 2)
end

server_started = false
port = nil
start_tcp_server do |server_port|
server_started = true
port = server_port
end
loop until server_started

io_requests_threshold = 5 # per thread

run_benchmark(5) do
io_threads = num_io_threads.times.map do
Thread.new do
io_requests_made = 0
loop do
open_tcp_connection("localhost", port)
io_requests_made += 1
if io_requests_made >= io_requests_threshold
break
end
end
end
end

stop_looping = false

cpu_threads = num_cpu_threads.times.map do
Thread.new do
loop do
fib(30)
break if stop_looping
end
end
end

io_threads.each(&:join)
stop_looping = true
cpu_threads.join
end
2 changes: 1 addition & 1 deletion lib/argument_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def parse(argv)
args.out_override = v
end

opts.on("--category=headline,other,micro,ractor", "when given, only benchmarks with specified categories will run") do |v|
opts.on("--category=headline,other,micro,thread,ractor", "when given, only benchmarks with specified categories will run") do |v|
args.categories += v.split(",")
if args.categories == ["ractor"]
args.harness = "harness-ractor"
Expand Down
2 changes: 1 addition & 1 deletion test/run_benchmarks_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
it 'benchmarks.yml has valid category values' do
require 'yaml'
data = YAML.load_file(@benchmarks_yml)
valid_categories = ['headline', 'micro', 'other']
valid_categories = ['headline', 'micro', 'thread', 'other']

data.each do |name, metadata|
if metadata['category']
Expand Down
Loading