I’d be interested in any comments on the attached solution (especially
flaws
that I’ve overlooked); if it is sound then I’ll stick it up on the Wiki.
That’s pretty interesting.
I take it this solves threading and pooling at
the same time, and it’s transparent from the
client end?
I"m a little fuzzy on the details of how
it works. Do you feel like clarifying?
Sure. @pool is created as an array of object instances. Whenever an
incoming method request arrives, the facade picks one off the front of the
array. If it has an ‘alive?’ method then it checks that first, and replaces
it with a fresh object if it returns false. It then sends it the requested
message. The ‘ensure’ clause puts it back at the end of the array after the
method has finished (successfully or not).
Modifications to @pool are mutex-protected. The objects themselves need no
mutex, because each one is removed from the pool while it is processing a
message, and therefore it won’t receive a second one.
For example: Does every object have to have
alive? and suicide methods, or is this just
an example?
‘suicide’ was just an example, but it shows how to use ‘alive?’
My thinking is than a pool object may often contain other objects, for
example a DBI handle. If something goes seriously wrong with that and the
database disconnects, it is more convenient for the pool object to signal
that it wishes to be recreated from scratch, than having to handle the
re-initialisation of its component objects itself.
Why is alive? defined in the
module?
If the user happens to send an ‘alive?’ message to the pool front object, it
would be forwarded to an arbitrary member of the pool, which is a bit of a
waste of time. In particular, it might happen if you set up a chain of
objects, where a pool contains objects which are themselves DRb front-ends
to a remote object pool:
machine A machine B
P1 ,-- O1 --. P2 ,-- O4
----> SimplePool --- O2 ----------> SimplePool --- O5
`-- O3 --' `-- O6
(I had this running with protocol P1 = SOAP and protocol P2 = DRb !)
As part of its normal operation, SimplePool sends ‘alive?’ to O1/O2/O3, and
it’s pretty pointless to proxy this to a random selection out of O4/O5/O6.
However, in this case, it would be better for O1/O2/O3 to trap ‘alive?’
locally to save the round-trip requests.
Actually, I was seeing exceptions raised, and I think I was being confused
by the fact that ‘respond_to?’ and ‘alive?’ can’t be sent directly over SOAP
without mapping to a different name (which doesn’t contain a question mark).
NaHi is going to improve the error reporting in that case.
If the short-circuit ‘alive?’ were removed, I wouldn’t have an objection
Regards,
Brian.
···
On Wed, Mar 12, 2003 at 09:26:21AM +0900, Hal E. Fulton wrote: