Caching Willem Visser RW334. Overview AppEngine Datastore No Caching Naïve Caching Caching invalidation Cache updating Memcached Beyond your code.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

The creation of "Yaolan.com" A Site for Pre-natal and Parenting Education in Chinese by James Caldwell DAE Interactive Marketing a Web Connection Company.
Executional Architecture
CHAPTER 3 MORE ON FORM HANDLING INCLUDING MULTIPLE FILES WRITING FUNCTIONS.
My first computer: The Apple ][ It wanted to be programmed.
CHAPTER 15 WEBPAGE OPTIMIZATION. LEARNING OBJECTIVES How to test your web-page performance How browser and server interactions impact performance What.
Exadata Distinctives Brown Bag New features for tuning Oracle database applications.
Case Study - Amazon. Amazon r Amazon has many Data Centers r Hundreds of services r Thousands of commodity machines r Millions of customers at peak times.
1.  Understanding about How to Working with Server Side Scripting using PHP Framework (CodeIgniter) 2.
Lucene Part3‏. Lucene High Level Infrastructure When you look at building your search solution, you often find that the process is split into two main.
Turners SharePoint Web Site How we did it. 2 Page Anatomy Custom Search Web Part Custom Search Web Part Data Form Web Parts Content Query Web Part HTML.
Toolbox Mirror -Overview Effective Distributed Learning.
Analysis and Performance Information Systems 337 Prof. Harry Plantinga.
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos – A. Pavlo How to Scale a Database System.
Service Broker Lesson 11. Skills Matrix Service Broker Service Broker, provides a solution to common problems with message delivery and consistency that.
Google AppEngine. Google App Engine enables you to build and host web apps on the same systems that power Google applications. App Engine offers fast.
NovaBACKUP 10 xSP Technical Training By: Nathan Fouarge
How WebMD Maintains Operational Flexibility with NoSQL Rajeev Borborah, Sr. Director, Engineering Matt Wilson – Director, Production Engineering – Consumer.
1 3 Web Proxies Web Protocols and Practice. 2 Topics Web Protocols and Practice WEB PROXIES  Web Proxy Definition  Three of the Most Common Intermediaries.
Web Caching: Replication on the World Wide Web Jonathan Bulava CSC8530 – Distributed Systems Dr. Paul Schragger.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Finding cacheable areas in your Web Site using Python and Selenium David Elfi Intel.
Cloud computing lectures: Programming with Google App Engine Keke Chen.
Sistem Jaringan dan Komunikasi Data #9. DNS The Internet Directory Service  the Domain Name Service (DNS) provides mapping between host name & IP address.
The Confident Researcher: Google Away (Module 2) The Confident Researcher: Google Away 2.
Computer Measurement Group, India Optimal Design Principles for better Performance of Next generation Systems Balachandar Gurusamy,
Meet with the AppEngine Márk Gergely eu.edge. What is AppEngine? It’s a tool, that lets you run your web applications on Google's infrastructure. –Google's.
Ideas to Improve SharePoint Usage 4. What are these 4 Ideas? 1. 7 Steps to check SharePoint Health 2. Avoid common Deployment Mistakes 3. Analyze SharePoint.
Overview of Cloud Computing Sven Rosvall ACCU
Data Structures & Algorithms and The Internet: A different way of thinking.
Architecture Rajesh. Components of Database Engine.
Web Caching By Neeraj Agrawal. Caching Caching is widely used for improving performance in many context( e.g processor caches in hardware, buffer pool.
IMDGs An essential part of your architecture. About me
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Triggers A Quick Reference and Summary BIT 275. Triggers SQL code permits you to access only one table for an INSERT, UPDATE, or DELETE statement. The.
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
Distributed Backup And Disaster Recovery for AFS A work in progress Steve Simmons Dan Hyde University.
® IBM Software Group © 2007 IBM Corporation Best Practices for Session Management
BIT 286: Web Applications Lecture 10 : Thursday, February 5, 2015 ASP.Net Form Submission.
Google App Engine Data Store ae-10-datastore
1 Chapter Overview Defining Operators Creating Jobs Configuring Alerts Creating a Database Maintenance Plan Creating Multiserver Jobs.
Google App Engine MemCache ae-09-session
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
DataFlow Diagram – Level 0
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
WebObjects Matt Aguirre Lally Singh. What Is It? A Java based development platform specifically designed for database-backed web applications.
Roy Ernest Database Administrator Pinnacle Sports Worldwide
Barnett Trzcinski September 13, Overview Stores a To-Do List Task, Due Date, Completed Persistent on Server Google App Engine.
1 DIG 3134 Lecture 6: Maintaining State Michael Moshell University of Central Florida Media Software Design.
ITM © Port,Kazman 1 ITM 352 Cookies. ITM © Port,Kazman 2 Problem… r How do you identify a particular user when they visit your site (or any.
30 Copyright © 2009, Oracle. All rights reserved. Using Oracle Business Intelligence Delivers.
PHP Form Processing * referenced from
CS2021- Week 10 – Models and Views Web Development Model, Views, Controller Templates Databases.
Module 6: Administering Reporting Services. Overview Server Administration Performance and Reliability Monitoring Database Administration Security Administration.
Intro Web Applications Andrew Benson – ScottyLabs – CrashCourse F14.
COOKIES AND SESSIONS.
Apache Solr Dima Ionut Daniel. Contents What is Apache Solr? Architecture Features Core Solr Concepts Configuration Conclusions Bibliography.
Web Cache. What is Cache? Cache is the storing of data temporarily to improve performance. Cache exist in a variety of areas such as your CPU, Hard Disk.
MICROSOFT AJAX CDN (CONTENT DELIVERY NETWORK) Make Your ASP.NET site faster to retrieve.
CACHING TO IMPROVE PERFORMANCE
Google App Engine Mano Marks Developer Advocate. Problems building web applications Why Google App Engine? The App Engine Components What’s Next Questions?
Fundamentals of Web DevelopmentRandy Connolly and Ricardo HoarFundamentals of Web DevelopmentRandy Connolly and Ricardo Hoar Fundamentals of Web DevelopmentRandy.
Managing State Chapter 13.
Introduction to CodeIgniter (CI)
Web Caching? Web Caching:.
Edge computing (1) Content Distribution Networks
Fundamentals of Databases
Lecture 34: Testing II April 24, 2017 Selenium testing script 7/7/2019
Presentation transcript:

Caching Willem Visser RW334

Overview AppEngine Datastore No Caching Naïve Caching Caching invalidation Cache updating Memcached Beyond your code

AppEngine Python Datastore Datastore – db Old and will be going away at some point – ndb ( python/ndb/) New and supports some cool features from google.appengine.ext import ndb class Stuff(ndb.Model): title = ndb.StringProperty(required = True) content = ndb.StringProperty(required = True) date = ndb.DateTimeProperty(auto_now_add=True)

NDB Python class defines the model Each entity has a key, which in turn has a parent, up to the root that has no parent – Entities in this chain is in the same group – Entities in the same group has consistency guarantees stuff_title = self.request.get(’stuff_name') stuff = Stuff(parent=ndb.Key(”Things", stuff_title or "*notitle*"), content = self.request.get('content')) stuff.put()

NDB (2) Queries and Indexes There are very many ways to query Complex queries might need complex indexes – NDB creates simple indexes automatically – Complex ones can be defined in index.yaml GQL is similar to SQL Only gets executed when accessed stuff = ndb.GqlQuery("SELECT * FROM Stuff ORDER BY created DESC LIMIT 10") stuff = list(stuff)

No Caching Every db_read hits the database Database reads tend not to be the fastest thing This can be very inefficient therefore

Example No Caching def top_stuff(): stuff = db.GqlQuery("SELECT * FROM Stuff ORDER BY created DESC LIMIT 10") return list(stuff) class MainPage(Handler): def render_front(self, …): stuff = top_stuff() self.render("front.html", stuff = stuff, …) def get(self): self.render_front() def post(self): title = … data = … a = Stuff(title = title, data = data) a.put() self.redirect("/")

Naïve Caching This will do wonders for performance If the cache is too large it might start to slow down a bit Above the db_read is avoided but rendering HTML could also be cached if that takes a lot of time If not cache[request]: cache[request] = db_read(); return cache[request]

Example No Caching def top_stuff(): stuff = db.GqlQuery("SELECT * FROM Stuff ORDER BY created DESC LIMIT 10") return list(stuff) class MainPage(Handler): def render_front(self, …): stuff = top_stuff() self.render("front.html", stuff = stuff, …) def get(self): self.render_front() def post(self): title = … data = … a = Stuff(title = title, data = data) a.put() self.redirect("/")

Example CACHE = {} def top_stuff(): key = 'top' stuff = CACHE[key] if not stuff: logging.error("DB QUERY") stuff = db.GqlQuery("SELECT * FROM Stuff ORDER BY created DESC LIMIT 10") stuff = list(stuff) CACHE[key] = stuff return stuff class MainPage(Handler): def render_front(self, …): stuff = top_stuff() self.render("front.html", stuff = stuff, …) def get(self): self.render_front() def post(self): title = … data = … a = Stuff(title = title, data = data) a.put() self.redirect("/")

New data? Will the previous solution work? What happens if you add new data – Added to the DB and then redirect to / – Render_front calls top_stuff – However cache is hit and we get the old data Cache must be invalidated when new data comes

Clear Cache CACHE = {} def top_stuff(): … class MainPage(Handler): def render_front(self, …): stuff = top_stuff() self.render("front.html", stuff = stuff, …) def get(self): self.render_front() def post(self): title = … data = … a = Stuff(title = title, data = data) a.put() CACHE.clear() self.redirect("/")

Cache Stampede If one user writes new data – Cache gets cleared Now lots of users all access the site at the same time – All of them doing db_reads since the cache is empty This hammers the DB and slows everybody down – Depending on settings the DB might also block or even crash Without any caching this could also happen

Cache Refresh def top_stuff(update = False): key = 'top' stuff = CACHE[key] if (not stuff or update): logging.error("DB QUERY") stuff = db.GqlQuery("SELECT * FROM Stuff ORDER BY created DESC LIMIT 10") stuff = list(stuff) CACHE[key] = stuff return stuff class MainPage(Handler): def render_front(self, …): stuff = top_stuff() self.render("front.html", stuff = stuff, …) def get(self): self.render_front() def post(self): title = … data = … a = Stuff(title = title, data = data) a.put() top_stuff(True) self.redirect("/")

Cache Update Most aggressive solution – No DB reads! On new data, store in the DB and also directly into the cache, without reading from the DB The DB is just a backup storage now for in case something goes wrong, such as a server going down

Cache Comparisons Cache Approach DB_Read on page view DB_Read on submit Wrong results NoneAlwaysNone NaïveCache missNoneYes RefreshSeldomOnce UpdateNone

Sharing a Cache If we have more than one server Do we have a cache for each server, or, share a cache amongst servers? Cache for each server can have suboptimal behavior if they are not synchronized – Data might be in the cache on server 1 and not server 2, for example Good solution is to use a very fast shared cache

Memcached See Very fast, in-memory, key-value store Caching technology behind very many websites Support for it within AppEngine from google.appengine.api import memcache … def top_stuff(update = False): key = 'top' stuff = memcache.get(key) if (update) or (not stuff): stuff = db.GqlQuery("SELECT * FROM Art ORDER BY created DESC LIMIT 10”) stuff = list(stuff) memcache.set(key,stuff) return stuff

NDB and Caching Two Caches controlled by policies – In context (microseconds) Only current http request Writes to datastore and cache, reads first checks cache – Memcache (milliseconds) All nontransactional context caches here All contexts share same memcache Within a transaction memcache is not used Can be configured by policies – Some standard ones available

More Caching Some caches also live outside the developers immediate control Browser Cache – Single user Proxy Cache – Multiple users Gateway Cache – Distributed by Content Delivery Networks HTTP 1.1 supports “Cache-Control” header – Allows developers to control how things are cached