Forum: Ruby on Rails backgroundrb concurrent client access, results services

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6d725706c09fcc3f3452efd18582527a?d=identicon&s=25 Mike Hang (mhang)
on 2007-07-15 00:37
First thank to backgroundrb, it sure makes distribute computing a lot
easier.  A couple of questions:
1. I don't fully understand the reason for Results services, can I just
create instance vars, methods within the Worker class help to exposed
shared result data?  I did notice about results being alive after the
Worker is deleted. Is this the only reason?

2. Continue with the first question, since I have no need to access data
after the Worker is deleted, I rather not introduce additional book
keeping. I want to introduce instance vars and methods to access data
within the Worker. Will I have to worry data corruption/sync problem if
I have multiple MiddleMan clients  accessing the same Worker that may be
calling instance vars and/or methods at the same time. Or if I just use
the Results service, my worries goes away. I guess I will spend sometime
soon digging into the codes to better understand it, but in the mean
time any info would be greatly appreciated.

Thanks,
Mike
6076c22b65b36f5d75c30bdcfb2fda85?d=identicon&s=25 Ezra Zygmuntowicz (Guest)
on 2007-07-15 01:00
(Received via mailing list)
On Jul 14, 2007, at 3:37 PM, Mike Hang wrote:

> data
> soon digging into the codes to better understand it, but in the mean
> time any info would be greatly appreciated.
>
> Thanks,
> Mike

Mike-

  Stay away from the results worker and just use methods and instance
variables. The results worker is only useful if you want to keep some
results around after you kill your worker. ALso the results worker is
a tad broken right now as well.

  If you need to have multiple access to variables in a worker then
you may need to synchronize access to instance variables and methods
with a mutex. add a 'lock' helper method like this to your worker:

def lock
   @_lock ||= Mutex.new
   @_lock.synchronize { yield }
end

  And then use it every time you have an area of code that could get
accessed by multiple clients at once:

def important_method
   lock do
     # some important thing in here that only
     #should be accessed by one thread at a time
   end
end


Cheers-
-- Ezra Zygmuntowicz
-- Founder & Ruby Hacker
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
This topic is locked and can not be replied to.