Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: When is it safe to move a file?

by Dominus (Parson)
on Jan 15, 2001 at 04:01 UTC ( [id://51831]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: When is it safe to move a file?
in thread When is it safe to move a file?

Says kschwab:
I'm not sure how one loop runs stat() a million times though :)
Your loop runs for at least 300 seconds. If it runs 3,300 times per second, it does one million stat calls.

Replies are listed 'Best First'.
Re: Re: When is it safe to move a file?
by kschwab (Vicar) on Jan 15, 2001 at 04:20 UTC
    Oh, I see. You are figuring the rename() updates the mtime for the file. It doesn't, not on any unix variant I've used, anyhow...

    So, yes, the loop could of ended up running amock, but it could have run once and dropped out. Depends on the mtime of the file that was ftp'ed in and when the script was run.

    In any case, I added the sleep()...thanks again for the catch.

      Says kschwab:
      Oh, I see. You are figuring the rename() updates the mtime for the file.
      No, I'm not. Here is what your loop looked like before you added the sleep at my suggestion:

      while (1) { $mtime=(stat($data_file . $$))[9]; # drop out of the loop if the file hasn't # changed in 5 minutes (perhaps longer # for a wan connection ?) last if (time > $mtime + 300); }

      Suppose your program executes the rename and then enters this loop just after the remote process has finished updating the file. In that case, the file's mtime is the current time. You then spend five minutes busy-waiting in this loop.

      Or instead, suppose that the remote process reopens the file for writing just before you do the rename, and spends sixty minutes updating the file. Your program will spend 65 minutes busy-waiting in the loop.

        Argh. Not that this is even important...it just got triggered by my comment I'm not sure how one loop runs stat() a million times though :)

        You are completely right, it's wrong without the sleep(), and would most likely create problems. I've conceded that several times. Something I knew, but it slipped by.

        What I was saying is that your earlier assertations:

        • Even if the loop runs only once, you have called stat one million times and run up the load on the system for five minutes
        • Your loop runs for at least 300 seconds

        weren't exactly correct.

        Suppose that 5 minutes elapses between the file being written, and the invocation of the script. The loop drops out the first time.

        So, the "minimum time" wasn't 300 seconds. I thought perhaps you were thinking that the rename() would change the mtime.

        In any case, it was a glaring omission, and you were helpful in pointing it out.

        Sorry for the confusion.

        Whew.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://51831]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2024-04-19 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found