Transactional Consistency and Automatic Management in an Application Data Cache Dan R

Transactional Consistency and Automatic Management in an Application Data Cache Dan R

Transactional Consistency and Automatic Management in an Application Data Cache Dan R. K. Ports Austin T. Clements Irene Zhang Samuel Madden Barbara Liskov MIT CSAIL [email protected] Abstract They are deployed extensively by well-known web ap- plications like LiveJournal, Facebook, and MediaWiki. Distributed in-memory application data caches like mem- These caches store arbitrary application-generated data in cached are a popular solution for scaling database-driven a lightweight, distributed in-memory cache. This flexibil- web sites. These systems are easy to add to existing de- ity allows an application-level cache to act as a database ployments, and increase performance significantly by re- query cache, or to act as a web cache and cache entire ducing load on both the database and application servers. web pages. But increasingly complex application logic Unfortunately, such caches do not integrate well with and more personalized web content has made it more use- the database or the application. They cannot maintain ful to cache the result of application computations that transactional consistency across the entire system, vio- depend on database queries. Such caching is useful be- lating the isolation properties of the underlying database. cause it averts costly post-processing of database records, They leave the application responsible for locating data such as converting them to an internal representation, or in the cache and keeping it up to date, a frequent source generating partial HTML output. It also allows common of application complexity and programming errors. content to be cached separately from customized con- Addressing both of these problems, we introduce a tent, so that it can be shared between users. For example, transactional cache, TxCache, with a simple program- MediaWiki uses memcached to store items ranging from ming model. TxCache ensures that any data seen within translations of interface messages to parse trees of wiki a transaction, whether it comes from the cache or the pages to the generated HTML for the site’s sidebar. database, reflects a slightly stale but consistent snap- Existing caches like memcached present two chal- shot of the database. TxCache makes it easy to add lenges for developers, which we address in this paper. caching to an application by simply designating func- First, they do not ensure transactional consistency with tions as cacheable; it automatically caches their results, the rest of the system state. That is, there is no way to and invalidates the cached data as the underlying database ensure that accesses to the cache and the database re- changes. Our experiments found that adding TxCache turn values that reflect a view of the entire system at a increased the throughput of a web application by up to single point in time. While the backing database goes 5:2×, only slightly less than a non-transactional cache, to great length to ensure that all queries performed in a showing that consistency does not have to come at the transaction reflect a consistent view of the database, i.e. it price of performance. can ensure serializable isolation, it is nearly impossible to maintain these consistency guarantees while using a 1 Overview cache that operates on application objects and has no Today’s web applications are used by millions of users notion of database transactions. The resulting anomalies and demand implementations that scale accordingly. A can cause incorrect information to be exposed to the user, typical system includes application logic (often imple- or require more complex application logic because the mented in web servers) and an underlying database that application must be able to cope with violated invariants. stores persistent state, either of which can become a bot- Second, they offer only a GET/PUT interface, plac- tleneck [1]. Increasing database capacity is typically a ing full responsibility for explicitly managing the cache difficult and costly proposition, requiring careful parti- with the application. Applications must assign names to tioning or the use of distributed databases. Application cached values, perform lookups, and keep the cache up server bottlenecks can be easier to address by adding to date. This has been a common source of programming more nodes, but this also quickly becomes expensive. errors in applications that use memcached. In particular, Application-level data caches, such as mem- applications must explicitly invalidate cached data when cached [24], Velocity/AppFabric [34] and NCache [25], the database changes. This is often difficult; identifying are a popular solution to server and database bottlenecks. every cached application computation whose value may 1 have been changed requires global reasoning about the Cache Database application. We address both problems in our transactional cache, TxCache. TxCache provides the following features: • transactional consistency: all data seen by the appli- cation reflects a consistent snapshot of the database, whether the data comes from cached application- level objects or directly from database queries. TxCache Library • access to slightly stale but nevertheless consistent Application snapshots for applications that can tolerate stale data, improving cache utilization. • a simple programming model, where applications simply designate functions as cacheable. The Tx- Data center Cache library then handles inserting the result of the function into the cache, retrieving that result the next time the function is called with the same arguments, and invalidating cached results when they change. To achieve these goals, TxCache introduces the follow- Figure 1: Key components in a TxCache deployment. ing noteworthy mechanisms: The system consists of a single database, a set of cache nodes, and a set of application servers. TxCache also • a protocol for ensuring that transactions see only introduces an application library, which handles all inter- consistent cached data, using minor database modi- actions with the cache server. fications to compute the validity times of database queries, and attaching them to cache objects. Figure1: a cache and an application-side cache library, • a lazy timestamp selection algorithm that assigns a as well as some minor modifications to the database transaction to a timestamp in the recent past based server. The cache is partitioned across a set of cache on the availability of cached data. nodes, which may run on dedicated hardware or share • an automatic invalidation system that tracks each ob- it with other servers. The application never interacts ject’s database dependencies using dual-granularity with the cache servers; the TxCache library transparently invalidation tags, and produces notifications if they translates an application’s cacheable functions into cache change. accesses. We ported the RUBiS auction website prototype and MediaWiki, a popular web application, to use TxCache, 2.1 Programming Model and evaluated it using the RUBiS benchmark [2]. Our Our goal is to make it easy to incorporate caching into a cache improved peak throughput by 1:5 – 5:2× depend- new or existing application. Towards this end, TxCache ing on the cache size and staleness limit, an improvement provides an application library with a simple program- oonly slightly below that of a non-transactional cache. ming model, shown in Figure2, based on cacheable func- The next section presents the programming model and tions. Applications developers can cache computations consistency semantics. Section3 sketches the structure simply by designating functions to be cached. of the system, and Sections4–6 describe each component Programs group their operations into transactions. Tx- in detail. Section7 describes our experiences porting ap- Cache requires applications to specify whether their trans- plications to TxCache, Section8 presents a performance actions are read-only or read/write by using either the evaluation, and Section9 reviews the related work. BEGIN-RO or BEGIN-RW function. Transactions are ended by calling COMMIT or ABORT. Within a transac- 2 System and Programming Model tion block, TxCache ensures that, regardless of whether TxCache is designed for systems consisting of one or the application gets its data from the database or the more application servers that interact with a database cache, it sees a view consistent with the state of the server. These application servers could be web servers database at a single point in time. running embedded scripts (e.g. with mod php), or dedi- Within a transaction, operations can be grouped into cated application servers, as with Sun’s Enterprise Java cacheable functions. These are actual functions in the pro- Beans. The database server is a standard relational gram’s code, annotated to indicate that their results can database; for simplicity, we assume the application uses be cached. A cacheable function can consist of database a single database to store all of its persistent state. queries and computation, and can also make calls to other TxCache introduces two new components, as shown in cacheable functions. To be suitable for caching, functions 2 • BEGIN-RO(staleness) : Begin a read-only transac- database. Adding explicit invalidations requires global tion. The transaction sees a consistent snapshot reasoning about the application, hindering modularity: from within the past staleness seconds. adding caching for an object requires knowing every • BEGIN-RW() : Begin a read/write transaction. place it could possibly change. This, too, has been

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    14 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us