dispersion index in statistics
authorJiří Filipovič <fila@ics.muni.cz>
Wed, 7 Jul 2010 13:52:03 +0000 (13:52 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Wed, 7 Jul 2010 13:52:03 +0000 (13:52 +0000)
12 files changed:
org.glite.lb.client/examples/stats-duration-fromto.c
org.glite.lb.client/interface/statistics.h
org.glite.lb.client/src/statistics.c
org.glite.lb.common/interface/xml_conversions.h
org.glite.lb.common/interface/xml_parse.h
org.glite.lb.common/src/xml_conversions.c
org.glite.lb.common/src/xml_parse.c.T
org.glite.lb.server/src/lb_proto.c
org.glite.lb.server/src/lb_xml_parse.c.T
org.glite.lb.server/src/lb_xml_parse.h
org.glite.lb.server/src/stats.c
org.glite.lb.server/src/stats.h

index e4b5ad9..79d7385 100644 (file)
@@ -34,7 +34,7 @@ int main(int argc,char **argv)
        time_t  now,from,to;
        char    *cfrom,*cto;
        int     from_res,to_res;
-       float   val;
+       float   duration, dispersion;
 
 
        edg_wll_InitContext(&ctx);
@@ -55,8 +55,7 @@ int main(int argc,char **argv)
         to = now;
         from = now - 600;
 
-       if (edg_wll_StateDurationFromTo(ctx,group,atoi(argv[2]),atoi(argv[3]),argc >=5 ? atoi(argv[4]) : 0,
-                               &from,&to,&val,&from_res,&to_res))
+       if (edg_wll_StateDurationFromTo(ctx,group,atoi(argv[2]),atoi(argv[3]),argc >=5 ? atoi(argv[4]) : 0, &from,&to,&duration,&dispersion,&from_res,&to_res))
        {
                char    *et,*ed;
                edg_wll_Error(ctx,&et,&ed);
@@ -70,9 +69,10 @@ int main(int argc,char **argv)
        cto[strlen(cto)-1] = 0;
 
        printf("Average duration at \"%s\": %f s\n"
+              "Dispersion index: %f\n"
               "  Measuered from %s to %s\n"
               "  With resolution from %d to %d s\n",
-              argv[1],val,cfrom,cto,from_res,to_res);
+              argv[1],duration,dispersion,cfrom,cto,from_res,to_res);
 
        return 0;
 }
index 8757fe9..7e8a656 100644 (file)
@@ -77,6 +77,7 @@ int edg_wll_StateDurationFromTo(
         time_t  *from,
         time_t  *to,
         float   *duration,
+       float   *dispersion,
         int     *res_from,
         int     *res_to
 );
index fed5af4..cd2ece4 100644 (file)
@@ -81,7 +81,7 @@ int edg_wll_StateRate(
                goto err;
 
        edg_wll_ParseStatsResult(ctx,message, from, to, rate, 
-                       &not_returned, res_from, res_to);
+                       &not_returned, &not_returned, res_from, res_to);
 
 err:
        free(response);
@@ -127,7 +127,7 @@ int edg_wll_StateDuration(
                goto err;
 
        edg_wll_ParseStatsResult(ctx,message, from, to, &not_returned, 
-                       duration, res_from, res_to);
+                       duration, &not_returned, res_from, res_to);
 
 err:
        free(response);
@@ -150,6 +150,7 @@ int edg_wll_StateDurationFromTo(
         time_t  *from,
         time_t  *to,
         float   *duration,
+       float   *dispersion,
         int     *res_from,
         int     *res_to
 )
@@ -175,7 +176,7 @@ int edg_wll_StateDurationFromTo(
                 goto err;
 
         edg_wll_ParseStatsResult(ctx,message, from, to, &not_returned,
-                        duration, res_from, res_to);
+                        duration, dispersion, res_from, res_to);
 
 err:
         free(response);
index d685184..6cb9038 100644 (file)
@@ -97,7 +97,7 @@ typedef struct _edg_wll_XML_ctx {
        edg_wll_JobStatCode     statsFinalState;
        int                     statsMinor;
        time_t                  statsFrom, statsTo;
-       float                   statsRate, statsDuration;
+       float                   statsRate, statsDuration, statsDispersion;
        int                     statsResFrom, statsResTo;
        glite_jobid_t           jobId;
        char                    *source;
index 43ea63f..b53c510 100644 (file)
@@ -93,7 +93,7 @@ extern int edg_wll_StatsRequestToXML(edg_wll_Context,const char *,const edg_wll_
 
 extern int edg_wll_StatsDurationFTRequestToXML(edg_wll_Context,const char *,const edg_wll_QueryRec *,edg_wll_JobStatCode,edg_wll_JobStatCode,int,time_t *,time_t *,char **);
        
-extern edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBody, time_t *from, time_t *to, float *rate, float *duration, int *res_from, int *res_to);
+extern edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBody, time_t *from, time_t *to, float *rate, float *duration, float *dispersion, int *res_from, int *res_to);
 
 #ifdef __cplusplus
 }
