We track the number of messages in each postfix queue on our
mailservers using a program I've written.  For most queues,
it simply does a readdir() and counts all files whose names don't
begin with ".", which is quick and efficient.  For the deferred queue,
it does a find-style walk through the directory tree.  Unfortunately,
on our fallback relays the deferred queues can get very large, and
walking the tree becomes a long and expensive endeavor.

By far the largest amount of time and I/O is spent calling stat() on
hundreds of thousands of queue files to determing that they're simple
files rather than directories to descend into.  I could avoid that two
ways:

1. If I could tell simply from the filename whether it's a queue file
   or a subdirectory: for example, if the name is 3 characters or
   longer it's a queue file, shorter than 3 it's a directory.

2. If the tree structure were static enough that I could make
   assumptions about it: for example, every file in the top level is a
   subdirectory, every file in a subdirectory is a queue file.

I can look at what I've got and extrapolate rules like the above,
but I don't know whether postfix *might* do something differently
later on that I just haven't seen, and I don't know whether the "rule"
I'm using will apply to other versions of postfix.

Are there any solid rules I can use to avoid calling stat on
everything when counting the deferred queue and any other hierarchical
queues postfix may have in current and future versions?
  -- Cos

Reply via email to