deployingjavaapplicationsonec2-1226335236709628-9

Embed Size (px)

Citation preview

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    1/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Running Java applicationson the Amazon Elastic

    Author of POJOs in Action

    oun er o ou oo s

    www.chrisrichardson.net

    Chris Richardson Running Java applications on Amazon EC2 Slide 1

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    2/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Show how to use

    for developing and deploying Javaapplications

    Chris Richardson Running Java applications on Amazon EC2 Slide 2

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    3/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Grew u in En land and live in Oakland CA Over twenty years of software development

    experience Building object-oriented software since 1986 Using Java since 1996

    Author of POJOs in Action Speaker at JavaOne, SpringOne, NFJS, JavaPolis,

    Spring Experience, etc. Chair of the eBIG Java SIG in Oakland

    . . Run a consulting and training company that helps

    organizations build better software faster anddeploy it on Amazon EC2

    Founder of Cloud Tools, an open-source project

    or ep oy ng ava app ca ons on mazon :http://code.google.com/p/cloudtools

    Chris Richardson Running Java applications on Amazon EC2 Slide 3

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    4/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Using Amazon EC2

    Developing on Amazon EC2 Deploying on Amazon EC2

    A few thou hts about Groov

    Chris Richardson Running Java applications on Amazon EC2 Slide 4

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    5/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    pu w yPast

    Present

    www.computermuseum.org.uk

    www.dell.com

    Yet we rarely have enough

    Chris Richardson Running Java applications on Amazon EC2 Slide 5

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    6/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    ,i n f r a st r u ct u r e t h a t h o st s y o u r

    app l i ca t ion , and i s b i l l ed bycon su m t ion

    Chris Richardson Running Java applications on Amazon EC2 Slide 6

    By James Sta ten o f For res ter Research

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    7/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Past

    Present

    Chris Richardson Running Java applications on Amazon EC2 Slide 7

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    8/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    z - y u pu Elastic Compute Cloud (EC2)

    On-demand computing

    Elastic Block Storage (EBS)" "

    Simple Storage Service (S3)

    Stores blobs of data mp e ueue erv ce

    Hosted queue-based messaging system

    Store data setsExecute queries

    Pay per useservices managed

    Chris Richardson Running Java applications on Amazon EC2

    Slide 8

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    9/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Virtualized computing environment

    Server instances manage t roug a we service API

    IP addresses and host names assigned dynamically Pay by the hour ($0.10-0.80/hour) + external bandwidth

    -. .

    https://ec2.amazonaws.com/?Action=RunInstances&ImageId=ami-398438493

    &MaxCount=3&MinCount=3

    cer@arra is ~$ ssh [email protected] login: Sun Dec 30 18:54:43 2007 from 71.131.29.181[root@domU-12-31-36-00-38-23:~]

    Chris Richardson Running Java applications on Amazon EC2 Slide 9

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    10/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Vir t u a l Com u t e 3 2 / Mem or St o r a e / h rCor es Un i t s

    / co r e*6 4Bi t

    Small 1 1 32 bit 1.7G 160G 0.10

    High-CPU

    Medium

    2 2.5 32 bit 1.7G 350G 0.20

    Large 2 2 64 bit 7.5G 850G 0.40

    ExtraLarge

    4 2 64 bit 15G 1690G 0.80

    High-CPU XL

    8 2.5 64 bit 7G 1690G 0.80

    Chris Richardson Running Java applications on Amazon EC2

    * EC2 Compute Unit = 1.0-1.2 GHz 2007 Opteron or 2007 Xeon processor

    Slide 10

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    11/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Use Amazon provided Machine Image (AMI)

    -

    64-bit Fedora Core 6 Many 3rd parties have public AMIs

    E.g. Redhat, RightScale

    Sun provides OpenSolaris Windows Server 2003 ($0.125-$2/hour) Optional SQL Server Standard ($1.10-3.20/hour)

    Install applications starting with someone else's AMI and

    save it Create an AMI from scratch

    Chris Richardson Running Java applications on Amazon EC2 Slide 11

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    12/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    erm na e your ns ance

    your loca l data is lost.

    Either very good or very bad

    Chris Richardson Running Java applications on Amazon EC2 Slide 12

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    13/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Mountable storage volumes

    "On-demand SAN"Size: 1 GB to 1 TB

    Create snapshotsStored in S3Create new volumes from the snapshot

    Cost:

    $0.10/GByte/month$0.10 per 1 million I/O requests

    Chris Richardson Running Java applications on Amazon EC2 Slide 13

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    14/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Instance IP addresses are dynamically allocated

    -

    Does not work well for publicly accessible services,e.g. a website

    as c a resses: Statically allocated addresses

    Associated with your account (max. 5) Attac e to an instance e.g. pu ic acing we

    server) You configure DNS to resolve to the elastic IP address

    r c ng:Non-attached Elastic IP address - $0.01/hour $0.10 per remap (if > 100 in a month)

    Chris Richardson Running Java applications on Amazon EC2 Slide 14

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    15/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    v y z By default, your database master and slave could run on

    Regions: Geographically dispersed locations

    Availability zone:

    Part of a region

    Specify availability zone when launching instances: Same zone as other instances for free data transfer Different zone for hi her-availabilit

    SLA with 99.95% region availability Instances have external connectivity You can launch new instances

    Chris Richardson Running Java applications on Amazon EC2 Slide 15

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    16/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    What is the Amazon Simple

    r rv Flat storage model consisting of buckets and objects

    Objects has a key, stores 1 byte - 5G Object key can look like a path

    $0.15/GB-Month

    $0.10-0.18/GB of data transferred-. . Data transfers between EC2 and S3 are free of bandwidth

    charges

    Buckets and objects can be:

    Public accessible by anyone Private accessible to owner, acl member

    Chris Richardson Running Java applications on Amazon EC2 Slide 16

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    17/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    PUT / HTTP/1.1Host: .s3.amazonaws.com

    Create a bucket

    PUT / HTTP/1.1< >

    Authorization: AWS AWSAccessKeyId:Signature

    Authorization: AWS AWSAccessKeyId:SignatureBytes

    Create an item in a bucket

    GET / HTTP/1.1Host: .s3.amazonaws.comAuthorization: AWS AWSAccessKeyId:Signature

    Download an item

    DELETE / HTTP/1.1Host: .s3.amazonaws.comAuthorization: AWS AWSAccessKeyId:Signature Delete an item

    Chris Richardson Running Java applications on Amazon EC2

    Slide 17

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    18/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    EC2 instances use S3:

    Store database snapshots in S3

    se par y nux e sys em a s oresdata in S3

    Chris Richardson Running Java applications on Amazon EC2 Slide 18

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    19/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Immediate access to many servers

    Great for testing

    Eliminates capital expenses

    e uces r s o success ca as rop e

    Chris Richardson Running Java applications on Amazon EC2 Slide 19

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    20/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Usin g Am azon EC2

    Developing on Amazon EC2 Deploying on Amazon EC2

    A few thou hts about Groov

    Chris Richardson Running Java applications on Amazon EC2 Slide 20

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    21/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Signing up for Amazon Web

    rv

    AWS accessidentifiers: Account Id Access Id Secret key Private ke and

    certificate

    Only takes afew minutes

    Chris Richardson Running Java applications on Amazon EC2 Slide 21

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    22/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    SOAP and Query APIs

    Launch and manage instances etc

    Amazon provided CLI tools

    AMI creation tools

    AWS CLI tools from Tim Kayor anAlternatives to Amazon CLI tools

    ElasticFoxAwesome Firefox pluginLaunch and manage instances

    Chris Richardson Running Java applications on Amazon EC2 Slide 22

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    23/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    https://ec2.amazonaws.com/?queryparameters...

    an atory parameters:Action what to doAWSAccessKe Id our access idVersion API version

    Timestamp when request was madeSignature digest of parameters and secret keySignatureVersion set to 1

    Other parameters depend on Action Returns an XML document

    Chris Richardson Running Java applications on Amazon EC2 Slide 23

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    24/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    RunInstances MinCount, MaxCount, ImageId,InstanceType,

    .

    DescribeInstances InstanceId.n

    CreateSecurityGroup GroupName, GroupDescriptionAuthorizeSecurityGroupIngress GroupName,

    SourceSecurityGroupName,IpProtocol

    Deaut orizeSecurityGroupIngress

    Chris Richardson Running Java applications on Amazon EC2 Slide 24

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    25/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    aws - simple access to EC2 and

    http://timkay.com/aws/

    Easy to use CLI for EC2 and S3 Implemented in Perl Authenticates using access id and secret

    key stored in ~/.awssecret

    Chris Richardson Running Java applications on Amazon EC2 Slide 25

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    26/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Chris Richardson Running Java applications on Amazon EC2 Slide 26

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    27/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    TIP: launch with a kepair or else you won'thave access

    Chris Richardson Running Java applications on Amazon EC2 Slide 27

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    28/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Easier: Modif an existin AMI

    Launch AMIConfigure: e.g. yum install

    Harder: Build one from scratch

    Launch AMICreate a file to contain OS installation

    Mount as a loopback file

    - Use AMI tools to bundle and upload to S3

    Chris Richardson Running Java applications on Amazon EC2 Slide 28

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    29/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Using Amazon EC2

    Developing on Amazon EC2 Deploying on Amazon EC2

    A few thou hts about Groov

    Chris Richardson Running Java applications on Amazon EC2 Slide 29

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    30/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Deploying a web application on

    Chris Richardson Running Java applications on Amazon EC2

    Not rocket science but there are many servers to configure and multiple files to upload

    Slide 30

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    31/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    ' Open source project 32 and 64 bit AMIs

    CentOS 5.10 A ache/Tomcat/M S L/JMeter/JetS3t installed

    EC2Deploy framework Launches instances

    , ,Deploys web applications Runs Jmeter tests

    Maven and Grails pluginsQuick and easy deployment to EC2

    Chris Richardson Running Java applications on Amazon EC2 Slide 31

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    32/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Provides a DSL for describing a cluster:

    Number of Tomcats, MySQL slaves

    Database scriptsLocation of web a lications

    Launches EC2 instances

    Configures MySQL on gures omcat an ep oys weapplications

    Confi ures A ache to rox the Tomcat

    servers Runs JMeter tests

    Chris Richardson Running Java applications on Amazon EC2 Slide 32

    h 2008 h h dl d f O b 9 2 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    33/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    def ec2 = new EC2()

    ClusterSpec clusterSpec = new ClusterSpec()

    .tomcats(1)

    .instanceType(EC2InstanceType.SMALL)

    .slaves(1)

    .we pp ome cer p rac , p rac

    .catalinaOptsBuilder({optsBuilder, databaseHost, slaves ->

    optsBuilder.arg("-Xmx500m")

    optsBuilder.prop("jdbc.db.server", databaseHost)})

    .schema("ptrack", ["ptrack": "ptrack"],"src/test/resources/testdml1.s l"

    "src/test/resources/testdml2.sql"])

    SimpleCluster cluster = new SimpleCluster(ec2, clusterSpec)

    cluster.start()

    cluster.loadTest("/home/cer//jmeter/SimpleTest.jmx", [5, 10, 15])

    cluster.stop()

    Chris Richardson Running Java applications on Amazon EC2 Slide 33

    Cop ight 2008 Ch is Richa dsonColo ado Soft a e S mmit Octobe 19 24 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    34/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    < < f a a d e > >

    SimpleClusterClusterSpec

    ApacheServerTomcatServer MySqlServerJmeter

    App l i ca t ion

    stop()start()loadTest()

    numberOfTomcatsnumberOfMySqlSlaves...

    contextexplodedWar

    WebApp

    < < a b s t r a c t > >A l icat ion

    uploadToS3()updateTomcat()

    startPollin

    EC2

    waitUntilRunnin

    EC2Server

    instanceId

    EC2I ns tanceSta te

    stopPolling()

    newServers(n)...

    stop()

    ssh(command)...

    state

    publicDnsNameprivateDnsName

    Uses Query API

    to run, terminateand describe

    Executes ssh and

    Chris Richardson Running Java applications on Amazon EC2

    executeRequest(params)

    EC2RequestExecu to r

    ssh(dns, command, )

    Sshinstancesscp comman s

    Slide 34

    Copyright 2008 Chris RichardsonColorado Software Summit: October 19 24 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    35/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    class ApacheServer extends Application {

    def configure() {

    writeFile fileName: "$apacheConfDir/cluster.conf",

    templateName: "/templates/cluster.conf",

    templateArgs: [tomcats: tomcats]

    exec "$apacheBinDir/apachectl restart"

    waitForHttp port:80, path: tomcats[0].contexts[0]

    }

    }class MySqlServer extends Application {

    e con gureAsMaster()

    writeFile fileName: "/etc/my.cnf", templateName: "/templates/master.my.cnf"

    restartService "mysqld"

    exec command: "mysql -u root",

    templateName: "/templates/createSchema.sql",

    templateArgs: [schemaSpec: schemaSpec]

    executeSchemaScripts()

    Chris Richardson Running Java applications on Amazon EC2

    }

    }

    Slide 35

    Copyright 2008 Chris RichardsonColorado Software Summit: October 19 24 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    36/67

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Efficiently uploading web

    pp , . Non-durable disks = upload the entire web

    20+ MBs of jars, etc. Takes a long time (over a DSL connection)

    Web application consists of: 90% 3rd party libraries rarely changing

    10% application code and content only some of itc anges

    Use JetS3t to accelerate uploads Incremental upload of exploded web application to S3

    uc et Incremental download to Tomcat webapps/ directory First upload is slow but subsequent uploads are fast

    Chris Richardson Running Java applications on Amazon EC2 Slide 36

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    37/67

    py g ,,

    Goals: deploy redeploy sto.

    cloudtools-maven-plugin

    ptrack

    dbsave dbrestorejmeter

    ptrack:ptrack

    {builder, databasePrivateDnsName ->

    builder.arg("-Xmx1000m")

    builder.prop("jdbc.db.server", databasePrivateDnsName)}

    mvn cloudtools:deploy

    Chris Richardson Running Java applications on Amazon EC2 Slide 37

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    38/67

    framework plugin

    $ grails install-plugin

    rails cloud-tools-de lo

    Chris Richardson Running Java applications on Amazon EC2 Slide 38

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    39/67

    Using Amazon EC2

    Dev elop in g o n Am azon EC2

    Deploying on Amazon EC2

    A few thou hts about Groov

    Chris Richardson Running Java applications on Amazon EC2 Slide 39

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    40/67

    p r r r700070

    4000

    5000

    6000

    40

    50

    60

    1000

    2000

    3000

    10

    20

    30ART

    equ reshardware

    00

    1 2 4 8 16 32 64

    Measure transactions/second (TPS), average response time (ART), utilization, etc.

    Multiple test runs with different loads, number of servers, etc.

    Chris Richardson Running Java applications on Amazon EC2 Slide 40

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    41/67

    Runs JMeter with

    1

    10

    specified numberof threads

    database

    3.2757014224403784

    Collects machine

    utilization stats

    omca < name>

    94.32473318917411

    apache

    0.12280614752518504

    Generates reports

    jmeter

    7.033683910704496

    test runs

    557.943

    10.753786677133686

    916.6578333333

    Chris Richardson Running Java applications on Amazon EC2

    mvn cloudtools:jmeter -Dcloudtools.thread.count=1,4,8

    Slide 41

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    42/67

    Testin failover

    Launch clusterTake down servers

    Test recovery scripts, e.g. MySQL slave->master

    Launch cluster

    Apply database migration script

    Verif that it works

    Chris Richardson Running Java applications on Amazon EC2 Slide 42

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    43/67

    Tests can be slow, e.g.

    Web tests

    Database intensive tests

    Multiple test drivers, app servers, DBsRelatively cheap: >$75/hour developer vs.

    .

    Selenium Grid from ThoughtworksOpen Source framework

    Runs Selenium web tests in parallel on EC2 Stay tuned for more general solutions

    Chris Richardson Running Java applications on Amazon EC2 Slide 43

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    44/67

    missing dependency

    Manually installed 3rd party library

    Great for open-source projects

    Chris Richardson Running Java applications on Amazon EC2 Slide 44

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    45/67

    Using Amazon EC2

    Developing on Amazon EC2

    Deplo y in g on Am azon EC2

    A few thou hts about Groov

    Chris Richardson Running Java applications on Amazon EC2 Slide 45

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    D l i li ti

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    46/67

    Deploying applications on

    z Great for startups (especially

    Get up and running ready quicklyNo upfront hardware costs

    ca e up own w oa Reduces the risk of a success

    ca tas t rophe rea or en erpr sesNo need to wait for corporate IT Use for short-term projects

    Leaders See Big Prom ise, HaveBig Secur i t y Quest ion s

    www.cio.com/article/455832/Cloud_Computing_Survey_IT_Leaders_See_Big_Promise_Have_Big_Security_Questions

    Chris Richardson Running Java applications on Amazon EC2 Slide 46

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    47/67

    Security:

    Discomfort with sendingcustomer data to a 3rd party

    Not yet suitable for extremelylarge relational databases

    Lack of very large machines,e.g. memory Lack of multicast

    Financials:

    Steady state costs > your ownhardware

    Chris Richardson Running Java applications on Amazon EC2 Slide 47

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    48/67

    -www.acme.com

    EC2 Instance

    Elastic IP A

    Apache

    Tomcat

    MySQL

    Chris Richardson Running Java applications on Amazon EC2 Slide 48

    EBS Volume

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    49/67

    -www.acme.com

    Availability Zone A Availability Zone B

    Elastic IP A Elastic IP B

    ApacheApache

    TomcatTomcat

    TomcatTomcat

    MySQL(Master)

    MySQL(slave)

    Chris Richardson Running Java applications on Amazon EC2 Slide 49

    EBS Volume

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    50/67

    . .

    Chris Richardson Running Java applications on Amazon EC2 Slide 50

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    51/67

    Apply upgrades

    sure that everything works

    Chris Richardson Running Java applications on Amazon EC2 Slide 51

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    52/67

    Use AWS for short-term spikes. .

    handle read-only requests

    E.g. content rendering/transformation

    Chris Richardson Running Java applications on Amazon EC2 Slide 52

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    53/67

    y ur pp Simple Storage Service (S3)

    ores o s o a a

    Eg. Photo sharing website Store mediaHand out URLs to S3 objects

    Simple Queue Service (SQS)

    Hosted queue-based messaging system Alternative to JMS Loosely coupling between systems

    Store data sets Execute queries

    Chris Richardson Running Java applications on Amazon EC2 Slide 53

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    54/67

    JetS3t

    Rich API for accessing S3

    jets3t.dev.java.net/

    yp caAPI for SQS, EC2,

    Sim leDBcode.google.com/p/typica

    SimpleJPA

    Subset of JPA on SimpleDB

    Chris Richardson Running Java applications on Amazon EC2

    pa

    Slide 54

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    55/67

    Using Amazon EC2

    Developing on Amazon EC2

    Deploying on Amazon EC2

    A f ew t h ou h t s ab ou t Gr oov

    Chris Richardson Running Java applications on Amazon EC2 Slide 55

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    56/67

    -

    Java compatible

    Chris Richardson Running Java applications on Amazon EC2 Slide 56

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Getting Groovy code to work

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    57/67

    g y

    =

    for IDE:-

    Limited refactorings

    Chris Richardson Running Java applications on Amazon EC2 Slide 57

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Groovy fans say "write unit

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    58/67

    Groovy fans say write unit

    Groovy

    versus

    When you have typos

    Java

    Chris Richardson Running Java applications on Amazon EC2 Slide 58

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Unit tests don't always catch

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    59/67

    Unit tests don t always catch

    rr rvoid testPollStatus_discoveringNewServer() {

    mockEC2RequestExecutor.demand.execu teRequs t {params ->.

    }

    def mockEC2Server = new MockFor(EC2Server.class).

    mockEC2RequestExecutor.use {

    ec2 = new EC2(awsProperties)ec2.pollStatus()

    assertEquals 1, ec2.servers.size()

    public class EC2 {

    }}

    public pollStatus() {def params = ['Action':

    'DescribeInstances']def p =

    class EC2RequestExecutor {

    public Node execu teReques t (Mapparameters) {

    ..

    }}

    Chris Richardson Running Java applications on Amazon EC2

    }

    Same typo in test and in code

    Slide 59

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    60/67

    : v pimport javax.crypto.Mac;import javax.crypto.spec.SecretKeySpec;

    class EC2RequestExecutor {

    Log logger = LogFactory.getLog(getClass())

    Java-like syntax

    Use Java libraries

    public String calculateRFC2104HMAC(String data, String key) {try {SecretKeySpec signingKey = new SecretKeySpec(key.getBytes("UTF8"),

    _ _Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM)mac.init(signingKey)byte[] rawHmac = mac.doFinal(data.getBytes())return new String(Base64.encodeBase64(rawHmac))

    }

    catch (Exception e) {throw new RuntimeException("Failed to generate HMAC : ", e)

    }

    Chris Richardson Running Java applications on Amazon EC2

    Slide 60

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

    Groovy is concise and

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    61/67

    y

    xpr vdef configureAsMaster() {

    writeFile fileName: "/etc/my.cnf", templateName: "/templates/master.my.cnf"

    restartService "mysqld"

    exec command: "mysql -u root"," " No arens,

    templateArgs: [schemaSpec: schemaSpec]

    executeSchemaScripts()}

    Keyword parameters

    class TomcatServer { tomcatServer.contextsdef getContexts() {

    webApps.context}

    }

    o ge

    Chris Richardson Running Java applications on Amazon EC2 Slide 61

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    62/67

    def sortServers(servers) {

    servers.sort {a, b -> a.instanceId b.instanceId}

    public EC2Server findInstance(String instanceId) {

    def server = servers.find instanceId == it.instanceIdif (server)return server

    else throw new RuntimeException(.)}

    Chris Richardson Running Java applications on Amazon EC2 Slide 62

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    63/67

    i-4ef21327

    ami-3795705e

    def client = new HttpClient()def responseStream =

    pending

    .def parser = new XmlParser(false, false)def response = parser.parseText(responseStream)

    =

    . . .new EC2Server(this, awsProperties, ssh,

    it.instanceId[0].text(),it.instanceState[0].children()[1].value()[0])

    Chris Richardson Running Java applications on Amazon EC2 Slide 63

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    64/67

    def schemaScript = """

    DROP SCHEMA IF EXISTS ${schemaSpec.name};CREATE SCHEMA ${schemaSpec.name};

    """

    String process(String templateName, Map params) {InputStream stream = getClass().getResourceAsStream(templateName)def engine = new groovy.text.SimpleTemplateEngine()engine.createTemplate(new InputStreamReader(stream)).make(params).toString()

    }

    ProxyPass /$it balancer://mycluster/$it stickysession=jsessionid

    BalancerMember ajp://${it.hostPrivateDnsName}:8009

    route=${it.jvmRoute} min=1 keepalive=On retry=5

    Chris Richardson Running Java applications on Amazon EC2

    %>

    Slide 64

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    65/67

    def report(String path, hosts, cpuCount, threadCount) {def builder = new groovy.xml.MarkupBuilder(new OutputStreamWriter(new FileOutputStream(path)))builder. er fo rm a n ceRe o rtcpus cpuCountt h reads threadCount

    hosts.entrySet().each { hostEntry ->hos t {n a m e hostEntry.key

    . .}}reques t s {timings.entrySet().sort{ a, b-> a.key b.key}.each{ pair ->reques t {

    10

    database

    3.27

    .ar t pair.value.average()e r r o r s pair.value.errorPercentage()

    }}

    }

    tomcat0

    94.32

    e ura on a ue = oa en me - s ar me .dura t i on durationValue

    def tpsValue = transactionCount/ durationValuet p s tpsValuear t averageResponseTime()

    }

    557.943

    10.753786677133686

    916.6578333333

    Chris Richardson Running Java applications on Amazon EC2

    }

    Slide 65

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    66/67

    Cloud Computing

    Pay as you go no upfront investment/commitmentrequired

    Easil scale u down

    Cloud Tools Easy deployment and testing from Maven and Grails

    Confi ure multi le clusters Run JMeter tests in parallel

    Using Groovy Has some nice features Dynamic language features are double-edged sword We need better statically typed languages

    Chris Richardson Running Java applications on Amazon EC2 Slide 66

    Copyright 2008, Chris RichardsonColorado Software Summit: October 19 24, 2008

  • 7/31/2019 deployingjavaapplicationsonec2-1226335236709628-9

    67/67

    Download Cloud Tools today:

    http://code.google.com/p/cloudtools

    Send email:

    [email protected]

    Visit my website:

    http://www.chrisrichardson.net

    Talk to me about consulting and

    Chris Richardson Running Java applications on Amazon EC2

    ra n ng

    Slide 67