Transcript
Page 1: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Building Highly Scalable Java Applications on Windows AzureDavid [email protected]/dachou

Page 2: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Agenda

• Overview of Windows Azure

• Java How-to

• Architecting for Scale

> Introduction

Page 3: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

What is Windows Azure?

• A cloud computing platform (as-a-service)

– on-demand application platform capabilities

– geo-distributed Microsoft data centers

– automated, model-driven services provisioning and management

• You manage code, data, content, policies, service models, etc.– not servers (unless you want to)

• We manage the platform– application containers and services, distributed storage systems

– service lifecycle, data replication and synchronization

– server operating system, patching, monitoring, management

– physical infrastructure, virtualization networking

– security

– “fabric controller” (automated, distributed service management system)

> Azure Overview

Page 4: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Anatomy of a Windows Azure instance

Guest VMGuest VMGuest VMHost VMMaintenance OS,Hardware-optimized hypervisor

> Azure Overview > Anatomy of a Windows Azure instance

The Fabric Controller communicates with every server within the Fabric. It manages Windows Azure, monitors every application, decides where new applications should run – optimizing hardware utilization.

Storage – distributed storage systems that are highly consistent, reliable, and scalable.

Compute – instance types: Web Role & Worker Role. Windows Azure applications are built with web role instances, worker role instances, or a combination of both.

Each instance runs on its own VM (virtual machine) and local transient storage; replicated as needed

HTTP/HTTPS

Page 5: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Application Platform Services

> Azure Overview > Application Platform Services

StorageDynamic Tabular Data

BlobsMessage Queues

Distributed File System

Content Distribution

DataTransact-

SQL

Data Synchronizati

on

Relational Database

ADO.NET, ODBC, PHP

Integration Messasging RegistryService Bus

SecurityClaims-Based

Identity

Federated Identities

Secure Token

Service

Declarative Policies

MarketplaceApplicationMarketplac

e

Information Marketplac

e

FrameworksWorkflow Hosting

Distributed Cache

Services Hosting

Compute C / C++Win32 VHD

On-Premises Bridging

Networking

Page 6: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Application Platform Services

> Azure Overview > Application Platform Services

Compute

Storage

DataRelational Database

Integration

Security

Marketplace

Frameworks

Table Storage

Blob Storage

Queue DriveContent Delivery Network

VM Role

Networking Connect

ApplicationsDataMarket

Access Control

Service Bus

Composite App

Caching

Web Role Worker Role

ReportingDataSync

IntegrationConnect(BizTalk)

Page 7: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

How this may be interesting to you

• Not managing and interacting with server OS– less work for you

– don’t have to care it is “Windows Server” (you can if you want to)

– but have to live with some limits and constraints

• Some level of control– process isolation (runs inside your own VM/guest OS)

– service and data geo-location

– allocated capacity, scale on-demand

– full spectrum of application architectures and programming models

• You can run Java!– plus PHP, Python, Ruby, MySQL, memcached, etc.

– and eventually anything that runs on Windows

> Azure Overview

Page 8: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Java and Windows Azure

• Provide your JVM– any version or flavor that runs on Windows

• Provide your code– no programming constraints (e.g., whitelisting libraries, execution time limit,

multi-threading, etc.)

– use existing frameworks

– use your preferred tools (Eclipse, emacs, etc.)

• Windows Azure “Worker Role” sandbox– standard user (non-admin privileges; “full trust” environment)

– native code execution (via launching sub-processes)

– service end points (behind VIPs and load balancers)

> Java How-To

Page 9: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

• Worker Role (using scripts)– script-based installation and execution

– automated, need scripts

• Worker Role (using C# boot-strapping)– fabric sandbox native deployment

– automated, need additional code

• VM Role– host your own pre-configured Windows Server 2008 R2 Enterprise x64 VM

image

– automated, full control

– available shortly (in beta)

• Manual – remote-desktop

– loses automated provisioning, service lifecycle management, fault-tolerance, etc.

Deployment Options

> Java How-To > Deployment

Page 10: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Running Tomcat in Windows Azure

Service Instance

Service Instance

Worker Role

RoleEntry Point

Sub-Process

JVM

Tomcat

server.xmlCatalina

Fabric Controller

Load Balancer

TableStorage

BlobStorage

Queue

ServiceBus

Access Control

SQL Database

new Process()

bind port(x)

htt

p:/

/in

stan

ce:x

htt

p:/

/in

stan

ce:y

listen port(x)

http://app:80

getruntimeinfo

index.jsp

> Java How-To > Tomcat (SDK 1.2-based)

Page 11: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

• Boot-strapping code in WorkerRole.run()

• Service end point(s) in ServiceDefinition.csdef

Running Jetty in Windows Azure

> Java How-To > Jetty (SDK 1.2-based)

string response = ""; try {     System.IO.StreamReader sr;     string port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpIn"].IPEndpoint.Port.ToString();     string roleRoot = Environment.GetEnvironmentVariable("RoleRoot");     string jettyHome = roleRoot + @"\approot\app\jetty7";     string jreHome = roleRoot + @"\approot\app\jre6";     Process proc = new Process();     proc.StartInfo.UseShellExecute = false;     proc.StartInfo.RedirectStandardOutput = true;     proc.StartInfo.FileName = String.Format("\"{0}\\bin\\java.exe\"", jreHome);     proc.StartInfo.Arguments = String.Format("-Djetty.port={0} -Djetty.home=\"{1}\" -jar \"{1}\\start.jar\"", port, jettyHome);     proc.EnableRaisingEvents = false;     proc.Start();     sr = proc.StandardOutput;     response = sr.ReadToEnd(); } catch (Exception ex) {     response = ex.Message;     Trace.TraceError(response); }

