rrs-commit: r32 - trunk

decibel at decibel.org decibel at decibel.org
Sun Mar 6 22:09:51 GMT 2005


Author: decibel
Date: Sun Mar  6 22:09:51 2005
New Revision: 32

Modified:
   trunk/rrs_functions.sql
Log:
Ditch linear estimation for a simpler scheme. Don't worry about trying to delete from history_data_interval if history_data_interval length >= history length.

Modified: trunk/rrs_functions.sql
==============================================================================
--- trunk/rrs_functions.sql	(original)
+++ trunk/rrs_functions.sql	Sun Mar  6 22:09:51 2005
@@ -400,7 +400,7 @@
 BEGIN
     v_desired_run_time := rrs.setting_get(''desired run time'');
     IF v_desired_run_time IS NULL THEN
-        v_desired_run_time := rrs.setting_set( ''desired run time'', ''1 minute'' );
+        v_desired_run_time := rrs.setting_set( ''desired run time'', ''50 seconds'' );
         v_desired_run_time := rrs.setting_get(''desired run time'');
         RAISE WARNING ''calculate_end_time: WARNING desired run time not set, setting to %'', v_desired_run_time;
     END IF;
@@ -434,43 +434,23 @@
     RAISE DEBUG ''calculate_end_time BEGIN: p_first_end_time %, p_start_time %, desired run time %, minimum data interval %, maximum data interval %'', p_first_end_time, p_start_time, v_desired_run_time, v_min_interval;
 
     /*
-    To calculate the end time we build a linear estimation (http://mathworld.wolfram.com/LeastSquaresFitting.html).
-    This gives as a straight line of the formula y = ax + b. The formulas for a and b are
-
-    a = ( sum(y) * sum(x^2) - sum(x) * sum(xy) ) / ( count(*) * sum(x^2) - count(*) * sum(x)^2 )
-    b = ( sum(xy) - n * sum(x) * sum(y) ) / ( sum(x^2) - n * sum(x)^2 )
-
-    If x is runtime and y is data interval, our desired data_interval would be y = ax + b
-
+        For each row in history, calculate the ratio of desired runtime to actual, and apply that to the
+        data_interval that was used in that run. Take the average of those and use it for our value.
     */
     
-    SELECT INTO r
-            CASE WHEN ( count(*) * sum(x*x) - count(*) * sum(x)^2 ) = 0
-                    THEN 1
-                    ELSE ( sum(y) * sum(x*X) - sum(x) * sum(x*y) ) / ( count(*) * sum(x*x) - count(*) * sum(x)^2 )
-                    END
-                AS a
-            , CASE WHEN ( sum(x*x) - count(*) * sum(x) * sum(x) ) = 0
-                THEN 1
-                ELSE ( sum( x * y ) - count(*) * sum(x) * sum(y) ) / ( sum(x*x) - count(*) * sum(x) * sum(x) )
-                END
-            AS b
-        FROM (
-                SELECT rrs.interval_to_seconds(data_interval) AS y
-                        , rrs.interval_to_seconds( end_time - start_time) AS x
-                    FROM history_data_interval
-            ) raw
+    SELECT INTO v_data_interval
+            rrs.seconds_to_interval( avg(
+                        rrs.interval_to_seconds(data_interval)
+                        * rrs.interval_to_seconds( v_desired_run_time )
+                        / rrs.interval_to_seconds( end_time - start_time )
+                    ) )
+        FROM history_data_interval
     ;
 
-    v_data_interval := coalesce( rrs.seconds_to_interval(
-                                        r.a
-                                        * rrs.interval_to_seconds( v_desired_run_time )
-                                        + r.b
-                                    )
-                                , ''0 seconds''::interval )
-    ;
-    RAISE DEBUG ''a=%, b=%, v_data_interval=%'', r.a, r.b, v_data_interval;
-
+    IF v_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;
@@ -482,12 +462,14 @@
 
     -- 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;
 
     -- 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_last_end_time - p_first_end_time )
+        VALUES( p_start_time, p_start_time, v_data_interval )
     ;
 
+    RAISE INFO ''limiting bucket creation to %'', v_data_interval; 
     RAISE DEBUG ''calculate_end_time RETURN: v_last_end_time %'', v_last_end_time;
     RETURN v_last_end_time;
 END;
@@ -609,30 +591,34 @@
         -- Trim the history table
         v_history_data_interval_length := rrs.setting_get( ''history_data_interval length'' );
         IF v_history_data_interval_length IS NULL THEN
-            v_history_data_interval_length := rrs.setting_set( ''history_data_interval length'', 100 );
+            v_history_data_interval_length := rrs.setting_set( ''history_data_interval length'', 20 );
             v_history_data_interval_length := rrs.setting_get( ''history_data_interval length'' );
             RAISE WARNING ''log_time: WARNING history_data_interval length not set, setting to %'', v_history_data_interval_length;
         END IF;
-        SELECT INTO v_min_keep_time
-                min( start_time )
-            FROM (
-                    SELECT start_time
-                        FROM (
-                                SELECT start_time
-                                    FROM rrs.history_data_interval
-                                    ORDER BY start_time DESC
-                            ) ordered
-                        LIMIT v_history_data_interval_length
-                ) limited
-        ;
-        IF FOUND THEN
-            DELETE FROM rrs.history_data_interval WHERE start_time < v_min_keep_time;
+
+        IF v_history_data_interval_length >= v_history_length THEN
+            IF v_history_data_interval_length > v_history_length THEN
+                RAISE INFO ''log_time: history_data_interval length (%) > history_length(%)'', v_history_data_interval_length, v_history_length;
+            END IF;
+        ELSE
+            SELECT INTO v_min_keep_time
+                    min( start_time )
+                FROM (
+                        SELECT start_time
+                            FROM (
+                                    SELECT start_time
+                                        FROM rrs.history_data_interval
+                                        ORDER BY start_time DESC
+                                ) ordered
+                            LIMIT v_history_data_interval_length
+                    ) limited
+            ;
+            IF FOUND THEN
+                DELETE FROM rrs.history_data_interval WHERE start_time < v_min_keep_time;
+            END IF;
         END IF;
         
-        UPDATE rrs.history_data_interval
-            SET end_time = v_end_time
-            WHERE start_time = p_start_time
-        ;
+        -- No need to update because the table is inherited
     END IF;
 
     RETURN v_end_time - p_start_time;


More information about the rrs-commit mailing list