sriram krishnan program manager microsoft corporation [email protected] es03

112
Windows Azure: Cloud service development best practices Sriram Krishnan Program Manager Microsoft Corporation sriramk@microsof t.com ES03

Upload: ronald-cooper

Post on 01-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Windows Azure: Cloud service development best practices

Sriram KrishnanProgram ManagerMicrosoft Corporation

[email protected]

ES03

1980

void quicksort(int* array, int left, int right)

{

if(left >= right)

return;

int index = partition(array, left, right);

quicksort(array, left, index - 1);

quicksort(array, index + 1, right);

}

simplicity

Act IArchitecture

Networks are unreliable

Hardware fails

A few design choices

Big, reliable,

expensive machine

Several commodity machines

Lots and lots of commodity machines

A few challenges

What do you do about that pesky thing called state?

Go horizontalGo stateless

Store state in Windows Azure storage

And it is the default out of the box!

Session state provider

<system.web>

...<sessionState mode="Custom"

customProvider="TableStorageSessionStateProvider">            <providers>

                <add name="TableStorageSessionStateProvider“

        type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageSessionStateProvider"                    

applicationName=“Foo” />

            </providers></sessionState>

</system.web>

How do you deal with unreliable components?

Be loosely coupled

Use Windows Azure queues for separation of work

Default.aspx(Input + Making

Coffee)

LB

Tight coupling : Default.aspx.cs

public partial class _Default : System.Web.UI.Page    {                 protected void Button1_Click(object sender,EventArgs e)        {            var order = txtOrder.Text;            ProcessOrder(order);        }

protected void ProcessOrder(string order)        {  //Make some coffee!

...        }

     }

Default.aspx(Input)

Windows Azure Queues

LB

Worker.cs(Make Coffee)

Loose coupling : Default.aspx.cs

public partial class _Default : System.Web.UI.Page    {                 protected void Button1_Click(object sender,EventArgs e)        {            var order = txtOrder.Text;

            QueueStorage qStore = QueueStorage.Create(_account);

            MessageQueue orderQ = qStore.GetQueue("OrderQueue");

            orderQ.PutMessage(new Message(order));         }

     }

Loose coupling : WorkerRole.cs

public class WorkerRole : RoleEntryPoint    {        public override void Start()        {

            QueueStorage qStore = QueueStorage.Create(_account);            MessageQueue orderQ = qStore.GetQueue("OrderQueue");            while (true)            {                Message msg = orderQ.GetMessage();

if( msg != null)                 ProcessOrder(msg.ContentAsString());            }        }               protected void ProcessOrder(string order)        {

//Make some coffee! ...

        }

How do you deal with varying load?

Build a thermostat for your service

How do you deal with failures?

Use Windows Azure storage for valuable data

Be prepared to reconstruct local state…

…since it can disappear any time

Retry on transient failures

But…

Be idempotent

Don’t launch a DoS attack on yourself

Be predictable

Avoid shutdown code

Know when to throttle and shed load

Case study: SmugMug and SkyNet

When is ‘good enough’ good enough?

The resiliency of email

Do all apps need the same guarantees?

It's a knob

Stateless front-endsLoose couplingBuilding a thermostatRetrying on failuresLoosening consistency

Recap

End of Act I

Act IIUpdates

Updates are hard

Hard to ‘undo’ a failed deployment

Need to deal with both code and schema changes

Code + data

Update only one at a time

Code vN Data vN

Code vN

Data vN

Code vN +1

Code vN

Data vN

Data vN+1

Be compatible

If it looks like a duck and walks like a duck…

http://www.flickr.com/photos/gaetanlee/298160415/

Use version numbers in schema

  class Employee : TableStorageEntity    {        public Employee(string firstName, string lastName) :            base(firstName, lastName) //partition key, row key        {}         public string JobTitle        {             get;             set;         }     }  

...       var qResult = from emp in

svc.CreateQuery<Employee>(EmployeeDataServiceContext.EmployeeTable)

       where emp.PartitionKey == "Steve" && emp.RowKey == "Marx        select emp;

Schema without versioning                                  }

  class Employee : TableStorageEntity    {        public Employee(string firstName, string lastName) :            base(firstName, lastName)        {}         public string JobTitle        {             get; set;         }

        public int Version         {             get; set;

        } 

    }  ...       var qResult = from emp in

svc.CreateQuery<Employee>(EmployeeDataServiceContext.EmployeeTable)

       where emp.PartitionKey == "Steve" && emp.RowKey == "Marx

&& emp.Version == 1        select emp;

Schema *with* versioning                                  }

How do you do upgrades without downtime?

Windows Azure’s rolling upgrades

Stage Deployment Production Deployment

Swap for zero downtime upgrade

+Stop + start for big changes or if

downtime isn’t an issue

Future: Precise control

When is the best time to update a service?

Use the Pacific Ocean

Case study: Windows Live ID

Update code or dataMaintain compatVersioning in schemasRolling upgrades

Recap

End of Act II

December 4th, 1996

Oh Oh!

Trace logs

Trickiest patch ever

Act IIIWhen things go wrong…

How do I debug?

Use the Windows Azure SDK and debug locally to find bugs

Separate code and config

 ServiceDefinition.csdef

<ServiceDefinition name="DemoService">  <WebRole name="WebRole">    <ConfigurationSettings>

      <Setting name="Color"/>

    </ConfigurationSettings>  </WebRole></ServiceDefinition>

ServiceConfiguration.cscfg

<ServiceConfiguration serviceName="DemoService">  <Role name="WebRole">    <ConfigurationSettings>

      <Setting name ="Color" value ="Red"/>

    </ConfigurationSettings>  </Role></ServiceConfiguration>

Configuration files           

Windows Azure’s configuration update mechanism

How do I debug the cloud?

Logging

  <?xml version="1.0"?><ServiceConfiguration serviceName=“DemoService”>

  <Role name="WebRole">

    <Instances count="1"/>    <ConfigurationSettings>

      <Setting name ="LogLevel" value ="Verbose"/>

    </ConfigurationSettings>  </Role></ServiceConfiguration>

...

Configurable logging           

if (RoleManager.GetConfigurationSetting("LogLevel") == "Verbose")       RoleManager.WriteToLog("Information", "Some log message");

Tag data with unique ID to track across the system

{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}

How do I get notified when something bad happens?

!

Windows Azure’s alerts

!

Email / IM / Phone

The Big Red Button

Use the SDKSeparate code and configConfigurable loggingAlertsThe Big Red Button

Recap

End of Act III

James Hamilton http://research.microsoft.com/~jamesrh/

Emre Kiciman http://research.microsoft.com/~emrek/

Pat Helland http://blogs.msdn.com/pathelland/

What really happened on Mars http://research.microsoft.com/~mbj/mars_pathfinder/

Flickr blog post http://code.flickr.com/blog/2008/09/26/flickr-engineers-do-it-offline/

Don MacAskill http://blogs.smugmug.com/don/

Credits & Acknowledgements

One final story

William of Ockhamc. 1288 - c. 1348

Numquam ponenda est pluralitas sine necessitate

Plurality ought never be posited without necessity

KISS

simplicity

[email protected]

www.sriramkrishnan.com

Evals & Recordings

Please fill

out your

evaluation for

this session at:

This session will be available as a recording at:

www.microsoftpdc.com

Please use the microphones provided

Q&A

© 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market

conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.