Roggie Boone
2008-May-09 13:15 UTC
[Backgroundrb-devel] register_status for excess thread_pool?
Hi, Newbie here. I''ve got a worker (for generating PDF reports) that uses the "thread_pool" to allow processing multiple reports simultaneously and queue up any requests that exceed the thread pool (pool_size = 10 currently). def process_pdf(user) thread_pool.defer(user) do |user| makepdf(user) end end My question is: I use a mutex to handle synchronizing the register_status. This works fine: def makepdf(user) txt = user.to_s + " started" save_status(user, :progress, txt) do_report(user) txt = user.to_s + " ended" save_status(user, :progress, txt) end def save_status(user_id,key,data) @status_mutex.synchronize do @worker_status[user_id] = { :key => key, :data => data} end register_status(@worker_status) end However, if more than 10 requests are submitted to the worker at a time, those in excess of 10 are queued and thus never get assigned a status in register_status. So, in my Rails/ajax view, I have no "status" to display while the user waits. I read that one shouldn''t use the register_status inside the thread_pool.defer block. Is there an alternate way to show a "pending" status to requests that have been deferred due to exceeding the thread pool? Thanks, Rog --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080509/6ac6a838/attachment.html>
Stevie Clifton
2008-May-09 13:31 UTC
[Backgroundrb-devel] register_status for excess thread_pool?
Hey Roggie, If I''m reading your code correctly, the simplest way would just be to call your save_status method before thread_pool. That way you would guarantee that each pdf job would start out with a "pending" state that would change only when there''s a free thread to handle that job. def process_pdf(user) save_status(user, :progress, "#{user} pending") thread_pool.defer(user) do |user| makepdf(user) end end>On Fri, May 9, 2008 at 9:15 AM, Roggie Boone <rogboone at yahoo.com> wrote:> Hi, > > Newbie here. I''ve got a worker (for generating PDF reports) that > uses the "thread_pool" to allow processing multiple reports > simultaneously and queue up any requests that exceed the thread > pool (pool_size = 10 currently). > > def process_pdf(user) > thread_pool.defer(user) do |user| > makepdf(user) > end > end > > My question is: I use a mutex to handle synchronizing the > register_status. This works fine: > > def makepdf(user) > txt = user.to_s + " started" > save_status(user, :progress, txt) > do_report(user) > txt = user.to_s + " ended" > save_status(user, :progress, txt) > end > > def save_status(user_id,key,data) > @status_mutex.synchronize do > @worker_status[user_id] = { :key => key, :data => data} > end > register_status(@worker_status) > end > > However, if more than 10 requests are submitted to the worker > at a time, those in excess of 10 are queued and thus never > get assigned a status in register_status. So, in my Rails/ajax > view, I have no "status" to display while the user waits. > I read that one shouldn''t use the register_status inside the > thread_pool.defer block. Is there an alternate way to > show a "pending" status to requests that have been deferred > due to exceeding the thread pool? > > Thanks, > Rog > > ________________________________ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now. > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >