Ruby poor performance in thread -
i have function io/computation. made demo function copies ~300mb here there. if run in thread join, slower if run without thread. checked with:
def cp start = time.now fileutils.cp_r("c:/tmp", "c:/tmp1") fin = time.now - start p fin end
comparing these:
cp thread.new{cp}.join
the first cp
call 2 4 times faster threaded call. same happens if do
cp thread.new{cp} sleep 200
i heard gil, etc., here, 1 thread runs @ time, no race running time. ideas on how can make faster or why happening?
threading isn't guarantee things run faster, or same speed, non-threaded code, @ least mri. jruby might better. cp
isn't getting full attention of cpu, why doing without threading, , allowing block until done, faster.
consider using fork
instead.
"a dozen (or so) ways start sub-processes in ruby: part 1" looks useful. "how spawn child process in ruby?".
Comments
Post a Comment