A great contribution to the paper.
[aquarium] / doc / arch / aquarium.tex
1 \documentclass[preprint,10pt]{sigplanconf}
2 \usepackage{amsmath}
3 \usepackage{amssymb}
4 \usepackage{graphicx}
5 \usepackage[british]{babel}
6 \usepackage{url}
7 \usepackage{listings}
8 \usepackage{color}
9
10 \newcommand{\cL}{{\cal L}}
11
12 \begin{document}
13 \conferenceinfo{ScalaDays '12}{London, UK.}
14 \copyrightyear{2012}
15 \copyrightdata{1-59593-056-6/05/0006}
16
17 \titlebanner{DRAFT---Do not distribute}
18
19
20
21 \title{Aquarium: Billing for the Cloud in the Cloud}
22
23 \authorinfo{Georgios Gousios \and Christos KK Loverdos}
24 {GRNet SA}
25 {\{gousiosg,loverdos\}@grnet.gr}
26
27 \maketitle
28 \begin{abstract}
29     This paper describes the architecture for the Aquarium cloud infrastructure
30     software.
31 \end{abstract}
32
33 \category{D.3.3}{Programming Languages}{Language Constructs and Features}[Control structures]
34
35 \terms
36     Object-Oriented Programming, Philosophy
37
38 \keywords
39     OOP, Ontology, Programming Philosophy
40
41 \section{Introduction}
42 \section{Requirements}
43
44 Aquarium was designed on a clean sheet to serve a particular purpose,
45 namely the provision of billing services to an IaaS infrastructure,
46 and also be extensible to new services. In the following sections,
47 we briefly present the requirements that shaped Aquarium's design.
48
49 \subsection{Application Environment}
50 Aquarium developed as part of the Okeanos project at GRNet. The
51 Okeanos project is building a full stack public IaaS system for Greek
52 universities, and several services on top of it. Several components comprise
53 the Okeanos infrastructure:
54
55 \begin{description}
56
57     \item[Synnefo] is an IaaS management console. Users can create and start
58         VMs, monitor their usage, create private internal networks among VMs
59         and connect to them over the web. The service backend is based on
60         Google's Ganneti for VM host management and hundrends of physical
61         VM container nodes.
62
63     \item[Archipelago] is a storage service, based on the Rados
64         distributed object store. It is currently under development, and the
65         plan is to act as the single point of storage for VM images, shared
66         volumes and user files, providing clonable snapshots and distributed
67         fault tolerance.
68     
69     \item[Pithos] is a user oriented file storage service. Currently it its
70         second incarnation, it supports content deduplication, sharing of files
71         and folders and a multitude of clients.
72
73     \item[Astakos] is an identity consolidation system that also acts as the
74         entry point to the entire infrastructure. Users can login using 
75         identities from multiple systems, such as the Shibboleth (SAML) 
76         federation enabled across all Greek universities or their Twitter 
77         accounts.
78
79 \end{description}
80
81 While all the above systems (and several prospective ones) have different 
82 user interfaces and provide distinct functionality in the context of
83 the GRnet IaaS, they all share a common notion of \emph{resources}, access
84 and manipulation options to which they offer to users. 
85
86 \subsection{Supported Users}
87
88 The Okeanos IaaS will support the Greek higher education, an estimated
89 population of 100.000 students and researchers. Each member will be granted
90 access to a collection of resources using her institutional account. To enforce
91 a limit to the resources that can be acquired from the platform, each user will
92 have a limited amount of credits, renewable each month, which will be allowed
93 to spend on any resource available through the infrastructure. Resources can
94 also be shared; for example files on the Pithos file service or virtual machine
95 images on the Archipelago storage can be 
96
97
98 \subsection{Configuration}
99
100 Billing systems are by nature open ended. As new services are deployed, new
101 resources appear, while others might be phased out.  Moreover, changes to
102 company policies may trigger changes to price lists for those resources, while
103 ad-hoc requests for large scale computational resources may require special
104 pricing policies. In order for a billing system to be able to successfully
105 adapt to changing requirements, it must be able to accommodate such changes
106 without requiring changes to the application itself. This means that all
107 information required for Aquarium in order to perform a billing operation,
108 must be provided to it externally. Moreover, to ensure high-availability,
109 billing configuration should be updatable while Aquarium is running, or at
110 least with minimal downtime, without affecting the operation of external
111 systems.
112
113
114 \subsection{Scaling}
115
116 In the context of the Okeanos system, Aquarium provides billing services on a
117 per user basis for all resources exposed by other systems. As such, it is in
118 the critical path of user requests that modify resource state; all supported
119 applications must query Aquarium in order to ensure that the user has enough
120 credits to create a new resource. This means that for a large number of users
121 (given previous GRNet systems usage by the Greek research community, we
122 estimate a concurrency level of 30.000 users), Aquarium must update and
123 maintain in a queryable form their credit status, 
124 with soft realtime guarantees. 
125
126 Being on the critical path also means that Aquarium must be highly resilient,
127 too. If Aquarium fails, all supported systems will also fail. Even if Aquarium
128 fails for a short period of time, it must not loose any billing events, as this
129 will allow users to use resources without paying for them. Moreover, in case of
130 failure, Aquarium must not corrupt any billing data under any circumstances,
131 while it should reach an operating state very fast after a service restart.
132
133 \section{Architecture}
134
135
136
137 \section{Implementation}
138
139 \subsection{The configuration DSL}
140
141 The configuration requirements presented above were addressed by creating a new
142 domain specific language ({\sc dsl}), based on the YAML format.  The DSL
143 enables administrators to specify billable resources, billing policies and
144 price lists and combine them arbitrarily into agreements applicable to specific
145 users, user groups or the whole system. 
146 The DSL supports inheritance for policies, price lists and agreements and composition in the case of agreements.
147 It also facilitates the
148 definition of generic, repeatable debiting rules, which are then used by the
149 system to refill the user's account with credits on a periodic based.
150
151 The DSL is in itself based on five top-level entities, namely:
152
153 \begin{description}
154
155     \item[Resources] specify the properties of resources that Aquarium knows
156         about. Apart from the expected ones (name, unit etc), 
157         a resource has two properties that affect billing: \textsf{costpolicy}
158         defines whether the billing operation is to be performed at the moment
159         a billing event has arrived, while the \textsf{complex} attribute defines
160         whether a resource can have many instances per user.
161
162     \item[Pricelists] assign a price tag to each resource, within a timeframe.
163     
164     \item[Algorithms] specify the way the billing operation is done in response
165         to a billing event. The simplest (and default) way is to multiply the 
166         billable quantity with the applicable price. To enable more complex billing
167         scenarios, the Aquarium DSL supports a simple imperative language with
168         a number of implicit variables (e.g. \texttt{price, volume, date}) 
169         that enable administrators to specify, e.g. billing algorithms that
170         scale with billable volume. Similarily to pricelists, algorithms
171         have an applicability timeframe attached to them.
172
173     \item[Crediplans] define a number of credits to give to users and a repetition
174         period.
175
176     \item[Agreements] assign a name to algorithm, pricelist and creditplan triplets,
177         which is then assigned to each user.
178
179 \end{description}
180
181
182 \begin{figure}
183 \lstset{language=ruby, basicstyle=\footnotesize,
184 stringstyle=\ttfamily, 
185 flexiblecolumns=true, aboveskip=-0.9em, belowskip=0em, lineskip=0em}
186
187 \begin{lstlisting}
188 resources:
189   - resource:
190     name: bandwidthup
191     unit: MB/hr
192     complex: false
193     costpolicy: continuous
194 pricelists:
195   - pricelist: 
196     name: default
197     bandwidthup: 0.01
198     effective:
199       from: 0
200   - pricelist: 
201     name: everyTue2
202     overrides: default
203     bandwidthup: 0.1
204     effective:
205       repeat:
206       - start: "00 02 * * Tue"
207         end:   "00 02 * * Wed"
208       from: 1326041177 #Sun, 8 Jan 2012 18:46:27 EET
209 algorithms:
210   - algorithm:
211     name: default
212     bandwidthup: $price times $volume
213     effective:
214       from: 0
215 agreements:
216   - agreement:
217     name: scaledbandwidth
218     pricelist: everyTue2
219     algorithm:
220       bandwidthup: |
221         if $volume gt 15 then
222           $volume times $price
223         elsif $volume gt 15 and volume lt 30 then
224           $volume times $price times 1.2
225         else
226           $volume times price times 1.4
227         end
228 \end{lstlisting}
229
230 \caption{A simple billing policy definition.} 
231 \label{fig:dsl}
232 \end{figure}
233
234 In Figure~\ref{fig:dsl}, we present the definition of a simple (albeit valid) 
235 policy. The policy parsing is done top down, so the order of definition 
236 is important. The definition starts with a resource, whose name is then
237 re-used in order to attach a pricelist and a price calculation algorith to it.
238 In the case of pricelists, we present an example of \emph{temporal overloading};
239 the \texttt{everyTue2} pricelist overrides the default one, but only for 
240 all repeating time frames between every Tuesday at 02:00 and Wednesday at
241 02:00, starting from the timestamp indicated at the \texttt{from} field. Another
242 example of overloading is presented at the definition of the agreement, which
243 overloads the default algorithm definition using the imperative part of the
244 Aquarium {\sc dsl} to provide a scaling charge algorithm.
245
246 \subsection{Billing}
247
248 As common to most similar systems, billing in Aquarium is the application of
249 a billing contract to an incoming billing event in order to produce an 
250 entry for the user's wallet. However, in stark contrast to most other systems,
251 which rely on database transactions in order to securely modify the user's
252 balance, Aquarium performs account updates asynchronously and concurrently
253 for all known users.
254
255 Billing events are obtained by a connection to a reliable message queue.
256 The billing event format depends on the 
257 The actual format of the event is presented in Figure~\ref{fig:resevt}.
258
259 \begin{figure}
260 \lstset{language=C, basicstyle=\footnotesize,
261 stringstyle=\ttfamily, 
262 flexiblecolumns=true, aboveskip=-0.9em, belowskip=0em, lineskip=0em}
263
264 \begin{lstlisting}
265 {
266   "id":"4b3288b57e5c1b08a67147c495e54a68655fdab8",
267   "occured":1314829876295,
268   "userId":31,
269   "cliendId":3,
270   "resource":"vmtime",
271   "eventVersion":1,
272   "value": 1,
273   "details":{
274     "vmid":"3300",
275     "action": "on"
276   }
277 }
278 \end{lstlisting}
279 \caption{A billing event example} 
280 \label{fig:resevt}
281
282 \end{figure}
283
284 \subsection{Implementation Experience}
285
286 One of the topics of debate while designing Aquarium was the choice of
287 programming platform to use. With all user facing systems in the Okeanos cloud
288 being developed in Python and the initial Aquarium designers being beginner
289 Scala users (but experts in Java), the choice certainly involved risk that
290 management was initially reluctant to take. However, by breaking down the
291 requirements and considering the various safeguards that the software would
292 need to employ in order to satisfy them, it became clear that a
293 typesafe language was a hard requirement. Of the platforms examined, the {\sc
294 jvm} had the richest collection of ready made components; the Akka library was
295 particularly enticing for its scalability and distribution possibilities it
296 offered.
297
298 The choice of Scala at the moment was a high risk/high gain bet for GRNet.
299 However, the development team's experience has been generally positive.  Scala
300 as a language was an enabling factor; case classes permitted the expression of
301 data models, including the configuration {\sc dsl}, that could be easily be
302 serialized or read back from wire formats while also promoting immutability
303 through the use of the \texttt{copy()} constructor.  The very active use of
304 immutability allowed us to write strict, yet simple and concise unit tests, as
305 the number of cases to be examined was generally low. The
306 \textsf{Maybe}\footnote{\textsf{Maybe} works like \textsf{Option}, but it has
307 an extra possible state (\textsf{Failed}), which allows exceptions to be
308 encapsulated in the return type of a function, and then retrieved and accounted
309 for in a pattern matching operation with no side effects. More at
310 \url{https://github.com/loverdos/Maybe}} monad, developed by the second author,
311 enabled side-effect free development of data processing functions, even in cases
312 where exceptions were the only way to go. Java interoperability was excellent,
313 while thin Scala wrappers around existing Java libraries enabled higher
314 productivity and use of Scala idioms in conjunction with Java code.
315
316 Despite the above, the experience was not as smooth as initially expected. The
317 most prominent problem we encountered was that of missing documentation. The
318 Akka library documentation, extensive as is, only scratches the surface.
319 Several other libraries we use, for example Spray for {\sc rest} handling, have
320 non-existent documentation. The Java platform, and .Net that followed, has
321 shown that thorough and precise documentation are key to adoption, and we
322 expected a similar quality level. Related is the problem of shared community
323 wisdom; as most developers know, a search for any programming problem will
324 reveal several straightforward Java or scripting language sources. The
325 situation with Scala is usually the opposite; the expressive power of the
326 language makes it the current language of choice for treating esoteric
327 functional programming concepts, while simple topics are often neglected. Scala
328 has several libraries of algebraic datatypes but no {\sc yaml} parser. As Scala
329 gains mainstream adoption, we hope that such problems will fade.
330
331 From a software engineering point of view, the current state of the project was
332 reached using about 6 person months of effort, 2 of which were devoted to
333 requirements elicitation, prototype building and familiarizing with the
334 language. The source code currently consists of 5.000 lines of executable
335 statements (including about 1.000 lines of tests), divided in about 10
336 packages. The system is built using both {\sc sbt} and Maven. 
337
338 \section{Performance}
339
340 To evaluate the performance and scalability of Aquarium, we performed two
341 experiments: The first one is a micro-benchmark that measures the time required
342 for the basic processing operation performed by Aquarium, which is billing for
343 increasing number of messages. The second one demonstrates Aquarium's
344 scalability on a single node with respect to the number of users.  In both
345 cases, Aquarium was run on a MacBookPro featuring a quad core 2.33{\sc g}hz
346 Intel i7 processor and 8{\sc gb} of {\sc ram}. We selected Rabbit{\sc mq} and
347 Mongo{\sc db} as the queue and database servers, both of which were run on a
348 virtualised 4 core with 4{\sc gb} {\sc ram} Debian Linux server. Both systems
349 were run using current versions at the time of benchmarking (2.7.1 for
350 Rabbit{\sc mq} and 2.6 for Mongo{\sc db}).  The two systems were connected with
351 a full duplex 100Mbps connection.  No particular optimization was performed on
352 either back-end system, nor to the {\sc jvm} that run Aquarium. 
353
354 To simulate a realistic deployment, Aquarium was configured, using the policy
355 {\sc dsl} to handle billing events for 4 types of resources, using 3 overloaded
356 pricelists, 2 overloaded algorithms, all of which were combined to 10 different
357 agreements, which were randomly (uniformly) assigned to users. To drive the
358 benchmarks, we used a synthetic load generator that worked in two stages: it
359 first created a configurable number of users and then produced billing events
360 that 
361
362
363 The measurements above were done on the first working version of the
364 Aquarium deployment. They present 
365
366 \section{Related Work}
367
368 \section{Conclusions and Future Work}
369 In this paper, we presented Aquarium, a high-performance, generic billing 
370 system, currently tuned for cloud applications. We presented the requirements
371 that underpinned its design, outlined the architectural decisions made
372 and analysed its implementation and performance.
373
374 Scala has been an enabling factor for the implementation of Aquarium, both
375 at the system prototyping phase and during actual development. 
376
377 Aquarium is still under development, with a first stable version 
378 being planned for early 2012. 
379
380 Aquarium is available under an open source license at 
381 \url{https://code.grnet.gr/projects/aquarium}.
382
383 \bibliographystyle{abbrvnat}
384 \bibliography{aquarium}
385
386 \end{document}