index 795b73c..00f5a78 100644 (file)
@@ -91,6 +91,7 @@ void edg_wll_initXMLCtx(edg_wll_XML_ctx *c) {
        c->statsMinor = 0;
        c->statsRate = 0;
        c->statsDuration = 0;
+       c->statsDispersion = 0;
        c->statsFrom = 0;
        c->statsTo = 0;
        c->statsResFrom = 0;
index c17d35e..3a3a6f9 100644 (file)
@@ -727,8 +727,9 @@ static void startStatsResult(void *data, const char *el, const char **attr)
                         }       
                         break;          
                 case 1: if (strcasecmp(el,"from") && strcasecmp(el,"to") &&
-                               strcasecmp(el,"rate") && strcasecmp(el,"duration") &&
-                               strcasecmp(el,"res_from") && strcasecmp(el,"res_to")) 
+                               strcasecmp(el,"rate") && strcasecmp(el,"duration") && 
+                               strcasecmp(el,"dispersion") && strcasecmp(el,"res_from") &&
+                               strcasecmp(el,"res_to")) 
                                        unexpWarning()
                         break;  
                 default: unexpWarning()
@@ -1321,6 +1322,8 @@ static void endStatsResult(void *data, const char *el UNUSED_VAR)
                         XMLCtx->statsRate = edg_wll_from_string_to_float(XMLCtx);
                 else if (!strcmp(XMLCtx->element,"duration"))
                         XMLCtx->statsDuration = edg_wll_from_string_to_float(XMLCtx);
+               else if (!strcmp(XMLCtx->element,"dispersion"))
+                        XMLCtx->statsDispersion = edg_wll_from_string_to_float(XMLCtx);
                 else if (!strcmp(XMLCtx->element,"res_from"))
                         XMLCtx->statsResFrom = edg_wll_from_string_to_int(XMLCtx);
                 else if (!strcmp(XMLCtx->element,"res_to"))
@@ -2382,7 +2385,7 @@ edg_wll_ErrorCode edg_wll_ParseQuerySequenceCodeResult(edg_wll_Context ctx, char
 
 
 /* parse statistics result from client */
-edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBody, time_t *from, time_t *to, float *rate, float *duration, int *res_from, int *res_to)
+edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBody, time_t *from, time_t *to, float *rate, float *duration, float *dispersion, int *res_from, int *res_to)
 {
        edg_wll_XML_ctx XMLCtx;
        edg_wll_ErrorCode errorCode;
@@ -2421,6 +2424,7 @@ edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBod
                *to = -1;
                *rate = 0;
                *duration = 0;
+               *dispersion = 0;
                *res_from = -1;
                *res_to = -1;
        } else {
@@ -2428,6 +2432,7 @@ edg_wll_ErrorCode edg_wll_ParseStatsResult(edg_wll_Context ctx, char *messageBod
                *to = XMLCtx.statsTo;
                *rate = XMLCtx.statsRate;
                *duration = XMLCtx.statsDuration;
+               *dispersion = XMLCtx.statsDispersion;
                *res_from = XMLCtx.statsResFrom;
                *res_to = XMLCtx.statsResTo;
        }
index 9e9ce6a..1cc473d 100644 (file)
@@ -1196,7 +1196,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                        edg_wll_JobStatCode final = EDG_WLL_JOB_UNDEF;
                        time_t from, to;
                        int i, j, minor, res_from, res_to;
-                       float rate = 0, duration = 0;
+                       float rate = 0, duration = 0, dispersion = 0;
                        
                        if (parseStatsRequest(ctx, messageBody, &function, &conditions, 
                                                &base, &final, &minor, &from, &to))
@@ -1218,7 +1218,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                        err = edg_wll_StateDurationFromToServer(
                                                ctx, conditions[0], base, final,
                                                 minor, &from, &to, &duration,
-                                                &res_from, &res_to);
+                                                &dispersion, &res_from, &res_to);
                                
                                switch (err) {
                                        case 0: if (html) ret = HTTP_NOTIMPL;
@@ -1235,8 +1235,9 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                }
                                /* glue errors (if eny) to XML responce */ 
                                if (!html && !fatal)
-                                       if (edg_wll_StatsResultToXML(ctx, from, to, rate, 
-                                                       duration, res_from, res_to, &message))
+                                       if (edg_wll_StatsResultToXML(ctx, from,
+                                               to, rate, duration, dispersion,
+                                               res_from, res_to, &message))
                                                ret = HTTP_INTERNAL;
                        }
                        
index c61c137..ffb4c7b 100644 (file)
@@ -2075,6 +2075,7 @@ int edg_wll_StatsResultToXML(
                time_t to,
                float rate,
                float duration,
+               float dispersion,
                int res_from,
                int res_to,
                 char **message)
