Cloud Computing with .Net
CodeMash 2009
Wes Faler
Cloud Computing

• Just what is “Cloud Computing”?
  – Is it difficult to get started with the Cloud?


• Short answers:
  – Computing resources on demand.

  – It’s easier than you think and you likely
    already know how and just don’t know it.
Example Cloud Architecture?




                               Worker
Client




              Controller       Worker



Client



                               Worker
Typical Cloud Architecture!




                                Web
Browser
                                Server




                 Load
                                Web

                 Balancer       Server

Browser



           Congratulations!     Web

                                Server
Client                 Master
          Essential

           Parts

            Of a

         Distributed
Queue                  Workers
         Application
Amazon EC2 Sample Application

• The problem:
  – Use ZabaSearch.com to search public
    records, obtaining alternate addresses
    for a person.
  – They won’t take a data file with
    thousands of records and do batch
    processing, but did ok as many searches
    as we can do using their web site.
  – I’m too cheap to pay a hundred people to
    point and click on a website, and doing it
    with just one is far too slow.
Amazon EC2 Sample App




                   Master
                                                       Client
                (Web Service)       Job
Jobs &                                           Windows service
                  -Get Jobs       Bundles
Results                                        calls Master interface
               - Report Results
                                               then uses Core logic
                -Worker Mgmt




     • We know all these technologies.
     • It’s only the technique we really need to study.
Amazon EC2 Sample App

• The Solution:
  – A core module able to POST to ZabaSearch
    and scrape data from its HTML.
  – A database as the queue of names/addresses
    to check and to hold the results.
  – A master web service giving out blocks of
    name/address jobs
  – A worker service getting jobs and using the
    core module
  – A local computer running the worker service
  – Any number of Amazon EC2 computers
    running the worker service
• Tada! It’s Cloud Ready!
Database Schema and Job States

                    •   Jobs start in “ToDo” status
                    •   When a worker requests a bundle,
                        jobs are set to “InProgress”, get an
                        expiration time, and get flagged
                        with the worker’s GUID.
                    •   Jobs not done by the expiration
                        time are reset back to “ToDo” and
                        their worker ID cleared.
                    •   When workers report results,
                        results are only recorded if the job
                        is still “InProgress” and still
                        assigned to the worker. Such jobs
                        get set to “Done”.
                    •   As a courtesy, workers can report
                        that they are abandoning work,
                        which just sets anything
                        “InProgress” assigned to them
                        back to “ToDo” with a cleared
                        worker ID.
Amazon EC2 Sample App

Code Demo
• ZabaSearch Core
• Master Web Service
• Client Interface
• Client Service Threading
Amazon EC2 Sample App

Getting It Into The Cloud

• Signup, Keys, Security, Security, Security,
  and Some More Security.

• Elastifox
  – Public AMIs
  – Instances
     • Start, Stop, Reboot
     • Destroy
  – Bundles
  – Private AMIs
Web

                         Servers
            DB                          Process
          Servers                        Flow



                    Things in a Cloud

                       All using:
Virtual
                        Storage
 PCs

                        Security
Cloud Hierarchy




Michael Sheehan on Jun 24th, 2008
“The Cloud Pyramid”
In the Cloud, you can…

• Rent
  –   Web servers
  –   Load balancers
  –   Database servers
  –   Storage space
  –   Logic
       • Application
       • Queue Management/Flow
• Vary
  – Number of each rented item
  – Location of each rented item
Types of Distributed Apps




                Farm

                                  Cluster

                  All Can Be In

  Shared PC            A Cloud


                                        Grid
Virtual PC      Farm         Cluster       Grid       Cloud

                                                       0 to Mini-   Pay as you
   Cash        Up front      Up front      Up front
                                                       Cluster      grow

                                                                    On
Availability   Dedicated Dedicated Dedicated Statistical
                                                                    Demand

Redundancy     None          Good          Good        Good         Varies


                                           General but General but
Computing      General       Specialized                           Varies
                                           Custom      Custom
Low Hanging Fruit

• What could you do with a virtual
  computer in the cloud?
  – It’s sharable
  – You control the configuration
  – Not just rebootable, reformatted-and-
    reinstalled with a click
  – Discardable
  – Cheap
  – No waiting
Low Hanging Fruit

• Install incremental releases onto a cloud
  virtual PC
  –   Control the demo environment
  –   Fully validate before release
  –   Restore to initial release easily
  –   Archivable
  –   Remove the client’s configuration from
      each release’s issue list
Low Hanging Fruit

• Training Applications on cloud virtual
  PCs
  – Create one master image and clone on
    demand
  – Trainees only need remote desktop
    access
  – Easily reset for those adventurous
    students
Low Hanging Fruit

