\documentclass[landscape]{slides}
\usepackage{multicol}
  
\input{preamble}
\input{SLIDES}

%\usepackage[dvips]{graphics}
%\usepackage[all,poly,ps,dvips,color]{xy}
%\UseCrayolaColors

%\DeclareMathOperator{\mathin}{in}
%\DeclareMathOperator{\mathout}{out}

\newcommand{\vindex}[2]{\left[ #1 \right] _ #2}
\newcommand{\eigen}{\mathbf a}
\newcommand{\elem}{\mathbf e}
\newcommand{\state}{\mathbf x}
\newcommand{\maxdeg}{\Delta}
\newcommand{\maxdegC}{d_{max}}

\newcommand{\din}{d_{\mathin}}
\newcommand{\dout}{d_{\mathout}}
\newcommand{\dmax}{d_{\max}}


\newcommand{\nlabel}[2]{\ar@{} @(#1,#1) |<<{#2}}
\newcommand{\gnlabel}[2]{[#1(.25)] {#2}}
\newcommand{\node}{{\bullet}}
\newcommand{\bypass}{{\circ}}

\begin{document}

\begin{titlepage}
\title{CS 591-06, Lecture 12}

\author {Jared Saia \\
{\red University of New Mexico}}

\date{}
\maketitle

\end{titlepage}


\begin{SLIDE}[The Congestion Problem]

The WWW suffers from distribution delays.  Two causes of delays:
\begin{itemize}
\item Congested Networks
\item Swamped servers
\end{itemize}

Servers and networks can be swamped unexpectedly (e.g. ``cool site of
the day'' phenomena)

\end{SLIDE}

\begin{SLIDE}[Solution to Congestion]
\begin{itemize}
\item Caching is the solution to the congestion problem
\item Nearby cache can serve a page quickly even if page source is swamped
\item Good for the users and good for the group
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Naive Approach]
\begin{itemize}
\item Naive Approach: Provide a group of users with a single shared
cache machine
\item Problem: if cache fails, all users are cut off
\item Problem: a single cache can be a bottleneck
\item Problem: Storage space of a single cache is limited so suffers
false misses
\item Problem: Limited number of users means limited amount of
aggregated requests
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Cooperative Caching]

\begin{itemize}
\item Cooperative Caching: Every client has one \emph{primary cache}.
If the request misses there, the client tries to locate the page in
other cooperating caches.
\item + : fault tolerance, scalability and request aggregation
\item - : consumes excess bandwidth and requires data duplication
\end{itemize}

\end{SLIDE}

\begin{SLIDE}[Akamai Approach]
\begin{itemize}
\item Hash-based scheme - \emph{consistent hashing}
\item A user requesting a page contacts only the one cache responsible
for that page, no inter-cache communication
\item + : less communication overhead per page request, discovers
misses quickly, reliable
\item - (?) : requires mathematical tools to develop the hashing scheme
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Hashing]
\begin{itemize}
\item Goal: Let any client hash a URL to a particular cache containing
that URL
\item Naive Approach: Hash URL u to cache via typical function like $h
(u) = 7u + 4 \mod 23$
\item Problem1: What happens when a 24th cache is added to the system?
(If we change to new function $h' (u)= 7u + 4 \mod 24$, then
essentially every URL is mapped to a different cache.)
\item Problem2: What happens if all of the clients have different
ideas of which servers are available?
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[A View]
\begin{itemize}
\item Each client has a different idea of what servers are available
(since information propogates at different speeds)
\item A \emph{view} for a particular client is the set of servers
which it knows are available
\item Because each client has a different view, each client will have
a different hash function!
\end{itemize}

\end{SLIDE}


\begin{SLIDE}[Desirable Properties]

\begin{itemize}
\item \emph{Monotonicity}: Adding a new cache to any view potentially
remaps URLs only from old caches to the new cache.  No URLs are
remapped from an old cache to another old cache.
\item \emph{Balance}: In any view, URL's are distributed uniformly
over the caching machines in that view
\item \emph{Load}: Over all views, no machine gets too much more than
the average number of URL's
\item \emph{Spread}: No URL is stored on too many caches
\end{itemize}

\end{SLIDE}


\begin{SLIDE}[Consistent Hashing]
\begin{itemize}
\item Choose some standard base hash function that maps strings to the
range $[0,\dots, 1]$.
\item This function maps every URL and every cache machine to the unit circle
\item Now assign each URL to the first cache whose point it encounters
moving clockwise from the URL point
\end{itemize}
\end{SLIDE}


\begin{SLIDE}[Hashing Example]
\ifig{hash1}
\end{SLIDE}

\begin{SLIDE}[Cache Insertion Example]
\ifig{hash2}
\end{SLIDE}

\begin{SLIDE}[Hash Time]
\begin{itemize}
\item Note that for a given view, we can store all the cache points of
that view in a binary tree
\item Then when we want to ``lookup'' a URL, we first find where it
falls on the unit circle and then lookup the nearest cache point in
the binary tree
\item This takes $O (\log C)$ time where $C$ is number of caches.
There is a more technical way to do it in $O (1)$ time.
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[A technical point]
\begin{itemize}
\item For technical reasons, we need to hash each cache to $O (\log C)$
points on the unit circle where $C$ is the number of cache machines
\item Everything else about the hashing algorithm is the same.
\item This duplication of cache points ensures a more uniform
distribution of pages to caches
\end{itemize}
\end{SLIDE}
  
\begin{SLIDE}[Analysis]
Intuition:
\begin{itemize}
\item \emph{Monotonicity}: When we add cache c to system, it ``steals''
only those URL points that are near it.  These are the only URLs that
change who they are hashed to.
\item \emph{Balance}:  In any view, all cache points are closest to
about the same number of URL points
\item \emph{Load}: A cache is stuck with an item if it's the closest
cache to the item in some view.  But if the cache is far from the
item, it's likely that in every view, some other cache is closer.
\item \emph{Spread}: Since only caches close to an item are likely
to be stuck with it in some view, it's likely that only a few caches
will ever be responsible for any item
\end{itemize}
\end{SLIDE}


\begin{SLIDE}[Assumptions]
\begin{itemize}
\item Let $C$ be the number of caching machines
\item Let $V$ be the number of views (and therefor the number of
clients).  Assume $V = \rho C$ where $\rho$ is some constant.
\item Let $U$ be the number of url's, and assume $U = \tau C$ where
$\tau$ is some constant.
\item Assume that each view contains at least $C/2$ cache machines.
\end{itemize}
\end{SLIDE}


\begin{SLIDE}[Consistent Hashing Properties]

\emph{Consistent Hashing} has the following properties:

\begin{itemize}
\item \emph{Monotonicity}: When we add a cache to any view, it ``steals''
only those URL points that are near it.  These are the only URLs that
change who they are hashed to.
\item \emph{Spread}: No URL is stored in more than $O (\log C)$ caches
\item \emph{Load}: Over all views, no machine gets more than $O (\log
C)$ times the average number of URL's
\item \emph{Balance}: In any view, URL's are distributed uniformly
over the caching machines in that view
\end{itemize}

\end{SLIDE}


\begin{SLIDE}[Initial Observations]
\begin{itemize}
\item Consider some fixed interval $I$ on the unit circle of length
$2k/C$ for some constant $k$
\end{itemize}

Questions:	
\begin{itemize}
\item Q1: For a fixed view, what is the probability that no ``cache
point'' falls in the interval I?
\item Q2: What is the probability that in some view, no ``cache
point'' falls in I?
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Question 1]
\begin{itemize}
\item Q1: For a fixed view, what is the probability that no ``cache
point'' falls in the interval $I$?

\item Each ``cache point'' fails to fall in $I$ independently, with
probability $1 - 2k/C$

\item There are at least $C/2* (\log C/2)$ such points ``cache points''.

\item Hence the probability of failure is no more than $(1-2k/C)^{C/2*
(\log C/2)}$.  This probability is no more than $e^{-k\log C/2}$

\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Question 2]
\begin{itemize}
\item Q2: What is the probability that in some view, no ``cache
point'' falls in I?
\item Let $\gamma$ be this bad event and let $\gamma_{i}$ for $1\leq
i\leq V$ be the event that $I$ contains no cache point in the $i$-th view
\item By the Union bound, we know
\begin{eqnarray}
P (\gamma) &\leq & \sum_{i=1}^{V} P (\gamma_{i})\\
& \leq & \sum_{i=1}^{V} e^{-k\log C/2}\\
& = & V* (2/C)^{k}\\
& = & \rho * (2^{k}/C^{k-1})
\end{eqnarray}

\item For $k$ chosen dependent only on $\rho$, this probability can be
made arbitrarily small!
\end{itemize}

\end{SLIDE}

\begin{SLIDE}[Useful Lemma]
To summarize, we've just proven the following important lemma:

\begin{itemize}
\item \emph{Lemma:} For a fixed interval $I$ of size $2k/C$, the event
that in some view, no cache point falls in $I$ is very small
(i.e. $\rho * (2^{k}/C^{k-1})$).
\end{itemize}

\end{SLIDE}



\begin{SLIDE}[Spread]
\begin{itemize}
\item Consider some fixed URL which is cached to the point $p$ on the
unit circle
\item Let $I$ be the interval of length $k*2/C$ for fixed $k$ such
that $p$ is the leftmost point of $I$
\item We've shown that in every view, at least one cache point is in $I$
\item Thus, only cache points which fall in $I$ can ever be
responsible for caching the given URL
\item Q: How many cache points could fall in this interval of size $k*2/C$?
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Spread]

