rrs-commit: r42 - trunk

decibel at decibel.org decibel at decibel.org
Sun Mar 13 23:31:51 GMT 2005


Author: decibel
Date: Sun Mar 13 23:31:50 2005
New Revision: 42

Modified:
   trunk/rrs.sql
   trunk/rrs_functions.sql
Log:
Limit slew rate for data interval changes

Modified: trunk/rrs.sql
==============================================================================
--- trunk/rrs.sql	(original)
+++ trunk/rrs.sql	Sun Mar 13 23:31:50 2005
@@ -89,20 +89,25 @@
 \.
 */
 
-CREATE OR REPLACE VIEW history_data_interval_duration_v AS '
-SELECT h.*
-        , CASE WHEN duration > '0 seconds'::interval
-            THEN rrs.seconds_to_interval(
-                    rrs.interval_to_seconds(data_interval)
-                    * rrs.interval_to_seconds( desired_run_time )
-                    / rrs.interval_to_seconds( duration )
-                )
-            END AS next_duration
-    FROM
-        ( SELECT rrs.setting_get('minimum data interval')::interval AS desired_run_time ) AS s
-        , ( SELECT start_time, end_time, end_time-start_time AS duration, data_interval
-                FROM history_data_interval ) h
-';
+CREATE OR REPLACE VIEW rrs.history_data_interval_run_time_v AS
+    SELECT h.*
+            , CASE WHEN run_time_sec > 0
+                THEN rrs.seconds_to_interval(
+                        rrs.interval_to_seconds(data_interval)
+                        * desired_run_time_sec
+                        / run_time_sec
+                    )
+                END AS next_data_interval
+        FROM
+            ( SELECT rrs.interval_to_seconds(
+                                rrs.setting_get('desired run time')::interval
+                        ) AS desired_run_time_sec
+            ) AS s
+            , ( SELECT start_time, end_time, data_interval
+                        , end_time - start_time AS run_time
+                        , rrs.interval_to_seconds( end_time - start_time ) AS run_time_sec
+                    FROM history_data_interval ) h
+;
 
 GRANT SELECT ON rrs TO PUBLIC;
 GRANT SELECT ON source TO PUBLIC;

Modified: trunk/rrs_functions.sql
==============================================================================
--- trunk/rrs_functions.sql	(original)
+++ trunk/rrs_functions.sql	Sun Mar 13 23:31:50 2005
@@ -393,9 +393,11 @@
 
     r record;
     v_desired_run_time interval;
+    v_last_start_time rrs.history.start_time%TYPE;
     v_min_interval interval;
     v_max_interval interval;
-    v_data_interval rrs.history_data_interval.data_interval%TYPE;
+    v_next_data_interval rrs.history_data_interval.data_interval%TYPE;
+    v_last_data_interval_secs double precision;
     v_last_end_time rrs.bucket.end_time%TYPE;
 BEGIN
     v_desired_run_time := rrs.setting_get(''desired run time'');
@@ -420,7 +422,7 @@
     IF v_max_interval IS NULL THEN
         v_max_interval = rrs.setting_set(
                                             ''maximum data interval''
-                                            , ( v_min_interval * 1000 )::text
+                                            , ( v_min_interval * 100 )::text
                                         )
         ;
         v_max_interval = rrs.setting_get(''maximum data interval'');
@@ -438,35 +440,45 @@
         data_interval that was used in that run. Take the average of those and use it for our value.
     */
     
-    SELECT INTO v_data_interval
-            avg( next_duration )
-        FROM history_data_interval_duration_v
-        WHERE duration > ''1 second''::interval
+    SELECT INTO v_next_data_interval, v_last_start_time
+            avg(next_data_interval), max(start_time)
+        FROM history_data_interval_run_time_v
+        WHERE next_data_interval IS NOT NULL
+    ;
+    SELECT INTO v_last_data_interval_secs
+            interval_to_seconds(data_interval)
+        FROM history_data_interval
+        WHERE start_time = v_last_start_time
     ;
 
-    IF v_data_interval IS NULL THEN
+    IF v_next_data_interval IS NULL THEN
         RAISE INFO ''calculate_end_time: no data available, using minimum interval (%)'', v_min_interval;
-        v_data_interval := v_min_interval;
-    END IF;
-    IF v_data_interval < v_min_interval THEN
-        RAISE INFO ''v_data_interval % too low, forcing to minimum interval (%)'', v_data_interval, v_min_interval;
-        v_data_interval := v_min_interval;
-    END IF;
-    IF v_data_interval > v_max_interval THEN
-        RAISE INFO ''v_data_interval % too high, forcing to maximum interval (%)'', v_data_interval, v_max_interval;
-        v_data_interval := v_max_interval;
+        v_next_data_interval := v_min_interval;
+    ELSE
+        IF interval_to_seconds(v_next_data_interval) > v_last_data_interval_secs * 3 THEN
+            RAISE INFO ''calculate_end_time: maximum data interval slew exceeded, capping to 3x last setting'';
+            v_next_data_interval := seconds_to_interval( v_last_data_interval_secs * 3 );
+        END IF;
+    END IF;
+    IF v_next_data_interval < v_min_interval THEN
+        RAISE INFO ''v_next_data_interval % too low, forcing to minimum interval (%)'', v_next_data_interval, v_min_interval;
+        v_next_data_interval := v_min_interval;
+    END IF;
+    IF v_next_data_interval > v_max_interval THEN
+        RAISE INFO ''v_next_data_interval % too high, forcing to maximum interval (%)'', v_next_data_interval, v_max_interval;
+        v_next_data_interval := v_max_interval;
     END IF;
 
     -- Now we have an upper limit on how many buckets to process, but we don''t want to go beyond rrs.tod()
-    v_last_end_time := min( rrs.tod(), p_first_end_time + v_data_interval );
-    v_data_interval := v_last_end_time - p_first_end_time;
+    v_last_end_time := min( rrs.tod(), p_first_end_time + v_next_data_interval );
+    v_next_data_interval := v_last_end_time - p_first_end_time;
 
     -- Log how much time we''ll actually be processing
     INSERT INTO rrs.history_data_interval( start_time, end_time, data_interval )
-        VALUES( p_start_time, p_start_time, v_data_interval )
+        VALUES( p_start_time, p_start_time, v_next_data_interval )
     ;
 
-    RAISE INFO ''limiting bucket creation to %'', v_data_interval; 
+    RAISE INFO ''limiting bucket creation to %'', v_next_data_interval; 
     RAISE DEBUG ''calculate_end_time RETURN: v_last_end_time %'', v_last_end_time;
     RETURN v_last_end_time;
 END;


More information about the rrs-commit mailing list