• A Spare Development PC – Per
  Developer!
  – Unit tests, esp. CPU intensive ones
  – Can start with standard, easily reset, test
    data
  – Installer testing without breaking your
    development environment
  – Ease handoffs to QA dept
  – Experiment with time-limited trial
    libraries without the time limit
Queuing!
   We finally have to take it seriously.
   (My simulation prof would be so happy!)

             Latency
             Activation
             Flow Control
Queuing: Latency

Consider:
• 100 requests, each taking 3 seconds on a
  high end server when done sequentially.
• How long does the 1st request take?
  – 3 seconds. Users love us!
• How long does the 100th request take?
  – 300 seconds. Users hate us. Work every
    weekend until this is fixed.
• 300 seconds? Don’t measure just
  “Performance”, measure “Latency”.
• Which do you test most often?
Queuing: Latency

Consider:
• 100 requests, each taking 3+1 seconds on
  20 medium virtual servers in a cloud.
• How long does the 1st request take?
  – 3+1 seconds. Users still love us!
• How long does the 100th request take?
  – 20 seconds. Is this ok?
• Classical “Performance” dropped, but
  “Latency” improved drastically. Which
  actually drives satisfaction more?
Queuing: Latency

Best Case Latency = Time/Item
Worst Case Latency = Time/Item * # of items /
  # of servers
Average Latency = Time/Item * (# of items / #
  of servers) / 2

Clouds likely raise Time/Item slightly but can
  raise the number of servers drastically.
Order the number of servers that will meet
  your latency needs.
Speed up your code! Time/Item still matters.
Queuing

• Activation
  – What gets activated when an item moves
    within the queue?
  – Push vs. Pull?


• Flow Control
  – Are all jobs equal?
  – Are all processes equal?


• What are users doing while they wait for
  queued items to finish?
Your life will be easier if you…

• Separate your core logic from your cloud
  communications logic
• Put core logic into its own assembly
• Objects-In, Objects-Out in your core
• Use unit tests for your core
• Use an interactive testing tool to debug your core logic
   – Remember it’ll be much harder to debug once in the
     cloud!
• Consider network connectivity problems when coding
  recovery logic
   – Balance reassignment with forgiveness
• Design for some local processing
Costs

• Data sent into the cloud, even if your cloud software
  requested the data.
• Data sent out of the cloud, even if your cloud software
  sent the data.
• Data sent within the cloud isn’t typically charged for.
• Time your machine instances exist – even if “off”.
• CPU time actually used.
• RAM available.
• Time and size of storage, including uninstantiated
  machine instances.

• Amazon EC2 costs me about $20/month and would be
  about $100/month for a 24x7 medium power virtual
  machine.
• Transfer large lumps, such as databases, once and
  keep them in the cloud. It’s faster and cheaper.
Cloud Computing

• Just what is “Cloud Computing”?

• Short answer: Computing resources on
  demand.

• Real answer: Architecture Freedom!
Wes Faler
wes.faler@gmail.com

