# Slower with multiple threads--expected?

**URL:** <https://www.ruby-forum.com/t/slower-with-multiple-threads-expected/190050>\
**Category:** JRuby\
**Created:** [June 12, 2010, 12:52am UTC](https://www.ruby-forum.com/t/slower-with-multiple-threads-expected/190050 "2010-06-12T00:52:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [June 12, 2010, 12:52am UTC](https://www.ruby-forum.com/t/slower-with-multiple-threads-expected/190050/1 "2010-06-12T00:52:46Z")

</div>

Hi.  
I noticed that this code:

for i in 1…10000000 do; end

when run in two threads, like [gist:435159 · GitHub](http://gist.github.com/435159)

takes  
12.764s

when run on a dual core machine, whereas if you run only one of the two  
threads, it takes

11.8s

Is this expected? Reportable to jira?

-rp

---

<div class="post-metadata">

**Author:** ![rogerdpack](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/45deac/32.png) [@rogerdpack](https://www.ruby-forum.com/u/rogerdpack)\
**Post date:** [October 11, 2010, 6:37pm UTC](https://www.ruby-forum.com/t/slower-with-multiple-threads-expected/190050/2 "2010-10-11T18:37:58Z")

</div>

> takes  
> 12.764s
> 
> when run on a dual core machine, whereas if you run only one of the two  
> threads, it takes
> 
> 11.8s

Here’s another example:

using two threads:

$ time jruby --server process\_single\_ip.rb

real 1m37.403s  
user 3m9.874s  
sys 0m5.407s

using one thread:

$ time jruby --server process\_single\_ip.rb

real 2m24.468s  
user 2m23.192s  
sys 0m4.766s

You’ll notice that the overall time for using two threads is less (which  
is good), however the “user” time is far different between the two, so  
we’re not seeing linear speedup (this is with plenty of cores available,  
so that’s not the problem). So…is this worth a JIRA?
