\section{Workload Characterization}
\label{sec:charac} 

In this section, we present a workload characterization of the UOL video service under different perspectives, modeling various aspects and distributions. 


\subsection{Session Definition}

Before presenting our analyses, we need to define an appropriate session duration for the sessions in our data. 
A user session is defined as a series of requests performed by a user to a Web site during a certain period of time~\cite{menasce-ec-99,arlitt00}. In online video
social networks, a typical session includes a list of videos by subject, search, video streaming, interaction with other users through the publication of
comments and evaluation of videos. These requests are very different from requests on user sessions of the traditional Web sites, which does not provide the
same level of interaction between users and objects as occurs in the Web 2.0 systems.

To determine the beginning and the end of a session in the UOL video service it is necessary to analyze the inter-request time between requests from the same user to
measure the period of inactivity of that user, since the sessions do not present a registry of login and logout. Thus, it is necessary to perform
an analysis to identify the time limit between requests to consider them as belonging to the same session. We consider two consecutive requests as belonging to the same session if
the time between them is smaller than this limit, namely \textit{session timeout}.

It is important to choose an appropriate session timeout in order to avoid generating sessions which do not represent the use of the service by users, avoiding
to join different moments of the use of the service or to fragment the user navigation. Following the methodology proposed in~\cite{menasce-ec-99}, we evaluate
the suitable session timeout for our application.

Figure~\ref{fig:nsessions} (left) presents the total number of sessions for different values of session timeout. A value extremely small (e.g. 1 minute) could
result in a high volume of sessions. As the value of the session timeout increases, the number of sessions is reduced continuously until stabilizing. The
stability occurs around 40 minutes, indicating this value as a suitable session timeout.


\begin{figure*}[htb]
\centering
\includegraphics[width=.49\textwidth]{fig/nsessions}
\includegraphics[width=.49\textwidth]{fig/nsessions_per_user}
\caption{Session Timeout (left) e CDF of the Number of Session per User (right)}
\label{fig:nsessions}
\end{figure*}

In addition to this analysis to choose a suitable session timeout, we also generate the cumulative distribution function (CDF) of the number of sessions per user for several values of session
timeout, as depicted in Figure~\ref{fig:nsessions} (right). The difference between the distributions for different values of session timeout is higher for
smaller values, becoming very small for values greater than 40 minutes. Thus, we adopt 40 minutes as session timeout for our analyses. In totality, our workload
contains 1,127,537 user sessions.

It is interesting to observe that our choice is coherent with the analysis made in~\cite{youtube_sessions}. Compared to previous efforts, which characterize
sessions in traditional Web sites~\cite{arlitt00,oke-tools2002}, the longest timeout values obtained are much longer compared to the 10 minutes usually
observed. The most intuitive reasons for this behavior are the longer time period that users take to watch a video and the interactive tools, which can make users to spend more time on
the site.




\subsection{Object Popularity}

Initially, we evaluate the popularity of objects aiming at verifying if the popularity of video views and tags searched follow a power law. Power laws establish the
following relation $P(E_n) \propto n^{-\alpha}$, where $P(E_n)$ is the probability of reference to the $n^{th}$ most popular element. In order to verify the
accuracy of the proposed models, we measure the factor $R^2$ of the linear regression~\cite{r2} for each analyzed distribution. In all the models presented, the
values of $R^2$ are higher than 0.97. A value of $R^2$ equals to 1 means that there are not differences between the model and the real workload.

\begin{figure*}[htb]
\centering
\includegraphics[width=.49\textwidth]{fig/ranking_videos}
\includegraphics[width=.49\textwidth]{fig/ranking_tag}
\caption{Videos Ranked by the Number of Views (left) and Tags Ranked by the Number of Access (right)}
\label{fig:ranking}
\end{figure*}


Next we analyze if the popularity distributions of videos and tags follows a power law. Figure~\ref{fig:ranking} (left) shows the ranking of video sorted by
the number of views. We can note that a small number of videos have a high number of views and that a high number of videos have only a few views. Such observation is
important since it suggests an opportunity for video caching. In fact, the distribution is modeled by a function that follows a power law,
with $\alpha = 1.156$ and $R^2 = 0.979$.

