by greg@[EMAIL PROTECTED]
(Greg Jetter)
Apr 25, 2007 at 09:14 AM
On Wednesday April 25 2007 8:42 am, Varj=C3=BC Tam=C3=A1s wrote:
> Dear Greg!
>
> The reason I did the test, and why I detailed the result is that I could
> not reproduce any of the nasty things which can happen without locking.
> I know that everyone suggests to use the lock, but following your
> argument the test should have had a different outcome.
>
> Any idea how to improve the test to realise potential data loss? It
> would convince me beyond "to be on the safe side".
>
> Kanya
you example I think features two processes accessing the same file , now
=
a=20
typical web application may have 2000 to 2 million processes going at
the=
=20
file at the same time ... example being some thing like a search
engine.=20
To test or produce a race condition or over writing , put the
script=
=20
under a real world load .
fork 20 or thirty instances of your script at the same time and let them
h=
ave=20
a go at the file. then look at the results and see if it's what you think
=
it=20
should be. bet it won't be :)
If you are certain that no more than 2 processes will ever access the
fi=
le=20
then feel free to forgo file locking . I have personal seen this happen
wit=
h=20
as little as three processes accessing the same file... There is a
reason=20
everyone suggest using file locking it's because we have all "been their
an=
d=20
done that". it's a common mistake new programmers make.
ask yourself "why do Data Base programs have row locking ? " it's the
same=
=20
thing.
Greg
=20