@@ -2087,6 +2088,7 @@ int edg_wll_StatsResultToXML(
        edg_wll_add_time_t_to_XMLBody(&pomA, to, "to", -1);
        edg_wll_add_float_to_XMLBody(&pomA, rate, "rate", 0);
        edg_wll_add_float_to_XMLBody(&pomA, duration, "duration", 0);
+       edg_wll_add_float_to_XMLBody(&pomA, dispersion, "dispersion", 0);
        edg_wll_add_int_to_XMLBody(&pomA, res_from, "res_from", -1);
        edg_wll_add_int_to_XMLBody(&pomA, res_to, "res_to", -1);
 
index 93bfdad..3698ae1 100644 (file)
@@ -50,7 +50,7 @@ int edg_wll_IndexedAttrsToXML(edg_wll_Context ctx, char **message);
 int edg_wll_NotifResultToXML(edg_wll_Context ctx, time_t validity, char **message);
 int edg_wll_QuerySequenceCodeResultToXML(edg_wll_Context ctx, char *source, char **message);
 
-int edg_wll_StatsResultToXML(edg_wll_Context,time_t,time_t,float,float,int,int,char **);
+int edg_wll_StatsResultToXML(edg_wll_Context,time_t,time_t,float,float,float,int,int,char **);
 
 int parseStatsRequest(edg_wll_Context,char *,char **,edg_wll_QueryRec ***,edg_wll_JobStatCode *,edg_wll_JobStatCode *,int *,time_t *,time_t *);
 
index a092f01..3480391 100644 (file)
@@ -25,6 +25,7 @@ limitations under the License.
 #include <stdio.h>
 #include <errno.h>
 #include <time.h>
+#include <math.h>
 
 #include "glite/lb/events.h"
 #include "glite/lb/jobstat.h"
@@ -366,6 +367,7 @@ static int stats_record_duration_fromto(
                        /* now we can do IT */
                        a->cells[a->ptr].cnt++;
                        a->cells[a->ptr].value += (float)timedif;
+                       a->cells[a->ptr].value2 += (float)timedif * (float)timedif;
                        glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG,
                                "update archive %d, cell %d incremented to %f",
                                i, a->ptr, a->cells[a->ptr].value);
@@ -460,7 +462,7 @@ int edg_wll_StateRateServer(
 
        edg_wll_ResetError(ctx);
 
-       if (err = findStat(ctx, group, major, EDG_WLL_JOB_UNDEF, minor, from, to, &stats)) return err;
+       if ((err = findStat(ctx, group, major, EDG_WLL_JOB_UNDEF, minor, from, to, &stats))) return err;
 
        /* remap the file if someone changed its size */
        if (stats->map->grpno != stats->grpno)
@@ -614,11 +616,12 @@ int edg_wll_StateDurationFromToServer(
         time_t  *from,
         time_t  *to,
         float   *duration,
+       float   *dispersion,
         int     *res_from,
         int     *res_to
 )
 {
-        edg_wll_Stats *stats = default_stats;   /* XXX: hardcoded */
+       edg_wll_Stats *stats = default_stats;   /* XXX: hardcoded */
         struct edg_wll_stats_group      *g;
         struct edg_wll_stats_archive    *a;
         int     i,j,matchi;
@@ -630,7 +633,7 @@ int edg_wll_StateDurationFromToServer(
 
         edg_wll_ResetError(ctx);
 
-       if (err = findStat(ctx, group, base_state, final_state, minor, from, to, &stats)) return err;
+       if ((err = findStat(ctx, group, base_state, final_state, minor, from, to, &stats))) return err;
 
        /* remap the file if someone changed its size */
         if (stats->map->grpno != stats->grpno)
@@ -712,6 +715,7 @@ int edg_wll_StateDurationFromToServer(
 
         rate = 0.0f;
        *duration = 0.0f;
+       *dispersion = 0.0f;
         match = 0;
 
        for (j=0; j<stats->archives[matchi].length; j++,afrom += i) {
@@ -750,19 +754,20 @@ int edg_wll_StateDurationFromToServer(
                }
                printf("diff: %ld\n", diff);
                match += diff;
-               rate += c->cnt * (float)diff/i;
+               rate += c->cnt * (float)diff;
                if (c->cnt)
                        *duration += (float)diff * c->value/c->cnt;
+               *dispersion += (float)diff * c->value2;
 
                if (*to >= afrom && *to < afrom+i) { 
-                       glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "matched to: match %d, rate %f, duration %f", match, rate, *duration);
+                       glite_common_log(LOG_CATEGORY_LB_SERVER, LOG_PRIORITY_DEBUG, "matched to: match %d, duration %f, dispersion %f", match, *duration, *disperson);
                        break;
                }
         }
-       printf("XXX %f %f %ld\n", rate, *duration, match);
-        rate /= match;
        *duration /= match;
-       printf("YYY %f %f %ld\n", rate, *duration, match);
+       *dispersion /= match;
+       rate /= match;
+       *dispersion = sqrtf(1/(rate-1) * ((*dispersion) - rate*(*duration)));
 
 cleanup:
        free(sig);
index b242bf9..7468e15 100644 (file)
@@ -37,6 +37,7 @@ int edg_wll_UpdateStatistics(
 struct edg_wll_stats_cell {
        int     cnt;
        float   value;
+       float   value2;
 };
 
 struct edg_wll_stats_archive {
@@ -101,6 +102,7 @@ int edg_wll_StateDurationFromToServer(
         time_t  *from,
         time_t  *to,
         float   *duration,
+       float   *dispersion,
         int     *res_from,
         int     *res_to
 );