[Yum-devel] URLGrabber Batch Mode
Michael Stenner
mstenner at linux.duke.edu
Sun Feb 29 02:31:34 UTC 2004
I got ahead of myself. I'm now coming back to this original email.
On Sat, Feb 28, 2004 at 06:19:51AM -0500, Ryan Tomayko wrote:
> Two separate requests have come up that have me thinking about being
> able to use URLGrabber in a sort-of batch mode:
>
> 1. Grabbing in a forked sandbox type thing for security reasons.
> 2. Grabbing files in parallel using multiple threads.
Eek. These are almost two completely different issues, but I see the
connection.
> I was thinking one way of accomplishing this might be to add some kind
> of BatchedURLGrabber/BatchedMirrorGroup class that would have pretty
> much the same interface as URLGrabber/MirrorGroup but instead of
> actually grabbing the files when the methods were called, it would keep
> a list of the url/kwargs. Once you ran through calling urlXXX for each
> file you would then call a "batchgrab" method that could do a variety of
> things including:
I hadn't thought of that approach. That has its merits, too. It's
not quite as good at being a drop-in replacement as one might hope
because of the return value and the fact that immediately after you do
batch_grabber.urlgrab(url) nothing has yet been done, and so a program
that expects the file to be there will break. This may be ok for yum,
but in general, it will not work.
> 1. Fork, setuid, and pull all files in the list. The synchronization
> between processes (via sockets or whatever) could be handled in the
> batchgrab method so it would feel as if it were a normal synchronous
> in-process call.
>
> 2. The batchgrab method could handle splitting off some number of
> threads to use when grabbing files and orchestrating mirror usage (to be
> sure only n connections were open to a single server at a time).
OK. The details of interface are not relevant to this discussion (I
think) which is a nice separation. This could work the way I
described in my previous email too, so we don't need to mix
discussions.
I agree that this is the right way to go. Obviously, 1 should be
optional, and should not be our first priority (if we do any of this
at all). It should basically work like this:
if not we_are_forking:
return thready_batchy_function(args)
else:
SET UP PIPES
pid = fork()
if not pid: # we are child
DROP PRIVS
ret = thready_batchy_function(args)
PICKLE ret
SEND PICKLED RETURN VALUE TO PARENT
EXIT
else: # we are parent
READ PICKED RETURN VALUE FROM CHILD
UNPICKLE IT
return ret
> None of this would be easy and there's a ton of stuff to think about.
> What I'm wondering is 1.) do we feel URLGrabber is the right place to be
> doing this kind of work? and 2.) does the idea of using a
> BatchedURLGrabber class make sense?
Like I said in the other message. I think this would be OK in a
separate module within urlgrabber. I DO NOT think everything should
be rewritten to deal with it. If the MirrorGroup class (for example)
absolutely cannot be made threadsafe without importing the threading
module, then I'd be tempted to say subclass it inside batch.py to fix
the things that need fixing. I'm pretty open on the details, though.
-Michael
--
Michael D. Stenner mstenner at ece.arizona.edu
ECE Department, the University of Arizona 520-626-1619
1230 E. Speedway Blvd., Tucson, AZ 85721-0104 ECE 524G
More information about the Yum-devel
mailing list