4

I need to synchronize two systems, so the producers list new entities to be created on the consumer app. It has no realtime need (mostly for datamining, so being a few hours behind isn't an issue), but it's important that this task doesn't run when the server is already busy serving real users.

I have tried to run the sync service with a lower priority (nice -n19) but for what I saw, it can still hurt performances, as if this sync service runs a big database query, it's still going to increase the load on the database process and on the complete machine

is there a way to test the load and simply exit if it's too high (say above 2)?

Ideally, having some kind of alert if the cron isn't processing for too long because the load never goes below 2.

Is this a good approach or am I creating more problems that I'm solving?

Xavier
  • 141
  • 4

1 Answers1

5

Simply wrap you script inside a testing condition. For example:

#!/bin/bash
load=`grep -o "^[0-9]*" /proc/loadavg`
if [ $load -gt 2 ]; then
    exit 1
fi
### Call you script here ###

The above script will check the 1-minute load average and, if greater than 2, it will exit. On the other side, if the load average is less or equal to 2, it will continue.

More complex tests can be written, but the concept is the same: use a wrapper script/function and then call your custom sync script.

shodanshok
  • 44,038
  • 6
  • 98
  • 162