Cloud Computing with .Net

  • 1.
    Cloud Computing with.Net CodeMash 2009 Wes Faler
  • 2.
    Cloud Computing • Justwhat is “Cloud Computing”? – Is it difficult to get started with the Cloud? • Short answers: – Computing resources on demand. – It’s easier than you think and you likely already know how and just don’t know it.
  • 3.
    Example Cloud Architecture? Worker Client Controller Worker Client Worker
  • 4.
    Typical Cloud Architecture! Web Browser Server Load Web Balancer Server Browser Congratulations! Web Server
  • 5.
    Client Master Essential Parts Of a Distributed Queue Workers Application
  • 6.
    Amazon EC2 SampleApplication • The problem: – Use ZabaSearch.com to search public records, obtaining alternate addresses for a person. – They won’t take a data file with thousands of records and do batch processing, but did ok as many searches as we can do using their web site. – I’m too cheap to pay a hundred people to point and click on a website, and doing it with just one is far too slow.
  • 7.
    Amazon EC2 SampleApp Master Client (Web Service) Job Jobs & Windows service -Get Jobs Bundles Results calls Master interface - Report Results then uses Core logic -Worker Mgmt • We know all these technologies. • It’s only the technique we really need to study.
  • 8.
    Amazon EC2 SampleApp • The Solution: – A core module able to POST to ZabaSearch and scrape data from its HTML. – A database as the queue of names/addresses to check and to hold the results. – A master web service giving out blocks of name/address jobs – A worker service getting jobs and using the core module – A local computer running the worker service – Any number of Amazon EC2 computers running the worker service • Tada! It’s Cloud Ready!
  • 9.
    Database Schema andJob States • Jobs start in “ToDo” status • When a worker requests a bundle, jobs are set to “InProgress”, get an expiration time, and get flagged with the worker’s GUID. • Jobs not done by the expiration time are reset back to “ToDo” and their worker ID cleared. • When workers report results, results are only recorded if the job is still “InProgress” and still assigned to the worker. Such jobs get set to “Done”. • As a courtesy, workers can report that they are abandoning work, which just sets anything “InProgress” assigned to them back to “ToDo” with a cleared worker ID.
  • 10.
    Amazon EC2 SampleApp Code Demo • ZabaSearch Core • Master Web Service • Client Interface • Client Service Threading
  • 11.
    Amazon EC2 SampleApp Getting It Into The Cloud • Signup, Keys, Security, Security, Security, and Some More Security. • Elastifox – Public AMIs – Instances • Start, Stop, Reboot • Destroy – Bundles – Private AMIs
  • 12.
    Web Servers DB Process Servers Flow Things in a Cloud All using: Virtual Storage PCs Security
  • 13.
    Cloud Hierarchy Michael Sheehanon Jun 24th, 2008 “The Cloud Pyramid”
  • 15.
    In the Cloud,you can… • Rent – Web servers – Load balancers – Database servers – Storage space – Logic • Application • Queue Management/Flow • Vary – Number of each rented item – Location of each rented item
  • 16.
    Types of DistributedApps Farm Cluster All Can Be In Shared PC A Cloud Grid
  • 17.
    Virtual PC Farm Cluster Grid Cloud 0 to Mini- Pay as you Cash Up front Up front Up front Cluster grow On Availability Dedicated Dedicated Dedicated Statistical Demand Redundancy None Good Good Good Varies General but General but Computing General Specialized Varies Custom Custom
  • 18.
    Low Hanging Fruit •What could you do with a virtual computer in the cloud? – It’s sharable – You control the configuration – Not just rebootable, reformatted-and- reinstalled with a click – Discardable – Cheap – No waiting
  • 19.
    Low Hanging Fruit •Install incremental releases onto a cloud virtual PC – Control the demo environment – Fully validate before release – Restore to initial release easily – Archivable – Remove the client’s configuration from each release’s issue list
  • 20.
    Low Hanging Fruit •Training Applications on cloud virtual PCs – Create one master image and clone on demand – Trainees only need remote desktop access – Easily reset for those adventurous students
  • 21.
    Low Hanging Fruit •A Spare Development PC – Per Developer! – Unit tests, esp. CPU intensive ones – Can start with standard, easily reset, test data – Installer testing without breaking your development environment – Ease handoffs to QA dept – Experiment with time-limited trial libraries without the time limit
  • 22.
    Queuing! We finally have to take it seriously. (My simulation prof would be so happy!) Latency Activation Flow Control
  • 23.
    Queuing: Latency Consider: • 100requests, each taking 3 seconds on a high end server when done sequentially. • How long does the 1st request take? – 3 seconds. Users love us! • How long does the 100th request take? – 300 seconds. Users hate us. Work every weekend until this is fixed. • 300 seconds? Don’t measure just “Performance”, measure “Latency”. • Which do you test most often?
  • 24.
    Queuing: Latency Consider: • 100requests, each taking 3+1 seconds on 20 medium virtual servers in a cloud. • How long does the 1st request take? – 3+1 seconds. Users still love us! • How long does the 100th request take? – 20 seconds. Is this ok? • Classical “Performance” dropped, but “Latency” improved drastically. Which actually drives satisfaction more?
  • 25.
    Queuing: Latency Best CaseLatency = Time/Item Worst Case Latency = Time/Item * # of items / # of servers Average Latency = Time/Item * (# of items / # of servers) / 2 Clouds likely raise Time/Item slightly but can raise the number of servers drastically. Order the number of servers that will meet your latency needs. Speed up your code! Time/Item still matters.
  • 26.
    Queuing • Activation – What gets activated when an item moves within the queue? – Push vs. Pull? • Flow Control – Are all jobs equal? – Are all processes equal? • What are users doing while they wait for queued items to finish?
  • 27.
    Your life willbe easier if you… • Separate your core logic from your cloud communications logic • Put core logic into its own assembly • Objects-In, Objects-Out in your core • Use unit tests for your core • Use an interactive testing tool to debug your core logic – Remember it’ll be much harder to debug once in the cloud! • Consider network connectivity problems when coding recovery logic – Balance reassignment with forgiveness • Design for some local processing
  • 28.
    Costs • Data sentinto the cloud, even if your cloud software requested the data. • Data sent out of the cloud, even if your cloud software sent the data. • Data sent within the cloud isn’t typically charged for. • Time your machine instances exist – even if “off”. • CPU time actually used. • RAM available. • Time and size of storage, including uninstantiated machine instances. • Amazon EC2 costs me about $20/month and would be about $100/month for a 24x7 medium power virtual machine. • Transfer large lumps, such as databases, once and keep them in the cloud. It’s faster and cheaper.
  • 29.
    Cloud Computing • Justwhat is “Cloud Computing”? • Short answer: Computing resources on demand. • Real answer: Architecture Freedom!
  • 30.