<Endpoints> <InputEndpoint name="HttpIn" port="80" protocol="tcp" /> </Endpoints>

Page 12: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

• Execute startup script in ServiceDefinition.csdef

• Service end point(s) in ServiceDefinition.csdef

Running Jetty with admin access + fixed ports

> Java How-To > Jetty (SDK 1.3-based)

<Startup> <Task commandLine=“runme.cmd" executionContext=“elevated" TaskType=“background"> </Task> </Startup>

<Endpoints> <InputEndpoint name="HttpIn" protocol=“http" port="80" localPort="80" />

</Endpoints>

Page 13: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

• Execute startup script in ServiceDefinition.csdef

• Service end point(s) in ServiceDefinition.csdef

Running GlassFish

> Java How-To > GlassFish (using script; SDK 1.3-based)

<Startup> <Task commandLine=“Run.cmd" executionContext=“limited" TaskType=“background">

</Task> </Startup>

<Endpoints> <InputEndpoint name="Http_Listener_1" protocol=“tcp" port="80" localPort="8080" /> <InputEndpoint name="Http_Listener_2" protocol=“tcp" port="8181" localPort="8181" /> <InputEndpoint name=“Admin_Listener" protocol=“tcp" port=“4848" localPort=“4848" /> <InputEndpoint name=“JMX_Connector_Port" protocol=“tcp" port=“8686" localPort=“8686" /> <InputEndpoint name=“Remote_Debug_Port" protocol=“tcp" port=“9009" localPort=“9009" /> </Endpoints>

Page 14: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Running GlassFish in Windows Azure

Service Instance

Service Instance

Worker Role

Sub-Process

JVM GlassFish

Fabric Controller

Load Balancer

TableStorage

BlobStorage

Queue

ServiceBus

Access Control

SQL Database

htt

p:/

/in

stan

ce:8

08

0

htt

p:/

/in

stan

ce:8

08

0

http://app:80

script

> Java How-To > GlassFish (SDK 1.3-based)

StartupCommand

Page 15: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Current constraints

Platform– Dynamic networking

• <your app>.cloudapp.net• no naked domain• CNAME re-direct from custom

domain• can declare up to 5 specific ports

be opened, or port ranges; cannot open arbitrary ports

• tcp socket connections terminated if idle for >60 seconds

– Non-persistent local file system• allocate local storage directory• read-only: Windows directory,

machine configuration files, service configuration files

– Stateless application model• round-robin traffic distribution

used dynamic load balancer; no sticky sessions

> Java How-To > Limitations

Java– REST-based APIs to services

• Table Storage – schema-less (noSQL)

• Blob Storage – large files (<200GB block blobs; <1TB page blobs)

• Queues• Service Bus• Access Control

Page 16: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Current tools for Java

Windows Azure– Windows Azure Tools for Eclipse/Java

• Multiple Java app servers• Any Windows-based JRE• http://www.windowsazure4e.org/

– Windows Azure SDK for Java• Java classes for Windows Azure

Blobs, Tables & Queues (for CRUD operations)

• Helper Classes for HTTP transport, AuthN/AuthZ, REST & Error Management

• Manageability, Instrumentation & Logging support

• Support for storing Java sessions in Azure Table Storage

• http://www.windowsazure4j.org/

– Windows Azure Starter Kit for Java• Ant-based package & deployment

tool• http://

wastarterkit4java.codeplex.com/

> Java How-To > Support for Java

SQL Azure– Microsoft JDBC Driver 3.0

• Type 4 JDBC driver

– Supports TDS & OData

– Interoperability using REST• Wrap SQL Azure with WCF Data

Services• Restlet extension for OData

Windows Azure AppFabric– App Fabric SDK for Java

• http://www.jdotnetservices.com/

Solution Accelerators– Tomcat

– Jetty

