in reply to Re: Daemon To Check For Files
in thread Daemon To Check For Files

Won't this pound your CPU and disk by running in a tight loop?

Yes it does. Unfortunately the files have to get processed *immediately* so a cron job won't work here.

A bit more info would help here. A legacy third party app (of which I have no control over) drops a file into a directory and waits for the file to be processed by my Perl program. The Perl program processes the file and appends results to it before renaming the file to something the legacy app is expecting (the file extension is changed to .done). Once the legacy app sees the .done extension it knows processing is complete and it reads the processing results from the file. Behind that legacy app is a patient user waiting for their results hence the reason why the files must be processed immediately.

Seeing as I'm kinda stuck in legacy app hell, is there anything else my Perl daemon could do to aleviate the CPU & disk pounding here?

Replies are listed 'Best First'.
Re: Re: Re: Daemon To Check For Files
by perrin (Chancellor) on Nov 04, 2003 at 23:49 UTC
    That's pretty nasty. I can't think of anything simple that will solve the essential problem, i.e. polling the directory, but you could probably help things out just by adding a sleep(1) to the end of your loop.
      This reminded me of something I've been meaning to play with in the linux kernel:
      CONFIG_IMON:

      This enables support for imon, the inode monitor. Through imon and fam, the File Alteration Monitor, programs can express interest in individual files and directories, and the kernel will notify those programs when the files change. This enables desktops, mail readers, administration tools, etc. to respond to changes in the system immediately. If you don't enable imon, such programs will have to poll files (by checking them every few seconds) to determine whether they've changed.

      See http://oss.sgi.com/projects/fam/ for more information on imon.

      If you don't know whether you want imon, it doesn't do any harm to say N here. (If you want imon, say M, not Y.)

      This option lives under 'File Systems' and is called 'Inode Monitor Support'. If this file processing is important enough this may help you - assuming you are on linux...

      --tidiness is the memory loss of environmental mnemonics