Every Night At Midnight

Proposed AntiPattern: EveryNightAtMidnight.

Symptoms: Cron jobs that run at intervals which are always both far too frequent and far too infrequent, at the same time. Code that runs at unpredictable, often user triggered times, that checks if an update is needed, and makes the user wait while its done.

Synopsis: Inelegant polling is done in a situation where a low priority daemon thread needs to be notified. Typical of cache scenarios and database summary tables, especially in applications where it is impossible to regenerate or update the information as frequently as required. As a result of polling, the process doesn't start working as soon as it should start, yet often starts working when there is no work to be done.

Resolution: If your environment isn't a multithreaded persistent system, there is little recourse. If your system is, code the task implementing the daemon to sleep on a work queue. When work is added to the work queue, the task will be notified, and it will awaken, attempt to limit the amount of work by details passed to it in the work queue if limit of the scope of work can be expressed, and then resume sleeping on the queue.

Thanks in advance to anyone who cleans this up, and deletes this message.

-- ScottWalters

Note that 'midnight' may take on arbitrary values. If your activity happens to be making backups of a wiki frequented by people who tend to stay up late, midnight might be 0500. Of course, whatever time, as long as it's on an hour, is midnight somewhere.


EditText of this page (last edited August 28, 2002) or FindPage with title or text search