# Need advice: threads or Typhoeus?

**URL:** <https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364>\
**Category:** Rails\
**Created:** [January 10, 2010, 10:54pm UTC](https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364 "2010-01-10T22:54:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [January 10, 2010, 10:54pm UTC](https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364/1 "2010-01-10T22:54:10Z")

</div>

Hi guys,

I need my app to make a few hundreds requests to external web services  
as quickly as possible. The web services are fairly fast, but still:  
if I do the requests one after the other, it is too slow.  
My understanding is I have two options:  
a- Threads.  
b- Typhoeus

Typhoeus seems great. Yet, the web services are all quite different  
(some are SOAP, some REST…) and therefore wrapped into interfaces. I  
might be able to implement Typhoeus but it means a lot of changes.  
I have read that threads in Rails can be challenging to implement  
especially when dealing with the DB. Yet, this part of my code doesn’t  
do anything with ActiveRecord. Are threads generally “OK” if no  
connection to the DB is involved?

Thanks a lot for your recommendations.

Pierre

---

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [January 10, 2010, 11:00pm UTC](https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364/2 "2010-01-10T23:00:37Z")

</div>

Hello there Pierre,

Threads are not really threads in ruby, so forget about threads.

Instead use a background process for that. You can accomplish that using  
some gem for creating background processes.  
Delayed Job may be a solution for you.

[]'s  
Rodrigo D.

---

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [January 10, 2010, 11:22pm UTC](https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364/3 "2010-01-10T23:22:16Z")

</div>

Thanks Rodrigo.

The thing is, my main challenge here is speed: I have to wait for the  
answers to the requests to be able “continue”. Therefore I am not sure  
about background processes (or delayed job): are they going to make  
the requests faster? Will they be able to run concurrently?

Thanks,  
Pierre

---

<div class="post-metadata">

**Author:** ![PierreW](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/da6949/32.png) [@PierreW](https://www.ruby-forum.com/u/PierreW)\
**Post date:** [January 10, 2010, 11:27pm UTC](https://www.ruby-forum.com/t/need-advice-threads-or-typhoeus/181364/4 "2010-01-10T23:27:32Z")

</div>

Pierre,

If you need speed, you can spawn multiple processes at the same time.  
That  
will increase your throughput. Logically that depends on how powerful  
your  
machine is.

You can check [railscasts.com](http://railscasts.com) for background processing casts.

[]'s  
Rodrigo D.
