detect database is too far behind and other minor timing improvements
Costa Tsaousis (ktsaou) committed
Apr 21, 2017 at 13:20 UTC
85d1d833ba2f352cb3aaf0a62e639bfcda8db553
4 files changed
+30
-45
src/rrdhost.c
+2
-2
@@ -309,7 +309,7 @@ RRDHOST *rrdhost_find_or_create(
309
if(host->rrd_update_every != update_every)
310
error("Host '%s' has an update frequency of %d seconds, but the wanted one is %d seconds.", host->hostname, host->rrd_update_every, update_every);
311
312
- if(host->rrd_history_entries != history)
312
+ if(host->rrd_history_entries < history)
313
error("Host '%s' has history of %ld entries, but the wanted one is %ld entries.", host->hostname, host->rrd_history_entries, history);
314
315
if(host->rrd_memory_mode != mode)
@@ -502,7 +502,7 @@ void rrdhost_free_all(void) {
502
void rrdhost_save(RRDHOST *host) {
503
if(!host) return;
504
505
- info("Saving database of host '%s'...", host->hostname);
505
+ info("Saving/Closing database of host '%s'...", host->hostname);
506
507
RRDSET *st;
508
src/rrdpush.c
+1
-1
@@ -57,7 +57,7 @@ int rrdpush_init() {
57
// to its current clock, we send for this many
58
// iterations a BEGIN line without microseconds
59
// this is for the first iterations of each chart
60
-static unsigned int remote_clock_resync_iterations = 60;
60
+unsigned int remote_clock_resync_iterations = 60;
61
62
#define rrdpush_lock(host) netdata_mutex_lock(&((host)->rrdpush_mutex))
63
#define rrdpush_unlock(host) netdata_mutex_unlock(&((host)->rrdpush_mutex))
src/rrdpush.h
+1
@@ -4,6 +4,7 @@
4
extern int default_rrdpush_enabled;
5
extern char *default_rrdpush_destination;
6
extern char *default_rrdpush_api_key;
7
+extern unsigned int remote_clock_resync_iterations;
8
9
extern int rrdpush_init();
10
extern void rrdset_done_push(RRDSET *st);
src/rrdset.c
+26
-42
@@ -188,7 +188,7 @@ void rrdset_reset(RRDSET *st) {
188
rd->last_collected_time.tv_sec = 0;
189
rd->last_collected_time.tv_usec = 0;
190
rd->collections_counter = 0;
191
- memset(rd->values, 0, rd->entries * sizeof(storage_number));
191
+ // memset(rd->values, 0, rd->entries * sizeof(storage_number));
192
}
193
}
194
@@ -586,16 +586,10 @@ RRDSET *rrdset_create(
586
// RRDSET - data collection iteration control
587
588
inline void rrdset_next_usec_unfiltered(RRDSET *st, usec_t microseconds) {
589
-
590
- if(unlikely(!st->last_collected_time.tv_sec)) {
591
- // the first entry
592
- microseconds = st->update_every * USEC_PER_SEC;
593
- }
594
- else if(unlikely(!microseconds)) {
595
- // no dt given by the plugin
596
- struct timeval now;
597
- now_realtime_timeval(&now);
598
- microseconds = dt_usec(&now, &st->last_collected_time);
589
+ if(unlikely(!st->last_collected_time.tv_sec || !microseconds || (st->counter % remote_clock_resync_iterations) == 0)) {
590
+ // call the full next_usec() function
591
+ rrdset_next_usec(st, microseconds);
592
+ return;
593
}
594
595
st->usec_since_last_update = microseconds;
@@ -615,15 +609,11 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
609
}
610
else {
611
// microseconds has the time since the last collection
618
-//#ifdef NETDATA_INTERNAL_CHECKS
619
-// usec_t now_usec = timeval_usec(&now);
620
-// usec_t last_usec = timeval_usec(&st->last_collected_time);
621
-//#endif
612
susec_t since_last_usec = dt_usec_signed(&now, &st->last_collected_time);
613
614
if(unlikely(since_last_usec < 0)) {
615
// oops! the database is in the future
626
- error("Database for chart '%s' on host '%s' is %lld microseconds in the future. Adjusting it to current time.", st->id, st->rrdhost->hostname, -since_last_usec);
616
+ info("RRD database for chart '%s' on host '%s' is %0.5Lf secs in the future. Adjusting it to current time.", st->id, st->rrdhost->hostname, (long double)-since_last_usec / USEC_PER_SEC);
617
618
st->last_collected_time.tv_sec = now.tv_sec - st->update_every;
619
st->last_collected_time.tv_usec = now.tv_usec;
@@ -634,26 +624,11 @@ inline void rrdset_next_usec(RRDSET *st, usec_t microseconds) {
624
last_updated_time_align(&st->last_updated, st->update_every);
625
626
microseconds = st->update_every * USEC_PER_SEC;
637
- since_last_usec = st->update_every * USEC_PER_SEC;
638
- }
639
-
640
- // verify the microseconds given is good
641
- if(unlikely(microseconds > (usec_t)since_last_usec)) {
642
- debug(D_RRD_CALLS, "dt %llu usec given is too big - it leads %llu usec to the future, for chart '%s' (%s).", microseconds, microseconds - (usec_t)since_last_usec, st->name, st->id);
643
-
644
-//#ifdef NETDATA_INTERNAL_CHECKS
645
-// if(unlikely(last_usec + microseconds > now_usec + 1000))
646
-// error("dt %llu usec given is too big - it leads %llu usec to the future, for chart '%s' (%s).", microseconds, microseconds - (usec_t)since_last_usec, st->name, st->id);
647
-//#endif
648
-
649
- microseconds = (usec_t)since_last_usec;
627
}
651
- else if(unlikely(microseconds < (usec_t)since_last_usec * 0.8)) {
652
- debug(D_RRD_CALLS, "dt %llu usec given is too small - expected %llu usec up to -20%%, for chart '%s' (%s).", microseconds, (usec_t)since_last_usec, st->name, st->id);
628
+ else if(unlikely((usec_t)since_last_usec > (usec_t)(st->update_every * 10 * USEC_PER_SEC))) {
629
+ // oops! the database is too far behind
630
+ info("RRD database for chart '%s' on host '%s' is %0.5Lf secs in the past. Adjusting it to current time.", st->id, st->rrdhost->hostname, (long double)since_last_usec / USEC_PER_SEC);
631
654
-//#ifdef NETDATA_INTERNAL_CHECKS
655
-// error("dt %llu usec given is too small - expected %llu usec up to -20%%, for chart '%s' (%s).", microseconds, (usec_t)since_last_usec, st->name, st->id);
656
-//#endif
632
microseconds = (usec_t)since_last_usec;
633
}
634
}
@@ -690,6 +665,14 @@ static inline void rrdset_init_last_updated_time(RRDSET *st) {
665
}
666
667
static inline void rrdset_done_push_exclusive(RRDSET *st) {
668
+// usec_t update_every_ut = st->update_every * USEC_PER_SEC; // st->update_every in microseconds
669
+//
670
+// if(unlikely(st->usec_since_last_update > update_every_ut * remote_clock_resync_iterations)) {
671
+// error("Chart '%s' was last collected %llu usec before. Resetting it.", st->id, st->usec_since_last_update);
672
+// rrdset_reset(st);
673
+// st->usec_since_last_update = update_every_ut;
674
+// }
675
+
676
if(unlikely(!st->last_collected_time.tv_sec)) {
677
// it is the first entry
678
// set the last_collected_time to now
@@ -758,9 +741,10 @@ void rrdset_done(RRDSET *st) {
741
742
// check if the chart has a long time to be updated
743
if(unlikely(st->usec_since_last_update > st->entries * update_every_ut)) {
761
- info("%s: took too long to be updated (%0.3Lf secs). Resetting it.", st->name, (long double)(st->usec_since_last_update / 1000000.0));
744
+ info("host '%s', chart %s: took too long to be updated (%0.3Lf secs). Resetting it.", st->rrdhost->hostname, st->name, (long double)(st->usec_since_last_update / 1000000.0));
745
rrdset_reset(st);
746
st->usec_since_last_update = update_every_ut;
747
+ store_this_entry = 0;
748
first_entry = 1;
749
}
750
@@ -1036,11 +1020,11 @@ void rrdset_done(RRDSET *st) {
1020
// this is collected in the same interpolation point
1021
1022
if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG)))
1039
- debug(D_RRD_STATS, "%s: THIS IS IN THE SAME INTERPOLATION POINT", st->name);
1023
+ debug(D_RRD_STATS, "host '%s', chart '%s': THIS IS IN THE SAME INTERPOLATION POINT", st->rrdhost->hostname, st->name);
1024
1041
-//#ifdef NETDATA_INTERNAL_CHECKS
1042
-// info("%s is collected in the same interpolation point: short by %llu microseconds", st->name, next_store_ut - now_collect_ut);
1043
-//#endif
1025
+#ifdef NETDATA_INTERNAL_CHECKS
1026
+ info("INTERNAL CHECK: host '%s', chart '%s' is collected in the same interpolation point: short by %llu microseconds", st->rrdhost->hostname, st->name, next_store_ut - now_collect_ut);
1027
+#endif
1028
}
1029
1030
usec_t first_ut = last_stored_ut;
@@ -1048,9 +1032,9 @@ void rrdset_done(RRDSET *st) {
1032
if((now_collect_ut % (update_every_ut)) == 0) iterations++;
1033
1034
for( ; next_store_ut <= now_collect_ut ; last_collect_ut = next_store_ut, next_store_ut += update_every_ut, iterations-- ) {
1051
-//#ifdef NETDATA_INTERNAL_CHECKS
1052
-// if(iterations < 0) { error("%s: iterations calculation wrapped! first_ut = %llu, last_stored_ut = %llu, next_store_ut = %llu, now_collect_ut = %llu", st->name, first_ut, last_stored_ut, next_store_ut, now_collect_ut); }
1053
-//#endif
1035
+#ifdef NETDATA_INTERNAL_CHECKS
1036
+ if(iterations < 0) { error("INTERNAL CHECK: %s: iterations calculation wrapped! first_ut = %llu, last_stored_ut = %llu, next_store_ut = %llu, now_collect_ut = %llu", st->name, first_ut, last_stored_ut, next_store_ut, now_collect_ut); }
1037
+#endif
1038
1039
if(unlikely(rrdset_flag_check(st, RRDSET_FLAG_DEBUG))) {
1040
debug(D_RRD_STATS, "%s: last_stored_ut = %0.3Lf (last updated time)", st->name, (long double)last_stored_ut/1000000.0);