493694bca1969328f6a142672872f568b3d83a6d
[aquarium] / doc / arch / aquarium.tex
1 \documentclass[letterpaper,twocolumn,10pt]{article}
2 \usepackage{usenix, epsfig, endnotes, xspace, url}
3
4 \usepackage{amsmath}
5 \usepackage{amssymb}
6 \usepackage{graphicx}
7 \usepackage{listings}
8 \usepackage{color}
9
10 \newcommand{\cL}{{\cal L}}
11 \newcommand{\TODO}{{\sl TODO \marginpar{\sl TODO}}}
12 \newcommand{\DTime}{\ensuremath{T}\xspace} % Time dimension
13 \newcommand{\DeltaDTime}{\ensuremath{\Delta{T}}\xspace}
14 \newcommand{\DUnitR}{\ensuremath{U_{R}}\xspace} % Unit of measure for resource R
15 \newcommand{\DeltaDUnitR}{\ensuremath{\Delta U_{R}}\xspace}
16 \newcommand{\MB}[1]{\ensuremath{#1\,\mbox{\sc MB}}}
17 \newcommand{\GB}[1]{\ensuremath{#1\,\mbox{\sc GB}}}
18 \newcommand{\secs}[1]{\ensuremath{#1\,sec}}
19
20 \newcommand{\todo}[1]{\textbf{TODO}\footnote{\textbf{TODO:} #1}}
21
22 \newcommand{\grnet}{{\sc grnet}\xspace}
23
24 \begin{document}
25
26 %don't want date printed
27 \date{}
28
29 %make title bold and 14 pt font (Latex default is non-bold, 16 pt)
30 \title{Aquarium: Billing for the Cloud in the Cloud}
31
32 \author{
33 {\rm Georgios Gousios}\\
34 GRNET S.A.
35 \and
36 {\rm Christos KK Loverdos}\\
37 GRNET S.A.
38 \and
39 {\rm Panos Louridas}\\
40 GRNET S.A.
41 \and
42 {\rm Nectarios Koziris}\\
43 GRNET S.A.
44 % copy the following lines to add more authors
45 % \and
46 % {\rm Name}\\
47 %Name Institution
48 } % end author
49
50 \maketitle
51
52
53 % Use the following at camera-ready time to suppress page numbers.
54 % Comment it out when you first submit the paper for review.
55 \thispagestyle{empty}
56
57 \subsection*{Abstract}
58
59 An important part of public IaaS offerings is resource management and
60 customer billing. In this paper, we present the design and
61 implementation of Aquarium, an extensible billing service software.
62 Aquarium associates state changes in cloud resources with respective
63 charges, based on configurable, user-specific and versioned charging
64 policy. The implementation of Aquarium is characterized by pervasive
65 data immutability, actor message passing and service orientation.
66
67 \section{Introduction}
68
69 Public cloud infrastructures have emerged as an alternative to
70 building and maintaining expensive proprietary data
71 centers.~\cite{Lourid10}. An important part of all public clouds is
72 resource management and customer billing~\cite{Armbr10}.
73 Unfortunately, even though all proprietary platforms do feature
74 mechanisms for billing customers for resource usage, there is
75 currently a lack of open solutions.
76
77 In this paper we present Aquarium, an open source resource billing software,
78 designed to handle the production  requirements of \grnet's public
79 Infrastructure as a Service (IaaS) platform. Aquarium utilizes a custom Domain
80 Specific Language ({\sc dsl}) for configuring the supported resources, the
81 pricelists, and the billing algorithms. It receives input from an event queue
82 and presents billing results through a {\sc rest api}. It has been developed
83 in Scala, using the Akka library to handle concurrency and actor-based
84 event processing. In the following sections, we present the requirements
85 that have driven Aquarium's design, the software architecture and
86 implementation of important computational algorithms, and a preliminary
87 evaluation of Aquarium's performance. 
88
89 \section{Requirements}
90
91 Aquarium was designed on a clean sheet to serve a particular purpose,
92 namely the provision of billing services to an IaaS infrastructure,
93 and also be extensible to new services. In the following sections, we
94 briefly present the requirements that shaped Aquarium's design.
95
96 Aquarium is developed to provide accounting and billing to \grnet's
97 cloud computing services---although its design ensures that its use is
98 not limitted to \grnet's specific requirements. These services include
99 provision of {\sc vm}s and online storage; additional services will be
100 built on top of them (for instance, repository services and services
101 for big data computations). Aquarium should be therefore able to:
102 \begin{itemize}
103 \item Provide accounting and billing for different resources, not all of
104 them known in advance. 
105 \item Cater for a variety of different pricing policies.
106 \item Allow for application of different pricing policies to different
107   resources, for different users, at different periods of time.
108 \item Allow for dynamic modification of any of the above.
109 \item Provide a consistent (not eventually consistent) view of users'
110   resource usage and billing.
111 \end{itemize}
112
113 Since \grnet's cloud computing services are offered to the whole Greek
114 research and academic community, Aquarium must be able to scale and be
115 flexible to cover different resource usage patterns for different
116 users.
117
118 As Aquarium must accommodate different resources with different
119 policies for different users over time, we were faced either with a
120 logistical nightmare of giving users resource chunks directly, or
121 adopting a \emph{pecunia non olet} approach, where users are given
122 credit, which they can use as they see fit. In \grnet's case, users
123 are not charged real money for using the services, so the credit is
124 virtual, but this does not make any difference to Aquarium.
125 Specifically, \grnet will supply virtual currency to its users, which
126 they will be able to spend on acquiring and using resources. If real
127 cash were used, \grnet (or any entity using Aquarium) would only need
128 to substitute real credit for virtual credit, without any changes in
129 Aquarium itself.
130
131 Aquarium is in the critical path of user requests that modify resource
132 state; all supported applications must query Aquarium in order to
133 ensure that the user has enough credits to create a new resource. This
134 means that for a large number of users (more than tens of thousands),
135 Aquarium must update and maintain in a queryable form their credit
136 status, with soft realtime guarantees.
137
138 Being on the critical path also means that Aquarium must be highly
139 resilient. If Aquarium fails, even for a short period of time, it must
140 not loose any billing events, as this will allow users to use
141 resources without being charged. Moreover, in case of failure,
142 Aquarium must not corrupt any billing data under any circumstance,
143 while it should reach an operating state very fast after a service
144 restart.
145
146 \section{Resources, Events, and Policies}
147
148 Aquarium is the recipient of several types of events from external
149 systems. More specifically, systems that manage the lifetime and
150 operation of chargeable resources are responsible to send events that
151 describe notable resource state changes. As an example, when a user
152 consumes disk space during a file upload, a resource event for the
153 \textsf{diskspace} resource along with the amount of bytes consumed
154 will be sent to Aquarium.
155
156 Another type of events are the user-related events. For example,
157 Aquarium needs to know when a user is first created and when the user
158 is activated or suspended. 
159
160 \begin{figure}[th]
161 \lstset{language=C, basicstyle=\footnotesize,
162 stringstyle=\ttfamily, 
163 flexiblecolumns=true, aboveskip=-0.9em, belowskip=0em, lineskip=0em}
164
165 \begin{lstlisting}
166 {
167   "id":"4b3288b57e5c1b08a67147c495e54a68655fdab8",
168   "occuredMillis":1314829876295,
169   "receivedMillis":1314829876300,
170   "userId": "31",
171   "cliendId": "snf-astakos-1",
172   "resource": "vmtime",
173   "value": 1,
174   "details": {
175     "vmid": "3300",
176     "action": "on"
177   }
178 }
179 \end{lstlisting}
180 \caption{A JSON-formatted \texttt{ResourceEvent}} 
181 \label{fig:resevt}
182 \end{figure}
183
184 For the exchange of events we have adopted the {\sc json} format.
185 Figure~\ref{fig:resevt} presents a JSON-formatted
186 \texttt{ResourceEvent} value. 
187
188 Of particular interest is the \textsf{details} map. Several resource
189 types can use this map in order to pass resource-specific attributes
190 to Aquarium, which in turn can be hooked into the charging algorithm.
191 We motivate this extension mechanism with an example for the
192 \textsf{VMtime} resource type, which simply represents usage of
193 virtual machines. A respective resource event needs to specify:
194 \begin{itemize}
195 \item Which particular resource instance (which virtual machine) it refers to.
196 \item The relevant state change for the resource instance. In this case, a virtual machine can be started (\textsf{on} state) or stopped (\textsf{off} state).
197 \end{itemize}
198
199 In our example of Figure~\ref{fig:resevt}, we use the \textsf{vmid}
200 and \textsf{action} extensions to specify that the virtual machine
201 instance with identifier \textsf{3300} was started, i.e. it
202 transitioned to the \textsf{on} state. We should generally note that each
203 resource type is free to choose the domain-specific attribute name for
204 the instance \textsf{ID}.
205
206 For the timing of events we assume all systems that send events to
207 Aquarium have synchronized clocks. We actually \textit{require} this,
208 so that Aquarium is not concerned with time book keeping.
209
210 We addressed the configuration requirements of Aquarium by creating a
211 new {\sc dsl}, based on the {\sc yaml} format. The {\sc dsl} enables
212 administrators to specify chargeable resources, charging policies and
213 price lists and combine them arbitrarily into agreements applicable to
214 specific users, user groups or the whole system. The {\sc dsl}
215 supports inheritance for policies, price lists and agreements and
216 composition in the case of agreements. It also facilitates the
217 definition of generic, repeatable debiting rules, which are then used
218 by the system to refill the user's account with credits on a periodic
219 base.
220
221 \begin{figure}
222 \lstset{language=c, basicstyle=\footnotesize,
223 stringstyle=\ttfamily, 
224 flexiblecolumns=true, aboveskip=-0.9em, belowskip=0em, lineskip=0em}
225
226 \begin{lstlisting}
227 resources:
228   - resource:
229     name: bandwidthup
230     unit: MB/hr
231     complex: false
232     costpolicy: continuous
233 pricelists:
234   - pricelist: 
235     name: default
236     bandwidthup: 0.01
237     effective:
238       from: 0
239   - pricelist: 
240     name: everyTue2
241     overrides: default
242     bandwidthup: 0.1
243     effective:
244       repeat:
245       - start: "00 02 * * Tue"
246         end:   "00 02 * * Wed"
247       from: 1326041177        //Sun, 8 Jan 2012 18:46:27 EET
248 algorithms:
249   - algorithm:
250     name: default
251     bandwidthup: $price times $volume
252     effective:
253       from: 0
254 agreements:
255   - agreement:
256     name: scaledbandwidth
257     pricelist: everyTue2
258     algorithm:
259       bandwidthup: |
260         if $volume gt 15 then
261           $volume times $price
262         elsif $volume gt 15 and volume lt 30 then
263           $volume times $price times 1.2
264         else
265           $volume times price times 1.4
266         end
267 \end{lstlisting}
268 %$
269 \caption{A simple billing policy definition.} 
270 \label{fig:dsl}
271 \end{figure}
272
273 In Figure~\ref{fig:dsl}, we present the definition of a simple (albeit valid) 
274 policy. The policy parsing is done top down, so the order of definition 
275 is important. The definition starts with a resource, whose name is then
276 re-used in order to attach a pricelist and a price calculation algorith to it.
277 In the case of pricelists, we present an example of \emph{temporal overloading};
278 the \texttt{everyTue2} pricelist overrides the default one, but only for 
279 all repeating time frames between every Tuesday at 02:00 and Wednesday at
280 02:00, starting from the timestamp indicated at the \texttt{from} field. Another
281 example of overloading is presented at the definition of the agreement, which
282 overloads the default algorithm definition using the imperative part of the
283 Aquarium {\sc dsl} to provide a scaling charge algorithm.
284
285 \section{Architecture}
286 \input{arch}
287
288 \section{Computational aspects}
289
290 \subsection{Charging basics and cost policies}
291
292 In order to charge based on the incoming resource events, time (\DTime) and the unit of measure (\DUnitR) for a resource ($R$) play a central role. \DUnitR can be taken into account either as whole value or as a difference \DeltaDUnitR. On first approximation, these lead to linear formulas that capture the essence of charging algorithms. Below, we will briefly  study charging scenarios for three well-known resources, namely \textsf{bandwidth}, \textsf{diskspace} and \textsf{vmtime}. For the analysis of each case, we assume: 
293 \begin{itemize}
294 \item The arrival of two consecutive resource events, happening at times $t_0$ and $t_1$ respectively, with a time difference of  $\Delta T = \Delta T_{0, 1} = t_1 - t_0$.
295
296 \item The total values of resource $R$ for times $t_0$ and $t_1$ are $U_R^0$ and $U_R^1$ respectively.
297 %In general, for time $t_i$, the respective total value would be $U_R^i$.
298
299 \item The charging unit is denoted as $C$. %By definition it is one credit.
300
301 \item A factor in the form $[\frac{C}{D}]$ represents the resource-specific charging unit, where $C$ is defined above, and $D$ depends on the combination of the previously discussed dimensions ($T$, $U_R$) that enters the calculation. The meaning of the factor is probably clearer if we think of it as ``credits per $D$'', as the representation readily suggests.
302 \end{itemize}
303
304 \paragraph{\textsf{bandwidth}}
305 In this case, an event at $t_1$ records a change of bandwidth, using the relevant unit of measure $U_R$.  The credit usage computation is $\Delta U_R \cdot  [ \frac{C}{U_R} ]$.
306 A concrete example is $\Delta U_R = \MB{10}$ and in this case the bandwidth charging unit $[ \frac{C}{U_R} ]$ is ``$credits$ per {\sc MB}'', since $U_R$ is measured in {\sc MB}.
307
308 \paragraph{\textsf{diskspace}}
309 We take into account the disk space $U_R^0$ occupied at $t_0$ together with the time passed, $\Delta T$. The credit usage computation is $U_R^{0} \cdot \Delta T \cdot [ \frac{C}{U_R \cdot T} ]$.
310 That is, when we receive a new state change for disk space, we actually calculate for how long we occupied the total disk space without counting the new state change. If we had \GB{1} at $t_0 = \secs{1}$ and we gained another \GB{3.14} at $t_1 = \secs{3.5}$ then we are charged for the \GB{1} we occupied for $3.5 - 1 = 2.5$ seconds. The disk space charging unit $[ \frac{C}{U_R \cdot T} ]$ is ``$credits$ per {\sc GB} per $sec$'', assuming $U_R$ (disk space) is measured in {\sc GB} and time in $sec$.
311
312
313 \paragraph{\textsf{vmtime}}
314 Events for VM usage come into pairs that record \textsf{on} and \textsf{off} states of the VM. We use the time difference between these events for the credit usage computation, given by $\Delta T \cdot [ \frac{C}{T} ]$.
315
316
317 The charging algorithms for the sample resources given previously motivate related cost policies, namely \textsf{discrete}, \textsf{continuous} and \textsf{onoff}. Resources employing the \textsf{discrete} cost policy are charged just like \textsf{bandwidth}, those employing the \textsf{continuous} cost policy are charged like \textsf{diskspace} and finally resources with a \textsf{onoff} cost policy are charged like \textsf{vmtime}. Due to space limits we omit a more detailed analysis and the description of more involved scenarios.
318
319
320 \subsection{State management}
321
322 %The only data mutation that takes place is the
323 %actor's state. Since each actor handles only its user's events and
324 %since there is only one actor for a user, the user state mutation is
325 %guaranteed to be race-free and events for different users are handled
326 %asynchronously and concurrently.
327
328 Scheduled tasks compute total charges, the updated resource state and
329 a total credit amount for each billing period. This computation is
330 recorded to a persistent store, in an append-only fashion, for future
331 reference and as a cached value. This cached value can be handy in
332 computations or in case of system crashes. In the latter, we wish to
333 avoid recomputation based on the whole history of events.
334
335 \section{Performance}
336
337 To evaluate the performance of Aquarium, we formulated an experiment
338 that evaluated two important properties: the time required to perform
339 the charging operation for a resource event and the overall time
340 required to process a resource event, end to end. To conduct the
341 experiment, Aquarium was configured, using the policy {\sc dsl} to
342 handle billing events for 5 types of resources, using 3 overloaded
343 pricelists, 2 overloaded algorithms, all of which were combined to 5
344 different agreements. Aquarium's data store was pre-filled in with
345 1.000.000 resource events, evenly distributed among 1.000 users. To
346 drive the benchmark, we used a synthetic load generator that produced
347 random billing events, at a configurable rate per minute.
348
349 To run the benchmark, we deployed Aquarium on a virtualized 4 core
350 2{\sc gh}z class {\sc cpu} and 4{\sc gb} {\sc ram} Debian Linux
351 server, on the Okeanos cloud infrastructure. The virtual machine
352 running Aquarium was configured with a 4{\sc gb} maximum heap size.
353 Rabbit{\sc mq} and Mongo{\sc db} where run in another 4-core, 4{\sc gb
354   ram} virtual machine. Both systems were run using current versions
355 at the time of benchmarking (2.7.1 for Rabbit{\sc mq} and 2.6 for
356 Mongo{\sc db}). The two virtual machines did not share a physical host
357 and communicated over Okeanos's switched network fabric at an
358 effective rate of 800 Mbits/sec, as reported by the \texttt{iperf}
359 utility. We paid particular attention to have Mongo{\sc db} load the
360 full working data set in memory, by repeatedly querying all stored
361 records. No further optimization was performed on either back-end
362 system.
363
364 \begin{figure}[t]
365     \begin{center}
366         \includegraphics[scale=0.63]{perf.pdf}
367     \end{center}
368
369     \caption{Average time for performing a billing operation and end
370       for end to end message processing for 100 active users and a
371       varying number of messages per minute.}
372     
373     \label{fig:perf}
374 \end{figure}
375
376 All measurements were done using the first working version of the Aquarium
377 deployment, so no real optimisation effort has taken place. This shows in the
378 current performance measurements, as Aquarium was not able to handle more than
379 about 500 billing operations per second. One factor that contributed to this
380 result was the way resource state recalculations was done; in the current
381 version, the system needs to re-read parts of the event and billing state from
382 the datastore every time a new resource event appears. This contributes to more
383 than 50\% of the time required to produce a charging event, and can be
384 completely eliminated when proper billing snapshots are implemented. In other
385 measurements, we also observed that the rate of garbage creation was extremely
386 high, more that 250 {\sc mb}/sec. Upon further investigation, we attributed it
387 to the way policy timeslot applicability is calculated. Despite the high
388 allocation rate, the {\sc jvm}'s garbage collector never went through a
389 full collection cycle; when we forced one after the benchmark run was over, 
390 we observed that the actual heap memory usage was only 80{\sc mb}, which
391 amounts to less than 1 {\sc mb} per user.
392
393 Even so, by extrapolating on the results and hardware configuration, an average
394 12-core box could handle more 1.500 messages per minute from about 300 active
395 users, at 5 events per minute. Given that activity from users is expected to
396 arrive in bursts, a more realistic expectation might be to receive 1 message
397 per user per 5 minutes on average; in that case, and provided that the resource
398 query cost is negligible as it is being served from an in memory cache, the
399 system could handle around 4.500 concurrent users. While such back of the
400 envelop calculations do not account for traffic spikes, they do provide an
401 rough estimation of the optimisation effort that must be put in place. 
402
403 \section{Related Work}
404
405 Yousef et al.~\cite{Youse08} described the three pricing models that
406 are used by cloud service providers for billing used resources, namely
407 tiered pricing, per-unit pricing and subscription-based pricing.
408 Aquarium's cost policies that are assigned to resources map exactly to
409 Yousef's pricing models. In fact, most offerings by public IaaS
410 providers~\cite{Azure12, Amaz12} offer services charged according to
411 Yousef models.
412
413 Work on resource accounting and billing has been carried out in the
414 context cloud federation~\cite{Rochw09, Elmro09} and (earlier) grid
415 federation projects. The Distributed Grid Accounting System ({\sc
416   dgas})~\cite{Piro06} was among the first to enable resource
417 accounting at the computing and storage layers and then aggregation of
418 the resources in a centralized location. The Reservoir project
419 investigated the use of service level agreements~\cite{Elmro09} for
420 resource provisioning in federated cloud scenarios.
421
422 On the cloud computing front, vendors such as VMWare, Microsoft and
423 {\sc ibm} provide full stack solutions, which also include resource
424 accounting. Usually, such systems are connected with existing
425 enterprise resource planning systems. \"Ubersmith has developed an
426 engine dedicated to resource accounting; much like Aquarium, it tracks
427 resource usage and applies accounting policies to it. On the open
428 source front, neither the Cloustack nor the Openstack projects, have
429 yet incorporated billing into their services. To the best of our
430 knowledge, Aquarium is the first open source system to offer
431 configurable accounting services for IaaS deployments.
432
433 Check also~\cite{Ruiz-Agundez11}.
434
435 \section{Discussion and Future Work}
436
437 A typesafe language was a hard requirement. Of the platforms examined,
438 the {\sc jvm} had the richest collection of ready made components; the
439 Akka library was particularly enticing for the scalability and
440 distribution possibilities it offered.
441
442 Scala as a language was an enabling factor; case classes permitted the
443 expression of data models, including the configuration {\sc dsl}, that
444 could be easily be serialized or read back from wire formats while
445 also promoting immutability through the use of the \texttt{copy()}
446 constructor. The pervasive use of immutability allowed us to write
447 strict, yet simple and concise unit tests, as the number of cases to
448 be examined was generally low. The
449 \textsf{Maybe}\endnote{\textsf{Maybe} works like \textsf{Option}, but
450   it has an extra possible state (\textsf{Failed}), which allows
451   exceptions to be encapsulated in the return type of a function, and
452   then retrieved and accounted for in a pattern matching operation
453   with no side effects. More at
454   \url{https://github.com/loverdos/Maybe}} monad, enabled side-effect
455 free development of data processing functions, even in cases where
456 exceptions were the only way to go. 
457
458 Akka's custom supervision hierarchies allowed us to partition the
459 system in self-healing sub-components, each of which can fail
460 independently of the other. For example, if the queue reader component
461 fails due to a queue failure, Aquarium will still be accessible and
462 responsive for the {\sc rest} interface. Also, Akka allowed us to
463 easily saturate the processing components of any system we tested
464 Aquarium on, simply by tuning the number of threads (in {\sc i/o}
465 bound parts) and actors (in {\sc cpu} bound parts) per dispatcher.
466
467 From a software engineering point of view, the current state of the project was
468 reached using about 8 person months of effort, 2 of which were devoted to
469 requirements elicitation, prototype building and familiarizing with the
470 language. The source code currently consists of 7.000 lines of executable
471 statements (including about 1.200 lines of tests), divided in about 10
472 packages. The system is built using both {\sc sbt} and Maven.
473
474 Aquarium is currenty under development, with a first production deployment
475 planned for April 2012. In the future, we plan to invest resources into
476 creating a comprehensive {\sc rest api} for accessing the user actor state and
477 to distribute the message processing accross multiple nodes in an active-active
478 mode.
479
480 \section{Acknowledgments and Availability}
481
482 Aquarium has been developed under contract from the Greek Ministry of Education
483 \todo{Fix Ack}
484
485 Aquarium is available under a {\sc bsd} 2-clause license from:
486 \url{https://code.grnet.gr/projects/aquarium}
487
488 {\footnotesize \bibliographystyle{acm}
489 \bibliography{aquarium}}
490
491 \theendnotes
492
493 \end{document}