– GlassFish

– etc.

Page 17: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Additional Cloud Integration/Interop Options

Cloud On-premises

Data SynchronizationSQL Azure Data Sync

Application-layer Connectivity &

Messaging AppFabric Service Bus

Security & Federated IdentityAppFabric Access Control

Secure Network Connectivity

Virtual Network Connect

> Cloud Scenarios

Page 18: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Facebook (2009)

• +200B pageviews /month

• >3.9T feed actions /day

• +300M active users

• >1B chat mesgs /day

• 100M search queries /day

• >6B minutes spent /day (ranked #2 on Internet)

• +20B photos, +2B/month growth

• 600,000 photos served /sec

• 25TB log data /day processed thru Scribe

• 120M queries /sec on memcache

> Architecting for Scale

Size matters

Twitter (2009)

• 600 requests /sec

• avg 200-300 connections /sec; peak at 800

• MySQL handles 2,400 requests /sec

• 30+ processes for handling odd jobs

• process a request in 200 milliseconds in Rails

• average time spent in the database is 50-100 milliseconds

• +16 GB of memcached

Google (2007)

• +20 petabytes of data processed /day by +100K MapReduce jobs

• 1 petabyte sort took ~6 hours on ~4K servers replicated onto ~48K disks

• +200 GFS clusters, each at 1-5K nodes, handling +5 petabytes of storage

• ~40 GB /sec aggregate read/write throughput across the cluster

• +500 servers for each search query < 500ms

• >1B views / day on Youtube (2009)

Myspace (2007)

• 115B pageviews /month

• 5M concurrent users @ peak

• +3B images, mp3, videos

• +10M new images/day

• 160 Gbit/sec peak bandwidth

Flickr (2007)

• +4B queries /day

• +2B photos served

• ~35M photos in squid cache

• ~2M photos in squid’s RAM

• 38k req/sec to memcached (12M objects)

• 2 PB raw storage

• +400K photos added /daySource: multiple articles, High Scalabilityhttp://highscalability.com/

Page 19: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

• Common characteristics– synchronous processes

– sequential units of work

– tight coupling

– stateful

– pessimistic concurrency

– clustering for HA

– vertical scaling

Traditional scale-up architecture

> Architecting for Scale > Vertical Scaling

app serverweb data store

units of work

web data store

Page 20: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

Traditional scale-up architecture

> Architecting for Scale > Vertical Scaling

web

data storeweb

• To scale, get bigger servers– expensive

– has scaling limits

– inefficient use of resources

Page 21: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

data storeapp server

Traditional scale-up architecture

> Architecting for Scale > Vertical Scaling

app serverweb

web

• When problems occur– bigger failure impact

Page 22: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Traditional scale-up architecture

> Architecting for Scale > Vertical Scaling

app serverweb

data storeweb

• When problems occur– bigger failure impact

– more complex recovery

Page 23: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Use more pieces, not bigger pieces

LEGO 10179 Ultimate Collector's Millennium Falcon• 33 x 22 x 8.3 inches (L/W/H)• 5,195 pieces

LEGO 7778 Midi-scale Millennium Falcon• 9.3 x 6.7 x 3.2 inches (L/W/H) • 356 pieces

> Architecting for Scale > Horizontal scaling

Page 24: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

Scale-out architecture

> Architecting for Scale > Horizontal scaling

app serverweb data store

• Common characteristics– small logical units of work

– loosely-coupled processes

– stateless

– event-driven design

– optimistic concurrency

– partitioned data

– redundancy fault-tolerance

– re-try-based recoverabilityweb data store

Page 25: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

app server

app server

app server

Scale-out architecture

> Architecting for Scale > Horizontal scaling

app serverweb data store

web

web

web data store

web

web

• To scale, add more servers– not bigger servers

data store

data store

data store

data store

Page 26: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

app server

app server

app server

app server

Scale-out architecture

> Architecting for Scale > Horizontal scaling

web data store

web

web

web data store

web

web

• When problems occur– smaller failure impact

– higher perceived availability

data store

data store

data store

data store

Page 27: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

app server

Scale-out architecture

> Architecting for Scale > Horizontal scaling

app serverweb data store

web

web app server

web data store

web

web

• When problems occur– smaller failure impact

– higher perceived availability

– simpler recovery

data store

data store

data store

data store

Page 28: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

• Scalable performance at extreme scale– asynchronous processes

– parallelization

– smaller footprint

– optimized resource usage

– reduced response time

– improved throughput

app server

app server

Scale-out architecture + distributed computing

> Architecting for Scale > Horizontal scaling

app serverweb data store

web

web app server

web data store

web

web

data store

data store

data store

data store

parallel tasks

async tasks

perceived response time

Page 29: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

app server

• When problems occur– smaller units of work

– decoupling shields impact

app server

app server

Scale-out architecture + distributed computing

> Architecting for Scale > Horizontal scaling

app serverweb data store

web

web app server

web data store

web

web

data store

data store

data store

data store

Page 30: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

app server

• When problems occur– smaller units of work

– decoupling shields impact

– even simpler recovery

app server

app server

Scale-out architecture + distributed computing

> Architecting for Scale > Horizontal scaling

app serverweb data store

web

web app server

web data store

web

web

data store

data store

data store

data store

Page 31: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Live Journal (from Brad Fitzpatrick, then Founder at Live Journal, 2007)

> Architecting for Scale > Cloud Architecture Patterns

Partitioned Data

DistributedCache

Web Frontend

Distributed Storage

Apps & Services

Page 32: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Flickr (from Cal Henderson, then Director of Engineering at Yahoo, 2007)

> Architecting for Scale > Cloud Architecture Patterns

Partitioned Data DistributedCache

Web Frontend

Distributed Storage

Apps & Services

Page 33: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

SlideShare (from John Boutelle, CTO at Slideshare, 2008)

> Architecting for Scale > Cloud Architecture Patterns

Partitioned Data

Distributed Cache

WebFrontend

Distributed Storage

Apps &Services

Page 34: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Twitter (from John Adams, Ops Engineer at Twitter, 2010)

> Architecting for Scale > Cloud Architecture Patterns

PartitionedData

DistributedCache

WebFrontend

DistributedStorage

Apps &Services

Queues

AsyncProcesses

Page 35: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

2010 stats (Source: http://www.facebook.com/press/info.php?statistics)

– People• +500M active users• 50% of active users log on in any given

day• people spend +700B minutes /month

– Activity on Facebook• +900M objects that people interact with• +30B pieces of content shared /month

– Global Reach• +70 translations available on the site• ~70% of users outside the US• +300K users helped translate the site

through the translations application

– Platform• +1M developers from +180 countries• +70% of users engage with

applications /month• +550K active applications• +1M websites have integrated with

Facebook Platform • +150M people engage with Facebook on

external websites /month

> Architecting for Scale > Cloud Architecture Patterns

Facebook(from Jeff Rothschild, VP Technology at Facebook, 2009)

PartitionedData

DistributedCache

WebFrontend

DistributedStorage

Apps &Services

ParallelProcesses

AsyncProcesses

Page 36: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Windows Azure platform components

Apps & Services

Services

Web Frontend

QueuesDistributed Storage

DistributedCache

Partitioned Data

> Architecting for Scale > Cloud Architecture Patterns

Content Delivery Network

Load Balancer

IISWeb Server

VM Role

Worker Role

Web Role

Caching

Queues Access Control

Composite App

Blobs

Relational Database

Tables

Drives Service Bus

Reporting

DataSync

Virtual NetworkConnect

Page 37: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Fundamental concepts

> Architecting for Scale

• Vertical scaling still works

Page 38: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Fundamental concepts

> Architecting for Scale

• Horizontal scaling for cloud computing

• Small pieces, loosely coupled

• Distributed computing best practices– asynchronous processes (event-driven design)

– parallelization

– idempotent operations (handle duplicity)

– de-normalized, partitioned data (sharding)

– shared nothing architecture

– optimistic concurrency

– fault-tolerance by redundancy and replication

– etc.

Page 39: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Hybrid architectures

> Architecting for Scale > Fundamental Concepts

Scale-out (horizontal)– BASE: Basically Available, Soft

state, Eventually consistent

– focus on “commit”

– conservative (pessimistic)

– shared nothing

– favor extreme size

– e.g., user requests, data collection & processing, etc.

Scale-up (vertical)– ACID: Atomicity, Consistency,

Isolation, Durability

– availability first; best effort

– aggressive (optimistic)

– transactional

– favor accuracy/consistency

– e.g., BI & analytics, financial processing, etc.

Most distributed systems employ both approaches

Page 40: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

Lastly…

Windows Azure is an open & interoperable cloud platform

Microsoft is committed to Java, and we are on a journey – please give us your feedback & participate in open source projects

Diverse Choice of Development Tools for Java Developers– Eclipse Tools for Windows Azure – Write Modern Cloud Application

– Tomcat Solutions Accelerator

– Admin Access & VM Role

– Windows Azure Platform SDKs for Java Developers• Windows Azure SDK (Storage, Diagnostics & Service Management)• App Fabric SDK (Service Bus & Access Control Services)• Restlet extension for OData (Java)

For more information:– http://windowsazure.com/interop

– http://www.interoperabilitybridges.com

> Wrap-Up

Page 41: CloudConnect 2011 - Building Highly Scalable Java Applications on Windows Azure

© 2010 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.

Thank you!

David [email protected]/dachou


Recommended