\begin{itemize}
\item Q: How many cache points could fall in this interval of length
$k*2/C$?
\item Let $X$ be the total number of cache points that fall in $I$
\item Each cache point falls in $I$ independently with probability $k*2/C$
\item By linearity of expectation, $E (X) = (C\log C)*k*2/C = 2k*\log
C = O (\log C)$
\item By Chernoff bounds, the probability that $X$ deviates from $E
(X)$ by much is very small
\item By a union bound, the probability that \emph{any} URL contains
more than $O (\log C)$ cache points in its interval is small
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Chernoff Bounds Review]
\begin{itemize}
\item Let $X=\sum _{i=1}^{m}X_{i}$ where the $X_{i}$ are random variables which
are: independent and all take on values between $0$ and $1$.
\end{itemize}
then for any $0<\delta \leq 1$,
\begin{itemize}
\item $P (|X - E (X)| \geq \delta E (X) ) \leq 2e^{\frac{-E (X) \delta
^{2}}{4}}$
\end{itemize}
\end{SLIDE}


\begin{SLIDE}[The Details]
\begin{itemize}
\item For all $1\leq j\leq U$, let $I_{j}$ be the interval of length
$k*2/C$ whose rightmost point is the same as the point that the $i$-th
URL is hashed to on the unit circle.
\item For any $1\leq j\leq U$, let $X_{j}$ be the total number of
cache points that fall in $I_{j}$
\item For any $1\leq j\leq U$, we know that $E (X_{j}) = (C\log C)*k*2/C$
\item By Chernoff Bounds, $P (|X_{j}-E (X_{j})|\geq (2k*\log C)) \leq
2e^{\frac{-2k \log C}{4}}$

