High Frequency Cron Monitoring

Effectively monitor crons that run very frequently

High frequency crons represent a particular monitoring challenge. Whether they are workers processing queues, API polling processes, or real-time synchronizations, these tasks that run every minute or every five minutes require monitoring adapted to their intense rhythm.

The main difficulty lies in balancing responsiveness and alert relevance. A cron that runs 1,440 times per day cannot trigger an alert on every micro-failure without creating unbearable noise. Conversely, waiting too long to alert on a recurring problem can have significant business consequences.

MoniTao provides the necessary tools to effectively monitor your high frequency crons: short and precise timeouts, configurable grace periods, and execution duration metrics to anticipate overlap problems before they occur.

Common use cases

High frequency crons are used in many business contexts where responsiveness is critical.

  • Queue workers: processing pending jobs (emails, push notifications, report generation). Every minute counts for user experience.
  • API polling: retrieving data from external services that don't offer webhooks. Stocks, weather, exchange rates.
  • Near real-time sync: cache updates, replication between systems, dashboard refreshes.
  • Webhook processing: consuming received webhook queues, with validation and routing to appropriate systems.

High frequency cron specific challenges

High execution frequency introduces issues that classic crons don't face.

  • Execution volume: 1,440 executions per day for an every-minute cron. The slightest anomaly multiplies rapidly.
  • Overlap risk: if execution N takes more than a minute, execution N+1 starts before N finishes. This can create duplicates or data corruption.
  • Resource consumption: CPU, memory, database connections. A poorly optimized high frequency cron can saturate the server.
  • Voluminous logs: without proper rotation, logs can fill the disk in a few days.

Adapted monitoring strategies

High frequency cron monitoring requires specific parameters to avoid false positives while ensuring rapid detection of real problems.

  • Short and precise timeout: configure a timeout of 2 to 3 times the execution frequency. For an every-minute cron, a 2-3 minute timeout allows tolerating an isolated failure.
  • Grace period: avoid alert spam by configuring a grace period. The alert only triggers if the problem persists beyond this delay.
  • Duration monitoring: monitor execution duration evolution. A progressive increase indicates an upcoming overlap problem.
  • Trend metrics: analyze patterns over several days to identify degradations before they become critical.

Overlap prevention

Overlapping is the main risk of high frequency crons. Here are techniques to avoid it.

  • File lock (flock): on Linux, use flock -n so a new execution is abandoned if the previous one is still running.
  • Application frameworks: Laravel offers withoutOverlapping(), Symfony has the Lock component. Use these native mechanisms.
  • Database flag: store an execution start timestamp and check it before each new launch.

Example with anti-overlap protection

Here's a Bash cron example with flock to prevent overlapping and MoniTao integration:

#!/bin/bash
# /etc/cron.d/queue-worker
* * * * * www-data flock -n /tmp/queue-worker.lock /path/to/queue-worker.sh

# queue-worker.sh
#!/bin/bash
set -e

# Process queue items
php /var/www/artisan queue:work --stop-when-empty

# Signal success to MoniTao
curl -fsS --max-time 10 "https://api.monitao.com/ping/YOUR_TOKEN"

The -n flag of flock silently fails if the lock is already taken. The script processes the queue then signals success to MoniTao. If the script doesn't complete within 2-3 minutes, MoniTao will alert.

Implementation guide

Follow these steps to set up effective monitoring for your high frequency crons.

  1. Evaluate actual frequency
    First, validate that high frequency is really necessary. Often, 5 or 15 minutes is enough and greatly simplifies monitoring.
  2. Implement anti-overlap protection
    Add flock, withoutOverlapping(), or a lock mechanism before even setting up monitoring.
  3. Create MoniTao heartbeat
    Configure a timeout of 2-3x the frequency. For an every-minute cron, use a 2-3 minute timeout.
  4. Configure alerts
    Set an appropriate grace period and choose alert channels that won't be overwhelmed.

Alert configuration

Alerts for high frequency crons must be balanced between responsiveness and relevance.

  • Complete stop: no ping received for 2-3x normal frequency. Critical problem requiring immediate intervention.
  • Repeated failures: multiple consecutive failures detected. The system is unstable and requires investigation.
  • Duration degradation: execution duration increases significantly. Warning sign of an upcoming overlap problem.
  • Exhausted resources: combined with system monitoring, detect when the cron consumes too much CPU, memory, or connections.

High frequency cron checklist

  • Frequency genuinely justified by business need
  • Anti-overlap protection implemented and tested
  • MoniTao timeout = 2-3x execution frequency
  • Log rotation configured
  • Server resources sufficient and monitored
  • Fallback plan if cron fails (alternative queue, failover)

Frequently asked questions

My every-minute cron sometimes runs twice simultaneously. Why?

The previous execution wasn't finished when the new one started (overlapping). Add a lock mechanism like flock on Linux or withoutOverlapping() in Laravel to avoid this problem.

What timeout should I configure for a cron that runs every minute?

Configure a timeout of 2 to 3 minutes. This allows tolerating an isolated failure without triggering an alert, while quickly detecting a prolonged stop.

With 1,440 executions per day, does MoniTao cost more?

No, MoniTao charges per heartbeat (monitored job), not per number of pings. Whether your cron runs 10 times or 10,000 times per day, the cost remains the same.

How do I know if I really need to run every minute?

Ask yourself: what happens if the data is 5 minutes late instead of 1 minute? If the answer is "nothing serious", reduce the frequency.

My high frequency cron consumes a lot of CPU. What should I do?

Optimize the cron code (SQL queries, algorithms). Reduce frequency if possible. Use a dedicated server for heavy tasks. Implement a batch mechanism to process multiple items in a single execution.

How do I avoid alert spam if my cron fails frequently?

Configure an appropriate grace period in MoniTao. The alert only triggers if the problem persists beyond this delay, reducing noise while alerting you to real problems.

Conclusion

High frequency crons are essential for many modern applications, but they require an adapted monitoring approach. The key is finding the balance between alert responsiveness and tolerance for isolated failures.

With MoniTao, you can effectively monitor your high frequency crons thanks to precise timeouts, configurable grace periods, and execution duration metrics. Start by protecting your crons against overlapping, then add monitoring for complete coverage.

Ready to Sleep Soundly?

Start free, no credit card required.