I tested ractors in ruby with docker and without
this is my script
threads = []
ractors = []
Benchmark.bm do |x|
x.report("Single thread:") do
cpu_intensive_task
cpu_intensive_task
end
x.report("Two threads:") do
2.times do
threads << Thread.new { cpu_intensive_task }
end
threads.each(&:join)
end
x.report("Two ractors:") do
2.times do
ractors << Ractor.new { cpu_intensive_task }
end
ractors.each(&:take)
end
end
when I run it local I see
user system total real
Single thread: 0.938003 0.000150 0.938153 ( 0.942506)
Two threads: 0.931752 0.000313 0.932065 ( 0.937688)
Two ractors: 1.177639 0.000387 1.178026 ( 0.592312)
but when I run it docker container I see
user system total real
Single thread: 1.221073 0.000000 1.221073 ( 1.221220)
Two threads: 1.200631 0.001995 1.202626 ( 1.201255)
Two ractors: 2.448438 0.000995 2.449433 ( 1.314552)
how to see real multithreading in docker?
I tried to configure my container with command like a
docker run --rm -it -v
pwd:/app --memory="1g" --memory-swap="1g" --cpus="4" --ipc='shareable' ruby bash
but nothing helps.
New contributor
Michael is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.