Great Circle Associates Majordomo-Workers
(September 1996)
 

Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: Re: Patch for 1.94 to avoid starvation when looping for lock
From: Dave Wolfe <dwolfe @ risc . sps . mot . com>
Date: Thu, 26 Sep 1996 10:00:11 -0500 (CDT)
To: gnu @ toad . com (John Gilmore)
Cc: majordomo-workers @ greatcircle . com (Majordomo developer's mailing list)
In-reply-to: <199609260135.SAA05454@toad.com> from "John Gilmore" at Sep 25, 96 06:35:39 pm
Reply-to: Dave Wolfe <david_wolfe @ risc . sps . mot . com>

[ John Gilmore writes: ]
> 
> Exponential backoff is the preferred approach -- e.g. back off 1
> second the first time, 2 the second, 4 the third, 8 the fourth, etc.

Let's see, 2**600 is Really Big (TM) (181 digits according to bc). I
think sleep() might have a problem with that. :-) But I'm not sure
everyone backing off at the same rate, whether exponential, linear,
quadratic, or whatever, would help as much as a random sleep.

I know this has all been discussed before (sorry, I don't remember
exactly what Brent (? somebody) wanted to do about file locking, but I
think it was to have queued locks so the request order was preserved and
all the fighting for the lock was eliminated), but that implementation
was definitely on hold for a later release (2.x?). As for file locking,
Brent recently commented on that to reiterate how that isn't as portable
as lock files. So before someone tries to slip this into 1.94, let's
take a look at something like this for a quick fix:

    srand(time ^ $$); # or some reasonably unique seed
    for ($tries = 1; $tries < $retries; $tries++) {
	# Try to obtain the lock $retries times, waiting at least 1 second
	# after each try
	if (&main'shlock("$lockfile")) {
	    # Got the lock; now try to open the file
	    $status = open($FH, $fm);
    ...
	    # return the success or failure of the open
	    return($status);
	} else {
	    # didn't get the lock; wait awhile and try again.
	    sleep(1 + rand(9)); # wait 1 to 10 seconds
	}
	   }
	   # If we get this far, we ran out of tries on the lock.

I first thought of looping on a fixed time limit, but that won't work
because it makes the number of lock tries indeterminate (possibly zero).
A fixed number of tries makes the time spent vary widely (e.g. 600 tries
could take 600 to 6000 seconds (5 to 50 minutes), not counting time
spent waiting to run), but that seems preferable to unreproducible lock
failures.

-- 
 Dave Wolfe    *Not a spokesman for Motorola*
 Motorola MMTG  6501 Wm. Cannon Dr. W. OE112  Austin  TX  78735-8598


Follow-Ups:
References:
Indexed By Date Previous: Re: Majordomo 1.94 Beta 3, whee!!
From: "Randall S. Winchester" <rsw@Glue.umd.edu>
Next: Re: Patch for 1.94 to avoid starvation when looping for lock
From: John Gilmore <gnu@toad.com>
Indexed By Thread Previous: Patch for 1.94 to avoid starvation when looping for lock
From: John Gilmore <gnu@toad.com>
Next: Re: Patch for 1.94 to avoid starvation when looping for lock
From: John Gilmore <gnu@toad.com>

Google
 
Search Internet Search www.greatcircle.com