\end{itemize}
\end{SLIDE}


\begin{SLIDE}[Details]
\begin{itemize}


\item For any $1\leq j \leq U$, let $\gamma_{j}$ be the event that
$I_{j}$ has more than $4k\log C$ cache points in it.  Then:

\begin{eqnarray}
P (\bigcup_{j=1}^{U} \gamma_{i}) & \leq & \sum_{i=1}^{U} P (\gamma_{i})\\
& \leq & \sum_{i=1}^{U} 2e^{\frac{-2k \log C}{4}}\\
& = & \tau C * 2e^{\frac{-2k \log C}{4}}\\
& = & e^{\frac{-2k \log C + 4\log (2\tau C)}{4}}
\end{eqnarray}
\end{itemize}
\end{SLIDE}

\begin{SLIDE}[Load]
\begin{itemize}
\item Load Fact: Over all views, no cache machine gets more than $O (\log
C)$ times the average number of URL's
\item To show this, note that each cache machine maps to $O (\log C)$
points on the unit circle
\item We can say it is responsible for all the URL points that map to
intervals of length $k*2/C$ associated with these points
\item Finally note that we don't expect too many of the URL points to
fall in any of these intervals!
\item Again we use LOE, Chernoff bounds, and union bounds.
\end{itemize}
\end{SLIDE}

\end{document} 

