java tech day 2009 - developing cloud computing applications with java

39
Developing Cloud Computing Applications with Java Shlomo Swidler CTO, MyDrifts.com [email protected] om

Upload: shlomo-swidler

Post on 11-May-2015

8.955 views

Category:

Technology


0 download

DESCRIPTION

Challenges faced by developers of cloud-computing applications and Java-based solutions. Including an overview of Google App Engine, Amazon Web Services, and sample Java code demonstrating design patterns that will scale in the cloud.

TRANSCRIPT

Page 1: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing Cloud Computing Applications with Java

Shlomo SwidlerCTO, [email protected]

Page 2: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing Cloud Computing Applications with

Java Overview of Cloud Computing

Amazon’s Cloud Platform

Google’s Cloud Platform

Application Development Challenges Posed by the Cloud…… and Java Solutions

222 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 3: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

About Me

CTO & co-Founder Music marketing on social networks Patent-pending targeting technology Java, MySQL, auto-scaling & cloud-based

Active in the Cloud Computing community Open Cloud Computing Interface Working Group

(an Open Grid Forum initiative) participant Contributor to Open Source cloud & Java projects

22 June 2009 3Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 4: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Cloud Computing Is…

A style of computing in which dynamically scalable and often virtualized resources are provided as a service over the Internet. Users need not have knowledge of, expertise in, or control over the technology infrastructure in the “cloud” that supports them.

– Wikipedia

422 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 5: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Cloud Computing Is…

A style of computing in which dynamically scalable and often virtualized resources are provided as a service over the Internet. Users need not have knowledge of, expertise in, or control over the technology infrastructure in the “cloud” that supports them.

– Wikipedia

522 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 6: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Cloud Computing Is…

622 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 7: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Cloud Computing Is…

722 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 8: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Cloud Computing Is…

Computing Resources

As a Service Pay-as-you-go or Subscription

822 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Infrastructure Platform Software

Processor LAMP Stack Email

Memory JVM CRM System

Storage Python VM ERP System

Network MapReduce SCM System

Page 9: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Advantages ofCloud Computing

From a Developer’s Perspective:

Pay-as-you-go “utility computing” Saves time Saves $$$

On-demand resource allocation & release

Scalability More on this later

922 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 10: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Risks ofCloud Computing

Security Who else has access to “your” resources ?

Recovery How easy is it ?

Provider lock-in

1022 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 11: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Amazon’s Cloud Platform:Amazon Web Services

Infrastructure-as-a-Service

Processors & Memory Elastic Compute Cloud

“EC2”

Storage Simple Storage Service

“S3” Elastic Block Store

“EBS” SimpleDB database

1122 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

Network Content Delivery

Network CloudFront

Messaging Simple Queue Service

“SQS”

Page 12: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Amazon DashboardElasticFox Firefox plugin

22 June 2009 12Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 13: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing onAmazon’s Cloud

Standard stuff:

Language

Libraries

Communications

Web Servers

Application Servers

Databases

22 June 2009 13Developing Cloud Computing Applications with Java by Shlomo Swidler

Challenges:

Scaling

Suitable for existing applications

Page 14: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Google’s Cloud Platform:Google App Engine

22 June 2009 14Developing Cloud Computing Applications with Java by Shlomo Swidler

Platform-as-a-Service

Language Python Java

Storage JDO or JPA or Datastore

APIs

User Accounts

Email

Image Transformation

Memcached

Cron jobs

Page 15: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Google DashboardGoogle Administration Console

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 15

Page 16: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing onGoogle’s Cloud

Easy stuff:

Scaling

22 June 2009 16Developing Cloud Computing Applications with Java by Shlomo Swidler

Challenges:

Language

Libraries

Communications

Data Storage

Suitable for new, lighter-weight applications

Page 17: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Application Development Challenges Posed by the

Cloud Deploying to the Cloud

Designing for Scalability Web Tier Application Tier Database Tier

22 June 2009 17Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 18: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Application Development Challenges Posed by the

Cloud Deploying to the Cloud

Designing for Scalability Web Tier Application Tier Database Tier

22 June 2009 18Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 19: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Deploying to the Cloud

IaaS platforms Mostly the same as traditional deployment

PaaS & SaaS platforms Custom procedures Custom configurations Custom tools

Google App Engine: Eclipse plug-in

22 June 2009 19Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 20: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Deploying an Application toGoogle App Engine

22 June 2009 20Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 21: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Designing the Application Tier for Scalability

22 June 2009 21Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 22: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Designing the Application Tier for Scalability

Make sure your Storage Tier is optimized Optimize database queries Use in-memory caching

Parallelize operations Use concurrent threads Use the Service Pools design pattern

22 June 2009 22Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 23: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Parallelize withConcurrent Threads

Motivation Allow long-running tasks to proceed without

impacting performance

Java offers the java.util.concurrent package Executor interface Future<T> interface

22 June 2009 23Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 24: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

java.util.concurrent Example: In-Memory Cache Existing implementations such as memcached

Cache shared by all application instances Access is via the network

Application requests an Object from the cache

Time until response is received can vary True of any network operation

Don’t let application code wait…

22 June 2009 24Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 25: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

java.util.concurrent

Exam

ple

: In-M

em

ory

C

ach

eString userId = "visitor01";

String memcachedKey = "userId:" + userId + ".lastLoginDate";

Future<Date> lastLoginDateGetter = MemcachedClient.get(memcachedKey, Date.class);

// perform the rest of the request handling code here

