Changeset 280

Show
Ignore:
Timestamp:
12/16/07 04:16:04 (8 months ago)
Author:
gethema..@gmail.com
Message:

check in fixes to README about thread pools

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r279 r280  
    332332 
    333333 
    334 * Using Threads inside BackgrounDRb 
     334* Using Threads inside BackgrounDRb : 
    335335 
    336336  Remember BackgrounDRb follows event model of network programming, but sad truth of life is 
    337337  not all networking libraries follow this model and hence they make use of blocking IO and threads. 
    338   But you need not fear, BackgrounDRb allows you to run all such tasks concurrently in threads 
     338  BackgrounDRb allows you to run all such tasks concurrently in threads 
    339339  which are internally managed by BackgrounDRb thread pool. 
    340340 
    341   Each worker has access to object "thread_pool" which can be used to run task in threads concurrently. 
     341  Each worker has access to object +thread_pool+ which can be used to run task in a thread concurrently. 
    342342 
    343343    thread_pool.defer(wiki_scrap_url) { |wiki_url| scrap_wikipedia(wiki_url) } 
    344344 
    345   So whatever task you specify within scrap_wikipedia() is going to run concurrently. 
     345  So whatever task you specify within +scrap_wikipedia+ is going to run concurrently. 
    346346 
    347347  WARNING: You shouldn't try to use +register_status+ method from within the block supplied to +defer+. Because, if you do that, 
     
    387387   end 
    388388 
     389  All above helper file does is that it stubs out, relevant worker methods, 
     390  which really need network IO. There can be methods added, which aren't 
     391  stubbed, for all such methods you are encouraged to stub them and send 
     392  the patch to the backgroundrb mailing list. 
     393 
    389394 
    390395 
  • trunk/script/bdrb_test_helper.rb

    r266 r280  
    1 require File.join(File.dirname(__FILE__) + "/../config/environment") 
     1require File.dirname(__FILE__) + '/../test_helper' 
    22WORKER_ROOT = RAILS_ROOT + "/lib/workers" 
    33$LOAD_PATH.unshift(WORKER_ROOT) 
  • trunk/server/meta_worker.rb

    r279 r280  
    3737    # can be used to make a call in threaded manner 
    3838    # passed block runs in a thread from thread pool 
     39    # for example in a worker method you can do: 
    3940    #   def fetch_url(url) 
    4041    #     puts "fetching url #{url}" 
     
    5253    # you can invoke above method from rails as: 
    5354    #   MiddleMan.ask_work(:worker => :rss_worker, :worker_method => :fetch_url, :data => "www.example.com") 
     55    # assuming method is defined in rss_worker 
    5456 
    5557    def defer(*args,&block)