1. Scaling Big while Sleeping Well Josh Holmes @joshholmes josh.holmes@microsoft.com www.joshholmes.com
2. Agenda Testing the Waters What is cloud computing? What are the advantages of cloud computing? How’s Azure fit in? Diving Deep Digging into PHP/Ruby on Azure Leveraging FastCGI Leveraging Azure Storage Leveraging SQL Azure
4. Cloud-Addressable Challenges 1 1 5 Maintaining security while increasing access and transparency—within and outside the organization Infrastructure costs are fixed and ongoing, and distract from the mission of reducing business process friction 2 6 Leveraging past investments to provide future value Security, access, and transparency across the value chain: suppliers, partners, etc. 3 Many data centers at limit—real estate, capacity, cooling and power 7 Lack of a common platform 4 Matching capacity to demand
5. In House or Hosted Servers Allocated IT-capacities Load Forecast “Under-supply“ of capacities “Waste“ of capacities Fixed cost of IT-capacities IT CAPACITY Barrier for innovations ActualLoad TIME
6. Cloud Computing Load Forecast Allocated IT capacities No “under-supply“ IT CAPACITY Reduction of “over-supply“ Possible reduction of IT-capacities in case of reduced load Reduction of initial investments ActualLoad Time
7. Types of Clouds Platform (as a Service) Private (On-Premise) Infrastructure (as a Service) You manage Applications Applications Applications You manage Runtimes Runtimes Runtimes Security & Integration Security & Integration Security & Integration Managed by vendor Databases Databases Databases You manage Servers Servers Servers Managed by vendor Virtualization Virtualization Virtualization Server HW Server HW Server HW Storage Storage Storage Networking Networking Networking
8. The Microsoft Cloud ~100 Globally Distributed Data Centers Quincy, WA Chicago, IL San Antonio, TX Dublin, Ireland Generation 4 DCs
9.
10. Categories of Services Application Services Software Services Platform Services The Microsoft Cloud Infrastructure Services
11. The trick is knowing what your systems need, and how the cloud can help.
18. “Packaged” Application Big Pharmaceutical Example Hosted “Packaged” “Packaged” using cloud “Software as a Service” Buy ERP “Too costly to run this myself, but I’ve made too many customizations” CRM Email Build vs. Buy “Home Built” Application Hosted “Home Built” “Home Built” using cloud “Platform as a Service” HR System Molecule Research Build Clinical Trial Hoster Vendor On Premise Cloud
19. “Packaged” Application Big Pharmaceutical Example Hosted “Packaged” “Packaged” using cloud “Software as a Service” Buy ERP CRM “CRM and Email are commodity services – They have no customizations, and it’s cheaper for someone else to run these” Email Build vs. Buy “Home Built” Application Hosted “Home Built” “Home Built” using cloud “Platform as a Service” HR System Molecule Research Build Clinical Trial Hoster Vendor On Premise Cloud
20. Big Pharmaceutical Example “Packaged” Application Hosted “Packaged” “Packaged” using cloud “Software as a Service” Buy ERP CRM Email Build vs. Buy “Home Built” Application Hosted “Home Built” “Home Built” using cloud “Platform as a Service” “I can’t afford to maintain this old HR application written in VB4 – it’s driving me mad!” HR System “…but due to regulatory issues, I cannot store my HR data off-premise” Molecule Research Build Clinical Trial Hoster Vendor On Premise Cloud
21. “Packaged” Application Big Pharmaceutical Example Hosted “Packaged” “Packaged” using cloud “Software as a Service” Buy ERP CRM Email HR System Build vs. Buy “Home Built” Application Hosted “Home Built” “Home Built” using cloud “Platform as a Service” “I wish I had access to cheaper compute and storage when I need it” Molecule Research Build Clinical Trial Hoster Vendor On Premise Cloud
22. “Packaged” Application Big Pharmaceutical Example Hosted “Packaged” “Packaged” using cloud “Software as a Service” Buy ERP CRM Email HR System Build vs. Buy “Home Built” Application Hosted “Home Built” “Home Built” using cloud “Platform as a Service” Molecule Research Build “THIS is where I want to spend my IT resources – I’m going to double down on this application!” Clinical Trial Hoster Vendor On Premise Cloud
25. Windows Azure VMs Small Medium Large X Large $0.12 $0.24 $0.48 $0.96 Per service hour Per service hour Per service hour Per service hour 1 x 1.6Ghz 2 x 1.6Ghz 4 x 1.6Ghz 8 x 1.6Ghz (moderate IO) (high IO) (high IO) (high IO) 1.75 GB memory 3.5 GB memory 7.0 GB memory 14 GB memory
26. Windows Azure, In One Picture Business Portal Developer Portal Service Management Service REST User Code … … Runtime API Storage Cluster VS Tools Compute Cluster … WA SDK VM Setup REST MSFT Datacenters Desktop Cloud VM
35. Windows Azure, In One Picture Business Portal Developer Portal Service Management Service REST User Code … … Runtime API Storage Cluster VS Tools Compute Cluster … WA SDK VM Setup REST MSFT Datacenters Desktop Cloud VM
43. Windows Azure 4 Eclipse Does a lot of the heavy lifting for you Creates the Web.config, Web.roleConfig, PHP implementation and debugs in the dev fabric http://windowsazure4e.org
44. Running EXEs in the Worker Process Start with a Worker Role Process to Copy the exes to the worker role’s app directory Execute the process Monitor the health of the process Other auxiliary tasks…
45. Running Ruby in the Worker Process http://code.msdn.microsoft.com/railsonazure Download and extract the solution Copy the Ruby bin and lib folders to the Ruby folder in the RR project Copy your rails application to the RailsApp folder in the RR project Open the solution in Visual Studio Run in the Dev Fabric Navigate to http://127.0.0.1:5100
59. PHP with Windows Azure Storage Windows Azure SDK for PHP @ http://phpazure.codeplex.com PHP programming model for Windows Azure Storage Features PHP classes for Blobs, Tables & Queues Store PHP sessions in Table Storage
60. Windows Azure Data Storage - Blobs Unstructured data storage Partitioned by container Unlimited containers
61. Blobs Sample $blobStorage= new Microsoft_WindowsAzure_Storage_Blob(); // Create if (!$blobStorage->containerExists($containerName)) { $blobStorage->createContainer($containerName); $blobStorage->setContainerAcl($containerName, Microsoft_WindowsAzure_Storage_Blob::ACL_PUBLIC); } // Store $blob = $blobStorage->putBlob($containerName, $blobName, $localFilename, $metadata); /* @var $blob Microsoft_WindowsAzure_Storage_BlobInstance */
63. Blob Stream Wrapper $blobStorage= new Microsoft_WindowsAzure_Storage_Blob(); // Register: $blobStorage->registerStreamWrapper(); // registers azure:// // or $blobStorage->registerStreamWrapper('blob://'); // use blob:// // Use $fp= fopen('azure://mycontainer/myfile.txt', 'r'); // ... fclose($fp);
64. Storage: XDrive NTFS drive in the cloud: X:br />Fixed size between 16MB and 1TB Max 8 drives on your VM Implemented as a page blob Single instance write Multiple instance read
65. Queue Workflow Concepts Windows Azure Queue Provides Guarantee delivery (two-step consumption) Worker Dequeues Message and mark it as Invisible Worker Deletes Message when finished processing it If Worker role crashes, message becomes visible for another Worker to process Doesn’t guarantee “only once” delivery Doesn’t guarantee ordering Best effort FIFO Worker Role Web Role Input Queue (Work Items) Worker Role Azure Queue Web Role Worker Role Web Role Worker Role
66. Azure Queues RemoveMessage GetMessage (Timeout) Worker Role PutMessage Queue Msg 1 Msg 2 Msg 2 Msg 1 Web Role Worker Role Worker Role Msg 3 Msg 4 Msg 2
67. Loosely Coupled Work with Queues Worker-Queue Model Load work in a queue Many workers consume the queue Input Queue (Work Items) Azure Queue Worker Role Web Role Worker Role Web Role Worker Role Web Role Worker Role
68. Queues $queueClient= new Microsoft_WindowsAzure_Storage_Queue(); // Create $result = $queueClient->createQueue('imageQueue'); // Delete $queueClient->deleteQueue('imageQueue'); // Add message $queueClient->putMessage('imageQueue', $message, $ttl); // Retrieve Messages $messages = $queueClient->getMessages('imageQueue', 10); foreach($messages as $message) { // Do work here... $queueClient->deleteMessage('imageQueue', $message); }
69. Windows Azure Data Storage - Tables Semi-Structured data Tables contain entities Entities contain properties May be partitioned across thousands of servers. Support ACID transactions over single entities Queries over entire table .NET and REST interfaces
70. Windows Azure Data Storage – Tables (Terms Part 1) Table Contains a set of entities. Entity (Row) Basic data items stored in a table. Property (Column) Single value in an entity. RowKey Unique ID of the entity within a partition Timestamp Time it was created
71. Windows Azure Data Storage – Tables (Terms Part 2) Partition Entities in a table with the same partition key PartitionKey Segments entities in to partitions to automatically distribute the table’s entities over many storage nodes. Sort Order There is a single index provided for the CTP, where all entities in a table are sorted by PartitionKey and then RowKey
72. Key Example – Blog Posts Partition 1 Partition 2 Getting all of dunnry’s blog posts is fast Single partition Getting all posts after 2008-03-27 is slow Traverse all partitions
73. Table Sample $tableStorage= new Microsoft_WindowsAzure_Storage_Table( 'table.core.windows.net', 'myaccount', 'myauthkey'); // Create $result = $tableStorage->createTable($tableName); // List $result = $tableStorage->listTables(); foreach($result as $table) { echo 'Table name is: ' . $table->Name . ""; } // Delete $tableStorage->deleteTable($tableName);
74. Tables with Entities // Structured entity class ImageEntityextends Microsoft_WindowsAzure_Storage_TableEntity { /** * @azure filename */ public $filename; /** * @azure size Edm.Int64 */ public $size; } // Unstructured entity // Microsoft_WindowsAzure_Storage_DynamicTableEntity
81. MySQL in a Windows Azure Application Running MySQL in a worker role Copy MySQL to the worker role sub-directory Copy to read-write local storage Configure MySQL to listen on the right port Monitor MySQL health Consuming MySQL Discover IP address and port Normal access from then on Handle topology changes
95. Database Migrations Scripts Transfer Schema BCP Transfer Data SSIS (SQL Server Integration Service) Transfer Schema and Data
96. Database Migrations (Cont.) The SQL Azure Migration Wizard helps you migrate your local SQL Server 2005 / 2008 databases into SQL Azure. The wizard walks you through the selection of your SQL objects, creates SQL scripts suitable for SQL Azure, and allows you to migrate your data.” http://sqlazuremw.codeplex.com/
98. PHP with SQL Azure SQL Server Driver for PHP @ http://sqlsrvphp.codeplex.com/ Supports PHP access to SQL Azure Features Choose between SQL Server and SQL Azure by changing connection string Use from on-premises or in Windows Azure
99.
100. More resources Microsoft Windows Azure Interop http://www.microsoft.com/windowsazure/interop/ Interop Bridges http://www.interoperabilitybridges.com/
101. More resources PHP http://www.windowsazure4e.org http://phpazure.codeplex.com/ MySQL Windows Azure MySQL PHP Solution Accelerator http://code.msdn.microsoft.com/winazuremysqlphp
102. More resources Python Sriram Krishnan http://www.sriramkrishnan.com/blog/2008/11/python-wrapper-for-windows-azure.html Ruby Simon Davies http://blogs.msdn.com/simondavies http://code.msdn.microsoft.com/railsonazure Johnny Halife http://github.com/johnnyhalife/waz-storage http://waz-storage.heroku.com/rdoc/index.html
103. And of course Josh Holmes http://www.joshholmes.com
104. Scaling Big while Sleeping Well Josh Holmes @joshholmes josh.holmes@microsoft.com www.joshholmes.com
Notes de l'éditeur
Many of the challenges with building applications today have very little to do with development tools, programming languages, or frameworks. Rather, many of the challenges that organizations face are related to the infrastructure required to deploy, run, and manage applications. Quickly summarize only 1 of the following:Startups - For example, imagine you were a startup building the next social networking site or online game You have to worry about numerous issues that are unrelated to the functionality of the application.[Capacity]You have to think about the capacity requirements for the application.Will it be used by a few thousand users or hundreds of thousands or millions?How do users translate to bandwidth, storage, and server requirements?Will the usage be consistent during all times of the year? Will it be consistent over the lifetime of the application?Can you handle spikes in demand if there were sudden demands for the app? (Digg Effect)Ultimately, most organizations end up paying for more capacity then they need.[Deployment, operations, and versioning]Then you have to worry about deploying and operating your applicationHow do you deploy your application over multiple servers?How do you role out updates to the app without taking it offline?How do you manage patches? Enterprise - For established organizations, some of these decisions and problems may have already been addressed through a shared data center or an established staff and processes. However, in enterprise organizations we often find that apps are silos of their own servers. Established organizations also still have to spend a significant amount of capital and operations funding. IT resources are applied to maintaining applications rather than delivering new value and functionality. ISV - Finally, if you’re an ISV who builds applications for use by other businesses you have to worry about a number of additional problems. You have to think about your customer’s capacity, which gets factored into the cost of ownership. Often, your sales opportunities are limited by your customer’s ability to deploy new applications.Your customers often have existing assets such as order fulfillment systems, ERP systems, multi-terabyte databases, etc. that are running on-premise. You must be able to easily integrate with these assets.
This reference chart may help us to recognize opportunities for using cloud computing within our own organizations or our vendors or customers.A new social networking sight may need a massive amount of scalability…A 911 call center may require that last “9” of reliability…A tax preparation package may require varying amounts of computational power, storage, and bandwidth…A hurricane relief site may need to launch on a moment’s notice and be available for a duration that is hard to predict at the onset of the disaster.A genome sequencing project or perhaps a search for extraterrestrial planets to live on in our future might require massive amounts of parallel processing power.A new online startup may need to begin business with little or no capital investment and fail fast with little or no financial lossSo with the terrific list of “great fits” … are there any “bad fits”? Well… yes… there are a few… at the present time…Frequently updated applications are not very good candidates. Primarily I say this because as a developer … the time that it takes to deploy is longer than if you had your own local on premise or hosted servers; however, you must take this with a grain of salt as you’ll have to compare it against the level of effort the you presently invest to make deployments in order to gauge the applicability of this advice.Applications needing external data storage are also not very good candidates at the present time.Of course, this is a moving target… and as cloud computing evolves further… even these bullets (and others like them) may move from the not-so-good list to the good-list. We are entering a new era of software development where we will once again be inspired and excited about our profession as software developers!
We’ll start with SQL Azure... This will give most of developers a common frame of reference as most developers are comfortable with relational databases.In a short while, I will introduce Blobs, Tables, Queues, and DrivesSQL Azure can be thought of as your SQL Server in the cloud. It is based on a subset of SQL Server 2008.Blobs are a means of storing unstructured data, such as pictures, movies, PDF’s, Word documents, and the like.Tables are a means of storing semi-structured or tabular data. Tables are similar to an Excel spreadsheet in the sense that data is tabular and there is no strict type cohesion as there would be in a SQL Server table column. Data stored in tables is partitioned and keyed for retrievalQueues are a means of buffered message delivery. There are very useful for communicating data between our Windows Azure service instances. As our service instances do not have to wait around for the I/O of delivering the message or the result of the message processing, they can dramatically improve the scalability of our software system.Drives are a recently added feature announced at the Los Angeles PDC in November 2009. Drives provide durable storage that appears to our application as an NTFS volume. The drive itself is an abstraction over the same Windows Azure Data Storage used for Blobs. You can get more information on Drives by visiting the PDC site on my slide.Applications may use multiple types of data storage at the same time. In fact, this is quite common. When we do our first Windows Azure Data Storage demo together, I will be showing you an application that uses Blobs, Tables, and Queues in concert.
Okay… That’s all about SQL Azure for now… we’ll come back to this topic in Session 3…Keep in mind that SQL Azure is a separate product from Windows Azure…. And that Windows Azure includes Windows Azure Data Storage, which we are going to talk about now. We will be using the Windows Azure Data Storage directly in demos, so these slides will provide more of a brief and high level overview.To get Windows Azure Data Storage setup, we simply create a new Storage Account from the Windows Azure Portal.
Our Windows Azure Data Storage will be accessible via RESTful queries at the endpoints you see on this slide, or via the API in the Windows Azure SDK library.We’ll be using the Windows Azure library in our demo.
It’s time now to introduce Windows Azure Data Storage Blobs.Blobs are for storage of unstructured data.We partition our data by creating Blob containers which we give names to.We can create an unlimited number of Blob Containers.We then simply place our blob data into the blob containers, supplying a unique identifier.When we want to retrieve our data, we simply provide the container and the unique identifier.
Use queues as a way of communicating w/ the backend worker rolesWRs call getmessage and pass timeoutTimeout value is importantExpiration time is important; message is marked in the queue as invisible; for duration of timeout it’s invisibleWhen we’re done processing, we call a message to remove the message through a deleteTh reason we do this is imagine we have a second worker role; if something goes wrong, once the timeout expires, the message becomes visible, and the next person to do a get message will get the message
http://www.flickr.com/photos/cav666/3562455727/http://go.microsoft.com/fwlink/?LinkId=153401Windows Azure Data Storage Tables are how we get massively scalable and highly available databases.Although there are some similarities, these tables are very different from relational database tables.Data in Windows Azure Data Storage Tables is semi-structured; The concept of a Windows Azure Data Storage Table is similar to how a spreadsheet is used to provide tabularized organization to data without strongly enforcing data cohesion.… Data is indexed in Tables for high performance retrieval, but there are no relationships between Tables.The tables support ACID transactions over single entities and rich queries over the entire table.
The PartitionKey combined with the RowKey uniquely identifies an entity in a table.
11:53Getting the all of dunnry’s post it fast because we’re selecting the entities by a partition keyGetting all of the posts after a certain is slow because we may have to traverse across multiple servers because we’re selecting entities that span partition keysA query without the partition key is really a scan
We have included this feature comparison table in anticipation of your likely questions about differences between using a relational database table as you may be currently doing with your SQL Server databases and the new Windows Azure Tables included in Windows Azure.
As I stated earlier, SQL Azure is based on SQL Server 2008. At this time it is only a subset of the features of the server product.My intention here is to convey the high level features that are supported and the ones that are not.SQL Azure will support most of the things we need… Tables, Index, Views, Stored Procedures, Triggers, and Constraints… in my book… that’s all the functionality that I need for most of my applications.There are some other adjunct technologies that ship as part of SQL Server 2008 such as SQL Reporting Services and Analysis Services which are not supported. The Service Broker is also not supported.
So let’s assume that we have designed our relational database with local developer and data modeling tools.We can begin our story then by assuming that we want to get our database deployed to the cloud.There are some tools that will expedite this process which I will show you later, but for now lets assume that we have scripted our database schema. We apply this script to SQL Azure which speaks native TDS.If you created your database through the SQL Azure Portal, then SQL Azure will have created one master database and three replicas of that database. If you create your database with the script the same will be true.These replicas are stored in different database centers from the master to provide redundancy and protection against geographical catastrophe.
Configuring our application to use SQL Azure storage instead of SQL Server is simply a matter of modifying the connection string in our application’s configuration file.When our application requests data, ADO.NET speaks to the TDS which directs our queries to the master database server. The master database server performs our query and returns the results to our application.
From our application’s point of view, there is only one SQL Azure database.As we make updates to our database, those updates are replicated to other copies stored in other data centers so that in the event that our database fails for any reason, the other databases will be standing by ready to take its place.
But what if that master database server fails for some reason?TDS is receives notification of the database failure and automatically redirects the call to the replica!The Azure Cloud Fabric is self-healing… and the details are outside the scope of this presentation; however, the fabric will get busy repairing itself like drones on a Borg mother ship… essentially with the objective of keeping three replicas online at a time.
I will demonstrate creating a SQL Azure account in session 3 where I will walk you through the entire process.For now I simply want to give you some background information to prepare you for our first demonstration.When we create our SQL Azure database server, we’ll be prompted for an Administrator’s name and a password.This username and password will be the granted a system administrator role that is similar to the “sa” account on a local SQL Server 2008 box. The account has permission to create and drop databases and database ownership authority in any databases that you create with this account.
After creating your SQL Azure database server, you will want to grant appropriate access through the SQL Azure firewall.SQL Azure provides a very simple and easy to maintain firewall. The firewall is so easy to use that it’s only going to get one slide in my deck!The firewall allows us to expose our database to Windows Azure services via a checkbox and to add ranges of IP addresses such as your home office and your business… or possibly the address of a 3rd party server hosting some application that needs data access.I’ll do a thorough demo of this feature in session 3…
When you created your SQL Azure database server, you supplied an administrator’s user name and password. I have named my user accordingly… to remind me of its power.The SQL Portal will offer you the ability to copy these credentials in connection string format to your clip board… tempting you into believing that you should just paste this into your configuration file.This is terrific for demos like mine… BUT you should NEVER, EVER do this…A database server system administrator password placed in a configuration file in clear text format… there has got to be something naive in the extreme going on here… and worse… no way to create non-sa-like users through the UI… you must script your database users and then apply the script to the database. And to anticipate your question… no… you can’t use SQL Server Management Studio to do this either.I will demo this as well in session 3… so hang tight…
There are a number of techniques for getting data migrated from an existing database into a SQL Azure database.One very effective technique is to script the database schema and any stored procedures or views and then apply these scripts to the SQL Azure database. Once the schema has been deployed to the cloud, BCP can be used to copy the data in.Another effective technique is to utilize SQL Server Integration Service which will transfer the Schema and the Data.
I think that I saved the best for last here… The SQL Server Migration Wizard is available for download from the CodePlex website at the URL on this slide.To quote the website, “The SQL Azure Migration Wizard helps you migrate your local SQL Server 2005 / 2008 databases into SQL Azure. The wizard walks you through the selection of your SQL objects, creates SQL scripts suitable for SQL Azure, and allows you to migrate your data.”I will demonstrate this tool in session 3 when I use it to migrate an application and associated database from the local desktop to the cloud.
Although some things can be done with SQL Server 2008 Management Studio, I highly recommend that you use the 2008 R2 Nov CTP as it is SQL Azure aware.After you have created your system administrator account for SQL Azure, you can use SQL Server Management Studio R2 CTP to make connections to the database and execute scripts such as the one that I am showing in this slide.