DEUTSCH-FRANZÖSISCHE SOMMERUNIVERSITÄT FÜR NACHWUCHSWISSENSCHAFTLER 2011 UNIVERSITÉ D’ÉTÉ FRANCO-ALLEMANDE POUR JEUNES CHERCHEURS 2011 CLOUD COMPUTING : DÉFIS ET OPPORTUNITÉS CLOUD COMPUTING : HERAUSFORDERUNGEN UND MÖGLICHKEITEN 17.7. – 22.7. 2011 Windows Azure as a Platform as a Service (PaaS) Jared Jackson Microsoft Research
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Source International Ice Cream Association (makeicecreamcom)
Windows Azure Overview
4
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
5
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
Web Role Instances Worker Role
Instances
Azure Storage Blob Queue Table
SQL Azure
Windows Azure Application Model
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Before we begin ndash Some Results
Vanilla 23
Chocolate 13
Strawberry 10
Coffee 3
Banana 3
Pistachio 7
Mango 3
Amarena 3
Malaga 3
Cherry 3
Tiramisu 3
Stratiatella 10
Cheescake 3
Cookies and Cream
3
Walnut 3
Cinamon 3
Favorite Ice Cream
Vanilla 33
Chocolate 11
Strawberry 5
Coffee 2
Cherry 2
Cookies and Cream 4
Butter Pecan 7
Neapolitan 4
Chocolate Chip 4
Other 29
Ice Cream Consumption
Source International Ice Cream Association (makeicecreamcom)
Windows Azure Overview
4
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
5
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
Web Role Instances Worker Role
Instances
Azure Storage Blob Queue Table
SQL Azure
Windows Azure Application Model
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Overview
4
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
5
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
Web Role Instances Worker Role
Instances
Azure Storage Blob Queue Table
SQL Azure
Windows Azure Application Model
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
4
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
5
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
Web Role Instances Worker Role
Instances
Azure Storage Blob Queue Table
SQL Azure
Windows Azure Application Model
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
5
Web Application Model Comparison
Machines Running IIS ASPNET
Machines Running Windows Services
Machines Running SQL Server
Ad Hoc Application Model
Web Role Instances Worker Role
Instances
Azure Storage Blob Queue Table
SQL Azure
Windows Azure Application Model
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components Fabric Controller
bull Manages hardware and virtual machines for service
Compute bull Web Roles
bull Web application front end
bull Worker Roles bull Utility compute
bull VM Roles bull Custom compute role bull You own and customize the VM
Storage bull Blobs
bull Binary objects
bull Tables bull Entity storage
bull Queues bull Role coordination
bull SQL Azure bull SQL in the cloud
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components Fabric Controller
bull Think of it as an automated IT department
bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor
bull Allows for automated management of virtual machines
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components Fabric Controller
bull Think of it as an automated IT department bull ldquoCloud Layerrdquo on top of
bull Windows Server 2008
bull A custom version of Hyper-V called the Windows Azure Hypervisor bull Allows for automated management of virtual machines
bull Itrsquos job is to provision deploy monitor and maintain applications in data centers
bull Applications have a ldquoshaperdquo and a ldquoconfigurationrdquo bull The configuration definition describes the shape of a service
bull Role types
bull Role VM sizes
bull External and internal endpoints
bull Local storage
bull The configuration settings configures a service bull Instance count
bull Storage keys
bull Application-specific settings
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components Fabric Controller
bull Manages ldquonodesrdquo and ldquoedgesrdquo in the ldquofabricrdquo (the hardware) bull Power-on automation devices bull Routers Switches bull Hardware load balancers bull Physical servers bull Virtual servers
bull State transitions bull Current State bull Goal State bull Does what is needed to reach and maintain the goal state
bull Itrsquos a perfect IT employee bull Never sleeps bull Doesnrsquot ever ask for raise bull Always does what you tell it to do in configuration definition and settings
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Creating a New Project
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Compute
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components ndash Compute Web Roles
Web Front End
bull Cloud web server
bull Web pages
bull Web services
You can create the following types
bull ASPNET web roles
bull ASPNET MVC 2 web roles
bull WCF service web roles
bull Worker roles
bull CGI-based web roles
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components ndash Compute Worker Roles
bull Utility compute
bull Windows Server 2008
bull Background processing
bull Each role can define an amount of local storage
bull Protected space on the local drive considered volatile storage
bull May communicate with outside services
bull Azure Storage
bull SQL Azure
bull Other Web services
bull Can expose external and internal endpoints
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Suggested Application Model Using queues for reliable messaging
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Scalable Fault Tolerant Applications
Queues are the application glue bull Decouple parts of application easier to scale independently bull Resource allocation different priority queues and backend servers bull Mask faults in worker roles (reliable messaging)
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Components ndash Compute VM Roles
bull Customized Role
bull You own the box
bull How it works
bull Download ldquoGuest OSrdquo to Server 2008 Hyper-V
bull Customize the OS as you need to
bull Upload the differences VHD
bull Azure runs your VM role using
bull Base OS
bull Differences VHD
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Application Hosting
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
lsquoGrokkingrsquo the service model
bull Imagine white-boarding out your service architecture with boxes for nodes and arrows describing how they communicate
bull The service model is the same diagram written down in a declarative format
bull You give the Fabric the service model and the binaries that go with each of those nodes
bull The Fabric can provision deploy and manage that diagram for you
bull Find hardware home
bull Copy and launch your app binaries
bull Monitor your app and the hardware
bull In case of failure take action Perhaps even relocate your app
bull At all times the lsquodiagramrsquo stays whole
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Automated Service Management Provide code + service model
bull Platform identifies and allocates resources deploys the service manages service health
bull Configuration is handled by two files
ServiceDefinitioncsdef
ServiceConfigurationcscfg
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Service Definition
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Service Configuration
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
GUI
Double click on Role Name in Azure Project
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Deploying to the cloud
bull We can deploy from the portal or from script
bull VS builds two files
bull Encrypted package of your code
bull Your config file
bull You must create an Azure account then a service and then you deploy your code
bull Can take up to 20 minutes
bull (which is better than six months)
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Service Management API
bullREST based API to manage your services
bullX509-certs for authentication
bullLets you create delete change upgrade swaphellip
bullLots of community and MSFT-built tools around the API
- Easy to roll your own
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
The Secret Sauce ndash The Fabric
The Fabric is the lsquobrainrsquo behind Windows Azure
1 Process service model
1 Determine resource requirements
2 Create role images
2 Allocate resources
3 Prepare nodes
1 Place role images on nodes
2 Configure settings
3 Start roles
4 Configure load balancers
5 Maintain service health
1 If role fails restart the role based on policy
2 If node fails migrate the role based on policy
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Storage
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Durable Storage At Massive Scale
Blob
- Massive files eg videos logs
Drive
- Use standard file system APIs
Tables - Non-relational but with few scale limits
- Use SQL Azure for relational data
Queues
- Facilitate loosely-coupled reliable systems
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Blob Features and Functions
bull Store Large Objects (up to 1TB in size)
bull Can be served through Windows Azure CDN service
bull Standard REST Interface
bull PutBlob
bull Inserts a new blob overwrites the existing blob
bull GetBlob
bull Get whole blob or a specific range
bull DeleteBlob
bull CopyBlob
bull SnapshotBlob
bull LeaseBlob
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Two Types of Blobs Under the Hood
bull Block Blob
bull Targeted at streaming workloads
bull Each blob consists of a sequence of blocks bull Each block is identified by a Block ID
bull Size limit 200GB per blob
bull Page Blob
bull Targeted at random readwrite workloads
bull Each blob consists of an array of pages bull Each page is identified by its offset
from the start of the blob
bull Size limit 1TB per blob
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Drive
bull Provides a durable NTFS volume for Windows Azure applications to use
bull Use existing NTFS APIs to access a durable drive bull Durability and survival of data on application failover
bull Enables migrating existing NTFS applications to the cloud
bull A Windows Azure Drive is a Page Blob
bull Example mount Page Blob as X bull httpltaccountnamegtblobcorewindowsnetltcontainernamegtltblobnamegt
bull All writes to drive are made durable to the Page Blob bull Drive made durable through standard Page Blob replication
bull Drive persists even when not mounted as a Page Blob
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Tables
bull Provides Structured Storage
bull Massively Scalable Tables bull Billions of entities (rows) and TBs of data
bull Can use thousands of servers as traffic grows
bull Highly Available amp Durable bull Data is replicated several times
bull Familiar and Easy to use API
bull WCF Data Services and OData bull NET classes and LINQ
bull REST ndash with any platform or language
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Queues
bull Queue are performance efficient highly available and provide reliable message delivery
bull Simple asynchronous work dispatch
bull Programming semantics ensure that a message can be processed at least once
bull Access is provided via REST
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Storage Partitioning
Understanding partitioning is key to understanding performance
bull Different for each data type (blobs entities queues) Every data object has a partition key
bull A partition can be served by a single server
bull System load balances partitions based on traffic pattern
bull Controls entity locality Partition key is unit of scale
bull Load balancing can take a few minutes to kick in
bull Can take a couple of seconds for partition to be available on a different server
System load balances
bull Use exponential backoff on ldquoServer Busyrdquo
bull Our system load balances to meet your traffic needs
bull Single partition limits have been reached Server Busy
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Partition Keys In Each Abstraction
bull Entities w same PartitionKey value served from same partition Entities ndash TableName + PartitionKey
PartitionKey (CustomerId) RowKey (RowKind)
Name CreditCardNumber OrderTotal
1 Customer-John Smith John Smith xxxx-xxxx-xxxx-xxxx
1 Order ndash 1 $3512
2 Customer-Bill Johnson Bill Johnson xxxx-xxxx-xxxx-xxxx
2 Order ndash 3 $1000
bull Every blob and its snapshots are in a single partition Blobs ndash Container name + Blob name
bullAll messages for a single queue belong to the same partition Messages ndash Queue Name
Container Name Blob Name
image annarborbighousejpg
image foxboroughgillettejpg
video annarborbighousejpg
Queue Message
jobs Message1
jobs Message2
workflow Message1
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Scalability Targets
Storage Account
bull Capacity ndash Up to 100 TBs
bull Transactions ndash Up to a few thousand requests per second
bull Bandwidth ndash Up to a few hundred megabytes per second
Single QueueTable Partition
bull Up to 500 transactions per second
To go above these numbers partition between multiple storage accounts and partitions
When limit is hit app will see lsquo503 server busyrsquo applications should implement exponential backoff
Single Blob Partition
bull Throughput up to 60 MBs
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
PartitionKey (Category)
RowKey (Title)
Timestamp ReleaseDate
Action Fast amp Furious hellip 2009
Action The Bourne Ultimatum hellip 2007
hellip hellip hellip hellip
Animation Open Season 2 hellip 2009
Animation The Ant Bully hellip 2006
hellip hellip hellip hellip
Comedy Office Space hellip 1999
hellip hellip hellip hellip
SciFi X-Men Origins Wolverine hellip 2009
hellip hellip hellip hellip
War Defiance hellip 2008
Partitions and Partition Ranges
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Key Selection Things to Consider
bullDistribute load as much as possible bullHot partitions can be load balanced bullPartitionKey is critical for scalability
See httpwwwmicrosoftpdccom2009SVC09 and httpazurescopecloudappnet for more information
bull Avoid frequent large scans bull Parallelize queries bull Point queries are most efficient
bullTransactions across a single partition bullTransaction semantics amp Reduce round trips
Scalability
Query Efficiency amp Speed
Entity group transactions
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Expect Continuation Tokens ndash Seriously
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 1000 rows in a response
At the end of partition range boundary
Maximum of 5 seconds to execute the query
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Tables Recap bullEfficient for frequently used queries
bullSupports batch transactions
bullDistributes load
Select PartitionKey and RowKey that help scale
Avoid ldquoAppend onlyrdquo patterns
Always Handle continuation tokens
ldquoORrdquo predicates are not optimized
Implement back-off strategy for retries
bullDistribute by using a hash etc as prefix
bullExpect continuation tokens for range queries
bullExecute the queries that form the ldquoORrdquo predicates as separate queries
bullServer busy
bullLoad balance partitions to meet traffic needs
bullLoad on single partition has exceeded the limits
WCF Data Services
bullUse a new context for each logical operation
bullAddObjectAttachTo can throw exception if entity is already being tracked
bullPoint query throws an exception if resource does not exist Use IgnoreResourceNotFoundException
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Queues Their Unique Role in Building Reliable Scalable Applications
bull Want roles that work closely together but are not bound together bull Tight coupling leads to brittleness
bull This can aid in scaling and performance
bull A queue can hold an unlimited number of messages bull Messages must be serializable as XML
bull Limited to 8KB in size
bull Commonly use the work ticket pattern
bull Why not simply use a table
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Queue Terminology
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Message Lifecycle
Queue
Msg 1
Msg 2
Msg 3
Msg 4
Worker Role
Worker Role
PutMessage
Web Role
GetMessage (Timeout) RemoveMessage
Msg 2 Msg 1
Worker Role
Msg 2
POST httpmyaccountqueuecorewindowsnetmyqueuemessages
HTTP11 200 OK Transfer-Encoding chunked Content-Type applicationxml Date Tue 09 Dec 2008 210430 GMT Server Nephos Queue Service Version 10 Microsoft-HTTPAPI20
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
6 msg1 visible 30s after Dequeue 9 msg1 visible 30s after Dequeue
3 0
1 3
1 2
1 3
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Queues Recap
bullNo need to deal with failures Make message
processing idempotent
bullInvisible messages result in out of order Do not rely on order
bullEnforce threshold on messagersquos dequeue count Use Dequeue count to remove
poison messages
bullMessages gt 8KB
bullBatch messages
bullGarbage collect orphaned blobs
bullDynamically increasereduce workers
Use blob to store message data with
reference in message
Use message count to scale
bullNo need to deal with failures
bullInvisible messages result in out of order
bullEnforce threshold on messagersquos dequeue count
bullDynamically increasereduce workers
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Windows Azure Storage Takeaways
Blobs
Drives
Tables
Queues
httpblogsmsdncomwindowsazurestorage
httpazurescopecloudappnet
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
49
A Quick Exercise
hellipThen letrsquos look at some code and some tools
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
50
Code ndash AccountInformationcs public class AccountInformation private static string storageKey = ldquotHiSiSnOtMyKeY private static string accountName = jjstore private static StorageCredentialsAccountAndKey credentials internal static StorageCredentialsAccountAndKey Credentials get if (credentials == null) credentials = new StorageCredentialsAccountAndKey(accountName storageKey) return credentials
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
51
Code ndash BlobHelpercs public class BlobHelper private static string defaultContainerName = school private CloudBlobClient client = null private CloudBlobContainer container = null private void InitContainer() if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudBlobClient() container = clientGetContainerReference(defaultContainerName) containerCreateIfNotExist() BlobContainerPermissions permissions = containerGetPermissions() permissionsPublicAccess = BlobContainerPublicAccessTypeContainer containerSetPermissions(permissions)
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
52
Code ndash BlobHelpercs
public void WriteFileToBlob(string filePath) if (client == null || container == null) InitContainer() FileInfo file = new FileInfo(filePath) CloudBlob blob = containerGetBlobReference(fileName) blobPropertiesContentType = GetContentType(fileExtension) blobUploadFile(fileFullName) Or if you want to write a string replace the last line with blobUploadText(someString) And make sure you set the content type to the appropriate MIME type (eg ldquotextplainrdquo)
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
53
Code ndash BlobHelpercs
public string GetBlobText(string blobName) if (client == null || container == null) InitContainer() CloudBlob blob = containerGetBlobReference(blobName) try return blobDownloadText() catch (Exception) The blob probably does not exist or there is no connection available return null
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
The blob is now available at httpltAccountNamegtblobcorewindowsnetltContainerNamegtltBlobNamegt Or in this case httpjjstoreblobcorewindowsnetschoolSummerSchoolAttendeestxt
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
55
Code - TableEntities using MicrosoftWindowsAzureStorageClient public class AttendeeEntity TableServiceEntity public string FirstName get set public string LastName get set public string Email get set public DateTime Birthday get set public string FavoriteIceCream get set public int YearsInPhD get set public bool Graduated get set hellip
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
57
Code ndash TableHelpercs public class TableHelper private CloudTableClient client = null private TableServiceContext context = null private DictionaryltstringAttendeeEntitygt allAttendees = null private string tableName = Attendees private CloudTableClient Client get if (client == null) client = new CloudStorageAccount(AccountInformationCredentials false)CreateCloudTableClient() return client private TableServiceContext Context get if (context == null) context = ClientGetDataServiceContext() return context
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
58
Code ndash TableHelpercs private void ReadAllAttendees() allAttendees = new Dictionaryltstring AttendeeEntitygt() CloudTableQueryltAttendeeEntitygt query = ContextCreateQueryltAttendeeEntitygt(tableName)AsTableServiceQuery() try foreach (AttendeeEntity attendee in query) allAttendees[attendeeEmail] = attendee catch (Exception) No entries in table - or other exception
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
59
Code ndash TableHelpercs public void DeleteAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return AttendeeEntity attendee = allAttendees[email] Delete from the cloud table ContextDeleteObject(attendee) ContextSaveChanges() Delete from the memory cache allAttendeesRemove(email)
60
Code ndash TableHelpercs public AttendeeEntity GetAttendee(string email) if (allAttendees == null) ReadAllAttendees() if (allAttendeesContainsKey(email)) return allAttendees[email] return null
Remember that this only works for tables (or queries on tables) that easily fit in memory This is one of many design patterns for working with tables
61
Pseudo Code ndash TableHelpercs public void UpdateAttendees(ListltAttendeeEntitygt updatedAttendees) foreach (AttendeeEntity attendee in updatedAttendees) UpdateAttendee(attendee false) ContextSaveChanges(SaveChangesOptionsBatch) public void UpdateAttendee(AttendeeEntity attendee) UpdateAttendee(attendee true) private void UpdateAttendee(AttendeeEntity attendee bool saveChanges) if (allAttendeesContainsKey(attendeeEmail)) AttendeeEntity existingAttendee = allAttendees[attendeeEmail] existingAttendeeUpdateFrom(attendee) ContextUpdateObject(existingAttendee) else ContextAddObject(tableName attendee) if (saveChanges) ContextSaveChanges()
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Thatrsquos it Now your tables are accessible using REST service calls or any cloud storage tool
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
63
Tools ndash Fiddler2
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Best Practices
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Picking the Right VM Size
bull Having the correct VM size can make a big difference in costs
bull Fundamental choice ndash larger fewer VMs vs many smaller instances
bull If you scale better than linear across cores larger VMs could save you money
bull Pretty rare to see linear scaling across 8 cores
bull More instances may provide better uptime and reliability (more failures needed to take your service down)
bull Only real right answer ndash experiment with multiple sizes and instance counts in order to measure and find what is ideal for you
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Using Your VM to the Maximum
Remember bull 1 role instance == 1 VM running Windows
bull 1 role instance = one specific task for your code
bull Yoursquore paying for the entire VM so why not use it
bull Common mistake ndash split up code into multiple roles each not using up CPU
bull Balance between using up CPU vs having free capacity in times of need
bull Multiple ways to use your CPU to the fullest
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Exploiting Concurrency
bull Spin up additional processes each with a specific task or as a unit of concurrency
bull May not be ideal if number of active processes exceeds number of cores
bull Use multithreading aggressively
bull In networking code correct usage of NT IO Completion Ports will let the kernel schedule the precise number of threads
bull In NET 4 use the Task Parallel Library
bull Data parallelism
bull Task parallelism
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Finding Good Code Neighbors
bull Typically code falls into one or more of these categories
bull Find code that is intensive with different resources to live together
bull Example distributed network caches are typically network- and memory-intensive they may be a good neighbor for storage IO-intensive code
Memory Intensive
CPU Intensive
Network IO Intensive
Storage IO Intensive
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Scaling Appropriately
bull Monitor your application and make sure yoursquore scaled appropriately (not over-scaled)
bull Spinning VMs up and down automatically is good at large scale
bull Remember that VMs take a few minutes to come up and cost ~$3 a day (give or take) to keep running
bull Being too aggressive in spinning down VMs can result in poor user experience
bull Trade-off between risk of failurepoor user experience due to not having excess capacity and the costs of having idling VMs
Performance Cost
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Storage Costs
bull Understand an applicationrsquos storage profile and how storage billing works
bull Make service choices based on your app profile
bull Eg SQL Azure has a flat fee while Windows Azure Tables charges per transaction
bull Service choice can make a big cost difference based on your app profile
bull Caching and compressing They help a lot with storage costs
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Saving Bandwidth Costs
Bandwidth costs are a huge part of any popular web apprsquos billing profile
Sending fewer things over the wire often means getting fewer things from storage
Saving bandwidth costs often lead to savings in other places
Sending fewer things means your VM has time to do other tasks
All of these tips have the side benefit of improving your web apprsquos performance and user experience
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Compressing Content
1 Gzip all output content
bull All modern browsers can decompress on the fly
bull Compared to Compress Gzip has much better compression and freedom from patented algorithms
2Tradeoff compute costs for storage size
3Minimize image sizes
bull Use Portable Network Graphics (PNGs)
bull Crush your PNGs
bull Strip needless metadata
bull Make all PNGs palette PNGs
Uncompressed
Content
Compressed
Content
Gzip
Minify JavaScript
Minify CCS
Minify Images
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Best Practices Summary
Doing lsquolessrsquo is the key to saving costs
Measure everything
Know your application profile in and out
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Research Examples in the Cloud
hellipon another set of slides
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
bull Clouds are the largest scale computer centers ever constructed and have the
potential to be important to both large and small scale science problems
bull Equally import they can increase participation in research providing needed
resources to userscommunities without ready access
bull Clouds suitable for ldquoloosely coupledrdquo data parallel applications and can
support many interesting ldquoprogramming patternsrdquo but tightly coupled low-
latency applications do not perform optimally on clouds today
bull Provide valuable fault tolerance and scalability abstractions
bull Clouds as amplifier for familiar client tools and on premise compute
bull Clouds services to support research provide considerable leverage for both
individual researchers and entire communities of researchers
Day 2 - Azure as a PaaS
Day 2 - Applications
Map Reduce on Azure
bull Elastic MapReduce on Amazon Web Services has traditionally been the only option for Map Reduce jobs in the web bull Hadoop implementation bull Hadoop has a long history and has been improved for stability bull Originally Designed for Cluster Systems
bull Microsoft Research this week is announcing a project code named Daytona for Map Reduce jobs on Azure bull Designed from the start to use cloud primitives bull Built-in fault tolerance bull REST based interface for writing your own clients
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants
Evapotranspiration (ET) is the release of water to the atmosphere by evaporation from open water bodies and transpiration or evaporation through plant membranes by plants