summaryrefslogtreecommitdiffstats
path: root/src/zabbix_server/dbsyncer/dbsyncer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/zabbix_server/dbsyncer/dbsyncer.c')
-rw-r--r--src/zabbix_server/dbsyncer/dbsyncer.c44
1 files changed, 35 insertions, 9 deletions
diff --git a/src/zabbix_server/dbsyncer/dbsyncer.c b/src/zabbix_server/dbsyncer/dbsyncer.c
index cf28a7db..c341668b 100644
--- a/src/zabbix_server/dbsyncer/dbsyncer.c
+++ b/src/zabbix_server/dbsyncer/dbsyncer.c
@@ -22,6 +22,7 @@
#include "db.h"
#include "log.h"
#include "zlog.h"
+#include "threads.h"
#include "dbcache.h"
#include "dbsyncer.h"
@@ -43,9 +44,11 @@
******************************************************************************/
int main_dbsyncer_loop()
{
- int now;
+ int now, sleeptime, last_sleeptime = -1, num;
double sec;
+ zabbix_log(LOG_LEVEL_DEBUG, "In main_dbsyncer_loop()");
+
zbx_setproctitle("db syncer [connecting to the database]");
DBconnect(ZBX_DB_CONNECT_NORMAL);
@@ -55,18 +58,41 @@ int main_dbsyncer_loop()
now = time(NULL);
sec = zbx_time();
+ num = DCsync_history(ZBX_SYNC_PARTIAL);
+ sec = zbx_time() - sec;
+
+ if (last_sleeptime == -1)
+ {
+ sleeptime = now - time(NULL) + CONFIG_DBSYNCER_FREQUENCY;
+ }
+ else
+ {
+ sleeptime = last_sleeptime;
+ if (num >= ZBX_SYNC_MAX)
+ sleeptime--;
+ else if (num < ZBX_SYNC_MAX / 2)
+ sleeptime++;
+ }
+
+ if (sleeptime < 0)
+ sleeptime = 0;
+ else if (sleeptime > CONFIG_DBSYNCER_FREQUENCY)
+ sleeptime = CONFIG_DBSYNCER_FREQUENCY;
- DCsync();
+ last_sleeptime = sleeptime;
- zabbix_log(LOG_LEVEL_DEBUG, "Spent " ZBX_FS_DBL " sec",
- zbx_time() - sec);
+ zabbix_log(LOG_LEVEL_DEBUG, "DB syncer spent " ZBX_FS_DBL " second while processing %d items. "
+ "Nextsync after %d sec.",
+ sec,
+ num,
+ sleeptime);
- zbx_setproctitle("db syncer [sleeping for %d seconds]",
- CONFIG_DBSYNCER_FREQUENCY);
- zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
- CONFIG_DBSYNCER_FREQUENCY);
+ if (sleeptime > 0) {
+ zbx_setproctitle("db syncer [sleeping for %d seconds]",
+ sleeptime);
- sleep(CONFIG_DBSYNCER_FREQUENCY);
+ sleep(sleeptime);
+ }
}
DBclose();
}