Similarly, Figure~\ref{fig:ranking} (right) shows the ranking of access to tags (e.g. lists of all videos with a certain tag). 
We can note that some tags concentrate a high number of accesses. As example,
the first tag of the ranking has 10,266 accesses. This ranking can be modeled by a power law distribution, with $\alpha = 0.983$ and $R^2 = 0.983$.







\subsection{User Activity}

Next, we analyze the level of activity of users in the system. We know that users can access the UOL video service several times in the same session or
in different sessions. Thus, in order to model the level of activity of users in the system, we characterize the
ranking of users in terms of requests sent and in terms of number of sessions created. By user we mean each anonymous IP of our workload.




\begin{figure*}[hbt]
\centering
\includegraphics[width=.49\textwidth]{fig/ranking_ip_all}
\includegraphics[width=.49\textwidth]{fig/ranking_user_nsessions}
\caption{Ranking of User Activity in Terms of Requests (left) and Sessions (right)}
%\vspace{-0.3cm}
\label{fig:ranking_user}
\end{figure*}

Figure~\ref{fig:ranking_user} (left) shows the ranking of users according to the number of requests sent to the server. We can note that there is a small number
of users that generate large amounts of requests to the server and a large number of users who sent few requests. In fact, the distribution is well modeled
by a power law of the type $f(x) = bx^{-\alpha}$, with $\alpha = 0.745$, and $R^2 = 0.987$.

In terms of sessions created in the server, the analysis shows that an exponential distribution is the function that better models the data. Thus, the ranking
of sessions can be modeled by an exponential distribution of the type $f(x) = \alpha e^{\beta x}$, with $\alpha = 175.2$ and $\beta = -0.002681$. This result
emphasizes the behavior that few users can generate large amounts of sessions, whereas most users generate only a few sessions.



%
%General model Exp1:
%       f(x) = a*exp(b*x)
%Coefficients (with 95% confidence bounds):
%       a =       175.2  (174, 176.3)
%       b =   -0.002681  (-0.002735, -0.002627)
%
%Goodness of fit:
%  SSE: 2540
%  R-square: 0.9966
%  Adjusted R-square: 0.9966
%  RMSE: 3.695
%

\subsection{Temporal Patterns}


This Section analyzes the number of requests that arrive in the server as a function of time. The requests about video streaming are not registered in the
workload. We have registered only HTML requests that provide access to the video. Thus, we cannot quantify the traffic in terms of bytes transferred by
the UOL video service with our workload.

\begin{figure*}[hbt]
\centering
\includegraphics[width=.49\textwidth]{fig/requests_bin}
\includegraphics[width=.49\textwidth]{fig/inter_req_time}
\includegraphics[width=.51\textwidth]{fig/inter_session_time}
\caption{Number of Requests in Intervals of one hour (top left). CCDF for the Inter-request Time (top right) and Inter-Session Time (down)}
\label{fig:temporal}
\end{figure*}


Figure~\ref{fig:temporal} (top left) shows the number of requests that arrive in the server in time intervals of one hour. The curve presents a periodic pattern,
with more intensity of requests during the day and small intensity during the night, similarly to other traditional Web
servers~\cite{eveline@tnet,arlitt_invariants}. Note that there are some points in which we can see 50,000 requests in 1 hour. Such points represent links to
videos available on popular Web pages of the UOL portal.

In order to analyze the participation of users visiting the system, we characterize the inter-request and inter-session time. We present in
Figures~\ref{fig:temporal} (top right) and (down) the complementary cumulative distribution function for these two metrics. We can note that the probability of
the inter-request time being higher than 5 seconds is smaller than 1\%, whereas 57\% of the requests that arrive in the server have time intervals smaller than 1
second. Similarly, about 96\% of the intervals between sessions are smaller than 5 seconds.

Both distributions are better modeled by an exponential function of the type  $f(x) = \alpha e^{\beta x}$. For the distribution of inter-request times we obtained
an  $\alpha = 0.424$ and $\beta = -1.298$ with $R^2 = 0.996$, and for the distribution of inter-session times we found an $\alpha = 0.5518$ and $\beta = -0.7309$ with $R^2 = 0.989$.


 
%A distribuição exponencial é a correspondente da distribuição de {\it Poisson} quando nos referimos a intervalos entre chegadas. Assim, podemos dizer
%que os intervalos de chegada ao servidor, tanto em termos de requisições quanto em termos de sessões, segue um processo de {\it Poisson}.