// then, at the end, get the user's last login date

Date lastLoginDate = null;

try {

lastLoginDate = lastLoginDateGetter.get(50, TimeUnit.MILLISECONDS);

} catch (InterruptedException e) {

// someone interrupted the FutureTask

} catch (ExecutionException e) {

// the FutureTask threw an exception

} catch (TimeoutException e) {

// the FutureTask didn't complete within the 50ms time limit

lastLoginDateGetter.cancel(false);

}

// return lastLoginDate to the presentation layer

22 June 2009 25Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 26: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

java.util.concurrent

Exam

ple

: In-M

em

ory

C

ach

e

import java.util.concurrent.Callable;

import java.util.concurrent.Executor;

import java.util.concurrent.Executors;

import java.util.concurrent.Future;

import java.util.concurrent.FutureTask;

public class MemcachedClient {

private static Executor executor = Executors.newFixedThreadPool(1);

public static <T> Future<T> get(String objectKey, Class<T> type) {

final String objectKeyFinal = objectKey;

FutureTask<T> getFromCacheOperation = new FutureTask<T>(

new Callable<T>() {

public T call() {

Object networkResponse = requestObjectOverNetwork(objectKeyFinal);

return (T) networkResponse;

}

}

);

executor.execute(getFromCacheOperation);

return getFromCacheOperation;

}

private static Object requestObjectOverNetwork(String objectKey) {

// network stuff goes in here

}

}

22 June 2009 26Developing Cloud Computing Applications with Java by Shlomo Swidler

Page 27: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Parallelize with Service Pools

Motivation Allow services to scale according to demand Scale up and down

22 June 2009 27Developing Cloud Computing Applications with Java by Shlomo Swidler

Request Queue

Response Queue

Storage

Page 28: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Java Service Pool for Amazon Web Services:

Lifeguard Open source Apache License Version 2.0 http://code.google.com/p/lifeguard/

22 June 2009 28Developing Cloud Computing Applications with Java by Shlomo Swidler

Request Queue

Response Queue

Storage

Page 29: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Lifeguard Framework Framework provides:

Message handling File handling Scaling logic

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 29

Request SQS Queue

Response SQS Queue

S3 Storage

EC

2

Insta

nce

s

Ingestor

ListenerPool Mgr

Config

Page 30: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Lifeguard Framework You provide:

Ingestor Service Pool Manager Configuration

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 30

Request SQS Queue

Response SQS Queue

S3 Storage

EC

2

Insta

nce

s

Ingestor

ListenerPool Mgr

Config

Page 31: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 31

public class ResizeImageIngestor extends IngestorBase {

private static final String ResizeImageWorkflowXML ="<Workflow>" +

"<Service>" +"<Name>ResizeImage</Name>" +"<WorkQueue>ResizeImage-input</WorkQueue>" +

"</Service>" +"</Workflow>";

public ResizeImageIngestor() {

super(ResizeImageIngestorWorkflowXML);

}

public void ingest(File imageFile) {

super.ingest(Collections.singletonList(imageFile));

}

}Ingestor

S3 Storage

Imple

ment th

e In

gesto

r

Page 32: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

22 June 2009 32Developing Cloud Computing Applications with Java by Shlomo Swidler

S3 Storage

Imple

ment th

e S

erv

icepublic class ResizeImageService extends AbstractBaseService {

private static final String ServiceConfigXML ="<ServiceConfig>" +

"<ServiceName>ResizeImage</ServiceName>" +"<WorkQueue>ResizeImage-input</WorkQueue>" +

"</ServiceConfig>";

public ResizeImageService() {super(ServiceConfigXML);

}

public List<File> executeService(File imageFile) {

Image origImage = new Image(imageFile);

File resizedImageFile = resizeImageToFile(origImage);

return Collections.singletonList(resizedImageFile);

}

}

Page 33: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

22 June 2009 33Developing Cloud Computing Applications with Java by Shlomo Swidler

Con

fig

ure

the P

ool M

an

ag

er

Pool Mgr

Config

<ServicePool>

<ServiceName>ResizeImage</ServiceName>

<VMImage>ami-39ba5df0</VMImage>

<WorkQueue>ResizeImage-input</WorkQueue>

<RampUpInterval>1</RampUpInterval>

<RampUpDelay>360</RampUpDelay>

<RampDownInterval>1</RampDownInterval>

<RampDownDelay>480</RampDownDelay>

<MinSize>0</MinSize>

<MaxSize>20</MaxSize>

<QueueSizeFactor>20000</QueueSizeFactor>

</ServicePool>

This configuration defines the SLA for this service

That’s all there is to implement

The framework does all the rest

Page 34: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Service Pool

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 34

Request SQS Queue

Response SQS Queue

S3 Storage

EC

2

Insta

nce

s

Ingestor

ListenerPool Mgr

Config

Pool of service instances dynamically scales with load

Page 35: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Service Pool Pool of service instances dynamically scales with

load

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 35

Page 36: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Service Pool Multiple service pools scale independently

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler

etc.

36

Page 37: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Service Pool Workloads can follow different workflows

Specify the Ingestor’s XML accordingly

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 37

Page 38: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing Cloud Computing Applications with

Java

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 38

Q&A

Page 39: Java Tech Day 2009 - Developing Cloud Computing Applications With Java

Developing Cloud Computing Applications with

Java

22 June 2009 Developing Cloud Computing Applications with Java by Shlomo Swidler 39

Shlomo [email protected]

Thank you!