What is the best way to send requests asynchronously with Celluloid ?

69 views
Skip to first unread message

Eqbal Qur'an

unread,
Feb 13, 2013, 11:01:51 AM2/13/13
to cellulo...@googlegroups.com
I have this ruby class : 

    require "celluloid"
    require "curb"

    class Sender 
      include Celluloid

      def send_url
         Curl.get(URL)
      end
    end

And another worker which is supposed to to use this class, something like 

    pool = Sender.pool(:size => 50)
    (1..10000).each do 
      pool.send_url
    end

Now since I'm new here, I want the worker to send 50 requests together instead of waiting for each request till it's done, am I doing it the right way like this or do I need to change  pool.send_url to pool.send_url! ? would the pool this way delegate the request to 50 workers directly or it will wait for each to finish before doing that? 

Thanks in advance 
Eqbal  

        
     

Josh Adams

unread,
Feb 13, 2013, 11:13:31 AM2/13/13
to cellulo...@googlegroups.com
pool.future.send_url


Eqbal  

        
     

--
You received this message because you are subscribed to the Google Groups "Celluloid" group.
To unsubscribe from this group and stop receiving emails from it, send an email to celluloid-rub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Josh Adams
CTO | isotope|eleven
[cell] (205) 215-3957
[work] (877) 476-8671 x201

Tony Arcieri

unread,
Feb 13, 2013, 6:58:43 PM2/13/13
to cellulo...@googlegroups.com
Yes, you can use pool.async.send_url or pool.future.send_url depending on how you want to handle the result.

Also I'd probably recommend not using Curl/Curb. Net::HTTP::Persistent is quite fast and supports a thread-safe connection pool.
Tony Arcieri
Reply all
Reply to author
Forward
0 new messages