CSIM BY EXAMPLES: Data collection, Workload generation and Simulation control
AA 2012/2013 [email protected]
(Agenda) Lezione 26/04/2012
¨ Collecting data ¨ Run length control ¨ Output
¤ transient (Welch algorithm)
¨ Traffic generation
Generazione numeri casuali e collezionamento statistiche
¨ Consideriamo il CWA Use Case: Modello C/S “diffserv”+“cluster” ¨ 5 Variabili aleatorie indipendenti
¤ Tempo di inter-arrivo richieste (itr) ¤ Priorità dei client (cp) ¤ Dimensione dei file per modellare ritardo rete (fs) ¤ Selezione del server -- supponiamo una politica Random (ss) ¤ Domanda di servizio al server (ds)
¨ Voglio collezionare le seguenti statistiche ¤ End-2-end response time ¤ Distribuzione dei tempi di servizio
Generazione numeri casuali
¨ 5 variabili iid à 5 stream diversi !
int init_seeds[5]={5, 6, 7, 9, 10} /* {itr,cp,fs,ss,ds} */!
STREAM s[5]; !
for (i=0;i<5;i++){!
!s[i] = create_stream(); !
!reseed(s[i], (long) init_seed[i]);!
}!
/* Esempio 1*/!/* !!!!!!!!!Pseudo Codice!!!!!!!!!! */!#include “csim.h”;!/* set number of servers to 3 */!#define NUM_FACS 10 /*set the number of facilities */!#define H_PRI_RATE 0.4!#define H_PRI 5! !void sim( int argc, !!char *argv[]) {!
!!FACILITY servers[NUM_FACS]; /* declare facility array */!!FACILITY loadbalancer; !!!CLASS lp;!!CLASS hp;!
!!facility_set(servers, ”servers", NUM_FACS); !!loadbalancer=facility(“loadbalancer”);!!generated_client=0;!!resetted=false;!!stop_client=false;!
!!/* CONTINUA NEXT SLIDE */!
/* simtime() mi restituisce il tempo di simulzione*/! !while( simtime() <= SIMULATION_TIME )!{!!interarrival_time = stream_exponential(s[0], 0.1 ); /* Genera il tempo di interarrivo delle richieste distribuito come un’esponenziale di media 0.1*/!!!!hold( (double)interarrival_time ); /* simula tempo interarrivo tra 2 richieste*/!!!!Web_client( generated_client ); /* genera processo client (web
! ! ! ! !request)*/!!generated_client++;!
!!if ((simtime()>TRANSIENT_TIME)&&(!resetted)) {!! !reset();!! !resetted=true;!!}!!report_facilities();!
} /* End sim process */!! !
void Web_client( long int my_number ) {! !float filesize;!!sprintf( strbuf, "Web_client%d", my_number );!!create( strbuf ); /* Creazione del processo */!
!!!if(stream_uniform(s[1],0.0,1.0)<(double)H_PRI_RATE){!! !set_priority(H_PRI);!! !set_process_class(hp);!!} else set_process_class(lp);!
!!filesize=stream_pareto(s[2],1.0)!!hold(filesize/BW+2*RTT); !/*BW ad RTT are two constants !
! !representing the bandwidth and the round-trip time*/!!use(loadbalancer, SELECTION_TIME); /* SELECTION_TIME is a constant
! ! !modeling the service time of the loadbalancer */!!i = (int)stream_uniform(s[3],0.0, (double)(NUM_FACS-1)); /*select!! ! ! ! ! ! ! ! a facility*/!!use(servers[i], stream_pareto(s[4],2.0)); /*use facility[i] for
! ! ! ! !service_time time unit*/ terminate();!
}!!
Collecting statistics
¨ End-2-end response time (e2ert) ¨ Distribuzione dei tempi di risposta lb + srv (rts)
¨ Facility report non sufficiente
¨ Devo utilizzare 2 TABLES TABLE e2ert, rts;!e2ert = table(“e2e response time”);!rts = table(“responce time statistics”);!table_histogram(rts,20,0.0,10.0); /*table, nbucket,
! ! ! ! ! !min, max*/!
!
Tables and histograms
11. Tables
lower limit
frequency
proportion cumulative proportion
0.00000 265 0.275468 0.275468 ******************** 1.00000 219 0.227651 0.503119 ***************** 2.00000 125 0.129938 0.633056 ********* 3.00000 92 0.095634 0.728690 ******* 4.00000 74 0.076923 0.805613 ****** 5.00000 54 0.056133 0.861746 **** 6.00000 53 0.055094 0.916840 **** 7.00000 38 0.039501 0.956341 *** 8.00000 8 0.008316 0.964657 * 9.00000 8 0.008316 0.972973 *
>=10.00000 26 0.027027 1.000000 **
If leading or trailing buckets contain no values, the lines in the report for these buckets will not be printed. This allows the histogram to be output as compactly as possible without losing any information.
CSIM must save information for each bucket in a histogram. Consequently, the storage requirements for a table that has a histogram are proportional to the number of buckets.
11.5 Confidence Intervals
CSIM can automatically compute confidence intervals for the mean of the data in any table. The confidence interval calculations are enabled by calling the table_confidence function.
Prototype: void table_confidence(TABLE t)
Example: table_confidence(t);
If confidence intervals have been requested, the report for a table will have an additional section, as illustrated below.
98
11. Tables
Reports can be produced for all existing tables by calling the report_tables function.
Prototype: void report_tables(void)
Example: report_tables();
The report for a table will include the table name and all statistics, as illustrated below. If the table is empty, a message to that effect is printed instead of the statistics.
TABLE 1: response times minimum 0.009880 mean 2.881970 maximum 13.702809 variance 7.002668 range 13.692929 standard deviation 2.646255 observations 962 coefficient of var 0.918211
A summary report for all tables can be generated by calling the table_summary function.
Prototype: void table_summary(void)
Example: table_summary();
The report that is produced contains one line for each table and includes only a subset of the statistics. If a table is empty, no statistics will appear in the last three columns.
TABLE SUMMARY standard name observations mean maximum deviation ------------------------------------------------------------------------------------------------------------------ response times 962 2.881970 13.702809 2.646255
96
Tables
Histograms
void Web_client( long int my_number ) {! !double filesize,e2e,rt,t;!!sprintf( strbuf, "Web_client%d", my_number );!!create( strbuf ); /* Creazione del processo */!
!!!if(stream_uniform(s[1],0.0,1.0)<(double)H_PRI_RATE){!! !set_priority(H_PRI);!! !set_process_class(hp);!!} else set_process_class(lp);!
!!e2e=simtime();!!filesize=stream_pareto(s[2],1.0);!!hold(filesize/BW+2*RTT); !/*BW ad RTT are two constants !
! !representing the bandwidth and the round-trip time*/!!rt=simetime();!!use(loadbalancer, SELECTION_TIME); /* SELECTION_TIME is a constant
! ! !modeling the service time of the loadbalancer */!!i = (int)stream_uniform(s[3],0.0, (double)(NUM_FACS-1)); /*select!! ! ! ! ! ! ! ! a facility*/!!use(servers[i], stream_pareto(s[4],2.0)); /*use facility[i] for
! ! ! ! !service_time time unit*/ t=simtime();!!tabulate(e2ert,t-e2e); !!tabulate(rts,t-rt);!!terminate();!
}!!
NOTA: non usare tabulate(e2ert, simtime()-e2e); tabulate(e2ert, simtime()-rt);
Serie temporali
¨ …E se volessimo l’intera serie temporale dei tempi di servizio (e2ert e rts)? ¤ dovete raccorgliere i tempi in una struttura dati
dedicata (vettore, lista,…)
Intervallo di confidenza e controllo della lunghezza dei run.
¨ Possibilità di calcolare l’intervallo di confidenza del valore medio osservato (per ogni oggetto per il collezionamento delle statistiche)
¤ void table_confidence(TABLE t)
¤ void qtable_confidence(QTABLE qt)
¤ void meter_confidence(METER m)
¤ void box_time_confidence(BOX b)
¤ void box_number_confidence(BOX b)
¨ La tecnica utilizzata per calcolare l’intervallo di confidenza è la: Batch means analysis. ¤ Viene calcolato l’intervallo di confidenza per 3 livelli di accuratezza: 90,
95, 98%
Intervalli di confidenza
e2ert = table(“e2e response time”);!table_confidence(e2ert);!!!!!!!!!¨ Ottenere un risultato statistico senza conoscerne l’errore e
l’intervallo di confidenza equivale ad avere un numero senza significato
11. Tables
confidence intervals for the mean after 50000 observations
level
confidence interval
rel. error 90 % 4.114119 +/- 0.296434 = [3.817684, 4.410553] 0.077648 95 % 4.114119 +/- 0.354041 = [3.760078, 4.468159] 0.078837 98 % 4.114119 +/- 0.421555 = [3.692563, 4.535674] 0.080279
Chapter 16, “Confidence Intervals and Run Length Control,” describes confidence intervals in detail and explains how to interpret the information in this report.
11.6 Moving Windows
By default, all values recorded in a table are included in the statistics. If a moving window is specified for a table, only the last n values are used in computing the statistics, where n is called the window size. A moving window is specified for a table using the table_moving_window function.
Prototype: void table_moving_window(TABLE t, long n)
Example: table_moving_window(t, 1000);
Usually, a table’s moving window is specified immediately after the table is initialized. Additional calls can be made to table_moving_window to change the table’s window size. It is an error to specify a moving window for a table that is not empty.
If a table has a window size of n, the last n values recorded in the table must be saved by CSIM. Consequently, the storage requirements for a table having a moving window are proportional to its window size.
99
Caveat
¨ Per ogni statistica che collezionate va calcolato intervallo di confidenza
¨ L’errore va riportato anche nei grafici
¨ Ad es.
Run length control
¨ E’ possibile controllare la terminazione di una simulazione basandosi sull’osservazione di una o più variabili e sulla convergenza del loro valore medio all’interno di un’intervallo di confidenza. ¤ void table_run_length(TABLE t, double accuracy, double conf_level,
double max_time)
¤ accuracy specifica il massimo errore relativo che sarà consentito al valore medio della variabile osservata (0.1, 0.01, 0.001, …)
¤ conf_level specifica l’intervallo di confidenza, eg=0.95
¤ max_time specifica il tempo massimo da simulare se la variabile osservata non converge
¨ Quando la simulazione terminerà, l’evento converged sarà impostato ad occurred ¤ wait(converged);
Controllo della terminazione di una simulazione
¨ Voglio terminare automaticamente la simulazione void table_run_length(!
!TABLE t, /* La tabella per la statistica di !! ! interesse */!
!double accuracy, /*massimo valore per l’errore rel*/!
!double conf_level, /*Int. di confidenza e.g. 0.98*/!
!double max_time /*max durata sim. in caso di non ! ! ! !convergenza*/!
!); !
Esempio
¨ Scegliamo e2ert come variabile di controllo !#define MAX_SIM_TIME 200000!TABLE e2ert, sts;!e2ert = table(“e2e response time”);!table_run_length(e2ert, !
! ! !0.01, /*two digits accuracy*/!! ! !0.99, !! ! !MAX_SIM_TIME );!
!Quando la misura di interesse converge occorre l’evento built-in converged, ossia CSIM setta lo stato dell’evento, quindi l’espressione logica state(converged)==OCC diventa vera !
/* simtime() mi restituisce il tempo di simulzione*/! !while( state(converged)==NOT_OCC ){!!interarrival_time = stream_exponential(s[0], 0.1 ); /* Genera il tempo di interarrivo delle richieste distribuito come un’esponenziale di media 0.1*/!!!!hold( (double)interarrival_time ); /* simula tempo interarrivo tra 2 richieste*/!!!!Web_client( generated_client ); /* genera processo client (web
! ! ! ! !request)*/!!generated_client++;!
!!if ((simtime()>TRANSIENT_TIME)&&(!resetted)) {!! !reset();!! !resetted=true;!!}!
}!!report_facilities();!
} /* End sim process */!! !
Tips: come rappresentare i risultati
¨ Indice di prestazione in funzione del tempo ¤ punti e/o linee interpolate
¨ Indice di prestazione in funzione di grandezza omogenea crescente (num. server, tasso di arrivo, …) ¤ punti o linee interpolate
¨ Indice di prestazione in funzione di grandezza disomogenea ¤ diagramma a barre
Indice di prestazione in funzione di grandezza omogenea crescente (num. server, tasso di arrivo, …)
0
0.5
1
1.5
2
2.5
3
3.5
4
0 10000 20000 30000 40000 50000 60000
Res
pon
seTi
me(
s)
page_size(B)
5 Repliche, terzo Cluster
1KB 1KB_R 10KB 10KB_R 20KB 20KB_R 30KB 30KB_R 40KB 40KB_R 50K 50KB_R
OK ma mancano barre di errore
Indice di prestazione in funzione del tempo
(m) Tempi di risposta (CBR)
(n) Tempi di risposta (Exponential)
(o) Tempi di risposta (Pareto)
OK solo se non sono valori medi ma valori istantanei
Generazione del traffico
¨ Modello a Singola richiesta ¤ ogni utente entra nel sistema e fa una sola richiesta (ad
una o più risorse)
¨ E’ il modello usato fino ad ora negli esempi
Net serv. time LB serv. time SRV serv. time
tIN tOUT
Generazione del traffico ¨ Modello a sessione di richieste
¤ ogni client entra nel sistema genera una sequenza di richieste (ad una o più risorse) e poi termina
¤ Classico esempio: sessione web ¤ Parametri di carico:
n User think time, number of requests per session, number of object per request, file size, html service demand, embedded object service demand
tIN tOUT
tIN tOUT HTML obj service time
Embedded obj service time
Thin
k tim
e Th
ink
time
richieste sequenziali
richieste parallele
void Web_client( long int my_number ) {! !double filesize, rps, opr;!!sprintf( strbuf, "Web_client%d", my_number );!!create( strbuf ); /* Creazione del processo */!
!!!if(stream_uniform(s[1],0.0,1.0)<(double)H_PRI_RATE){!! !set_priority(H_PRI);!! !set_process_class(hp);!!} else set_process_class(lp);!
!!rps=ceil(stream_lognormal(s[5],4,5)); /*request per sessions*/!!for (i=1;i<=rps;i++){!! !opr=ceil(stream_pareto(s[6],1.5)); /*objects per request*/!! !l = (int)stream_uniform(s[3],0.0, (double)(NUM_FACS-1));!! !use(loadbalancer, SELECTION_TIME); /*Load balancer*/!! !use(servers[l], stream_pareto(s[4],2.0)); /*Server*/!! !hold(stream_pareto(s[2],1.0)/BW+2*RTT); /*network delay
! ! ! ! ! ! !responce*/!! !for (j=1;j<=opr;j++){ ! !!! ! !use(loadbalancer, SELECTION_TIME); !! ! !use(servers[l], stream_pareto(s[4],2.0)); !! ! !hold(stream_pareto(s[2],1.0)/BW+2*RTT); /*network delay
! ! ! ! ! ! !responce*/!! !}!! !hold(stram_pareto(s[7],1.2); /* Think time */!!}!
!!terminate();!}!!
Modello a sessione di richieste con richiesta sequenziale di oggetti
Homework
¨ come modello la richiesta parallela di embedded objects in una pagina HTML?
tIN tOUT HTML obj service time
Embedded obj service time
Thin
k tim
e
Trace drive simulation
¨ Da una traccia possiamo ottenere varie informazioni ¤ tempi interarrivo richieste ¤ tipo di richiesta (html, .jpg, .asp, .pdf, .php, …) ¤ dimensione risposta ¤ sorgente richiesta ¤ …
¨ Possiamo usare la traccia per ¤ ricavare un modello stocastico (workload
characterization) ¤ effettuare una trace driven simulation
Esempi di log file (httpd)
¨ Common log format (CLF) 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326!
!
¨ Combined log format!127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"!
Mail server (starting delivery)
Apr 26 09:44:45 srvdisp qmail: 1335426285.867954 starting delivery 487826: msg 10259125 to local XXXXXX!
Apr 26 09:44:46 srvdisp qmail: 1335426286.478031 starting delivery 487827: msg 10259125 to local XXXXXX!
Apr 26 09:44:54 srvdisp qmail: 1335426294.517049 starting delivery 487828: msg 10259457 to remote YYYYYYYYY!
Apr 26 09:45:00 srvdisp qmail: 1335426300.357987 starting delivery 487829: msg 10259125 to local XXXXXX!
Apr 26 09:45:19 srvdisp qmail: 1335426319.687104 starting delivery 487830: msg 10259445 to remote YYYYYYYYYY!
Apr 26 09:45:19 srvdisp qmail: 1335426319.687209 starting delivery 487831: msg 10259456 to remote YYYYYYYYYY!
Apr 26 09:45:47 srvdisp qmail: 1335426347.408213 starting delivery 487832: msg 10259125 to local XXXXXX!
mail server log (size)
Apr 26 09:55:52 srvdisp qmail: 1335426952.171420 info msg 10259125: bytes 2131 from <[email protected]> qp 4877 uid 1001!
Apr 26 09:55:52 srvdisp qmail: 1335426952.230861 info msg 10259464: bytes 2240 from <[email protected]> qp 4880 uid 1000!
Apr 26 09:55:57 srvdisp qmail: 1335426957.262077 info msg 10259125: bytes 1642 from <[email protected]> qp 4917 uid 1001!
Apr 26 09:56:05 srvdisp qmail: 1335426965.661453 info msg 10259125: bytes 2070 from <[email protected]> qp 4970 uid 1001!
Apr 26 09:56:14 srvdisp qmail: 1335426974.731352 info msg 10259125: bytes 4835 from <[email protected]> qp 5024 uid 1001!
!
mail server log (status)
Apr 26 10:00:21 srvdisp qmail: 1335427221.213428 delivery 487889: success: did_1+0+0/!
Apr 26 10:00:31 srvdisp qmail: 1335427231.461567 delivery 487890: success: did_1+0+0/!
Apr 26 10:00:49 srvdisp qmail: 1335427249.910971 delivery 487891: success: did_1+0+0/!
Apr 26 10:01:04 srvdisp qmail: 1335427264.451140 delivery 487892: success: did_1+0+0/!
Apr 26 10:01:30 srvdisp qmail: 1335427290.492033 delivery 487893: success: did_1+0+0/!
!
status: success, deferral, failure
Eliminazione del transiente: metodo di Welch
1. Effettuare*n*repliche*della*simulazione*(con*n*preferibilmente*≥ *5),*ognuna*di*lunghezza*pari*
a*m*(dove*m*è*sufficientemente*grande).*Sia* jiY *la*i?esima*osservazione*della*j?esima*replica*
(j=1,*2,*...,*n;*i=1,*2,*...,*m);*
2. Per*ogni*osservazione*calcolare*la*media*secondo* ∑=
=n
j
jii n
YY
1* mi ,...2,1=∀ ;*
3. Per* attenuare* le* oscillazioni* ad* alta* frequenza* in* ,..., 21 YY * (ma* lasciare* inalterate* le*
oscillazioni*a*bassa*frequenza)*si*calcola*la*media*mobile,*definita*dall’ampiezza*della*finestra*
temporale*w:*
!!!
"
!!!
#
$
=∀−
−+=∀+
=
∑
∑
−
−−=
+
−=
+
wii
Y
wmwiw
Y
wY i
issi
w
wssi
i
,...,112
,...,112)(
1
)1(
*
4. Infine*effettuare* il*plotting*di* )(wYi wmi −=∀ ,...,2,1 *e*scegliere*un*valore* l*a*partire*dal*
quale*il*grafico*ha*raggiunto*la*convergenza.*
Altri esempi sullo studio del transiente
¨ w = 8000 ed intervalli di osservazione di 500.000 valori (a sinistra) e di 100.000 (a destra)
Altri esempi sullo studio del transiente
¨ w = 8000 ed intervallo di osservazione di 100.000 valori (a sinistra) e con w = 2000 ed intervallo di 20.000 (a destra)