%Note que as figuras~\ref{fig:temporal} (meio) e (direita) não foram exibidas no formado convencional \textit{log-log} porque os modelos encontrados para as duas distribuições geram alguns números negativos, que não são exibidos em escala logarítmica. 

%1) Tempo entre requisições (R2 = 0.9964)
%
%General model Exp1:
%       f(x) = a*exp(b*x)
%Coefficients (with 95% confidence bounds):
%       a =       0.424  (0.4176, 0.4304)
%       b =      -1.298  (-1.347, -1.248)
%
%Goodness of fit:
%  SSE: 0.0006769
%  R-square: 0.9964
%  Adjusted R-square: 0.9964
%  RMSE: 0.003227
%
%2) Tempo entre sessões (R2 = 0.9893)
%
%General model Exp1:
%       f(x) = a*exp(b*x)
%Coefficients (with 95% confidence bounds):
%       a =      0.5518  (0.54, 0.5635)
%       b =     -0.7309  (-0.7615, -0.7002)
%
%Goodness of fit:
%  SSE: 0.004094
%  R-square: 0.9894
%  Adjusted R-square: 0.9893
%  RMSE: 0.0061

\subsection{Referrer of Requests and Sessions}

\begin{table}[htb]
\begin{center}
%\small 
\begin{tabular}{|l|c|c|}
\hline
\textbf{Domain} & \textbf {\% of Accesses} & \textbf{\% of Sessions} \\
\hline
uol.com.br & 50.46\% &  75.71\%  \\ \hline
videos.uol.com.br & 39.58\% & 12.10\%  \\ \hline
.br  & 7.26\%  & 7.89\%  \\ \hline
Others & 2.69\% & 4.30\% \\ \hline
\end{tabular}
\end{center}
\caption{Referrer of User Requests and Sessions}
\label{tab:referrer}
\end{table}

Next, we analyze the referrer of requests and sessions of users accessing the system. To analyze how users begin to navigate in the video system, we analyze the referrer of the first
request of each session. About 50\% of the sessions do not have the field referrer in the first request, being thus discarded. Similarly, around 40\% of the requests
do not have this field and were thus not used. Table~\ref{tab:referrer} shows the referrer of sessions and of requests accessing the system. We note that most part
of the sessions and requests come from other UOL services. However, a significant fraction (around 40\%) of the requests have origin in the video service, 
corresponding thus to users watching other videos or interacting with other users in the system. Only a small part of the requests and sessions come from other sites.



\subsection{Probability of Activity over Time}

%\noindent 
We next investigate whether there is any correlation between the
occurrence of a particular type of activity (e.g. Search, view a video, etc.) and session duration. To check for
such correlation, we categorized user sessions into four
non-overlapping classes based in their session durations: (\textit{a})
less than 1 minute long, (\textit{b}) between 1 and 10 minute long, (\textit{c}) between 10 and 
20 minute long, and (\textit{d}) longer than 20 minutes. For sessions
belonging to each of these intervals, we examined the average
proportion of the total session duration that a user spent on each
activity.
 

\begin{figure*}[htb]
\centering
\includegraphics[width=.49\textwidth]{fig/ubmg_per_user_session_duration_time_all}
\includegraphics[width=.49\textwidth]{fig/ubmg_per_user_session_duration_time_down}
\caption{Probability of Different Types of User Activities as Functions of Session Durations (Error Bars Indicate 95\% Confidence Interval)}
\label{fig:activity_time}
\end{figure*}

Figure~\ref{fig:activity_time} shows the fraction of time spent on each type of activity as a function of session duration. The results are shown in two separate plots, one
containing all groups of activities and the other removing the group View in order to emphasize
the trends for the less popular activities. 
We found two key patterns. First, regardless of session duration, users spent most of their time viewing videos.  In very short sessions
(i.e., under 1 minute long), users spent 76\% of their time in these activities. For longer sessions (i.e., 20 minutes or longer), users spend more than 89\% of their session times
viewing videos.  Second, the remaining categories of activities become less prevalent for longer sessions. The exception is the time spent evaluating content, which increases by a
factor of 9 when comparing sessions shorten than 1 minute to those longer than 20 minutes.








