Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Java on Windows Azure (Cloud Computing Expo 2010)
1. Building Highly Scalable
Java Applications
on Windows Azure
David Chou
david.chou@microsoft.com
blogs.msdn.com/dachou
2. Agenda
• Overview of Windows Azure
• Java How-to
• Architecting for Scale
> Introduction
3. 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
4. Anatomy of a Windows Azure instance
Guest VM
Guest VM
Guest VM
Host VM
Maintenance 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
5. Application Platform Services
> Azure Overview > Application Platform Services
Storage
Dynamic
Tabular Data
Blobs
Message
Queues
Distributed File
System
Content
Distribution
Data Transact-SQL
Data
Synchronization
Relational
Database
ADO.NET,
ODBC, PHP
Integration Registry RegistryService Bus
Security
Claims-Based
Identity
Federated
Identities
Secure Token
Service
Declarative
Policies
Marketplace
Application
Marketplace
Information
Marketplace
Frameworks
Workflow
Hosting
Distributed
Cache
Services
Hosting
Compute C/C++
Win32 VHD
On-Premises
Bridging
Networking
6. Application Platform Services
> Azure Overview > Application Platform Services
Compute
Storage
Data
Relational
Database
Integration
Security
Marketplace
Frameworks
Table Storage Blob Storage Queue Drive
Content Delivery
Network
VM Role
Networking Connect
ApplicationsDataMarket
Access
Control
Service Bus
Composite
App
Caching
Web Role Worker Role
ReportingDataSync
Integration
Connect
(BizTalk)
7. 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
8. 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.)
• File-based deployment
– no OS-level installation (conceptually extracting a tar/zip with run.bat)
• 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
9. Some boot-strapping in C#
• Kick-off process in WorkerRole.run()
– get environment info (assigned end point ports, file locations)
– set up local storage (if needed; for configuration, temp files, etc.)
– configure diagnostics (Windows Server logging subsystem for monitoring)
– launch sub-process(es) to run executable (launch the JVM)
• Additional hooks (optional)
– Manage role lifecycle
– Handle dynamic configuration changes
• Free tools
– Visual Studio Express
– Windows Azure Tools for Visual Studio
– Windows Azure Tools for Eclipse/Java (CTP 2010H2)
– Windows Azure SDK
> Java How-To > Boot-strapping
10. Running Tomcat in Windows Azure
Service Instance
Service Instance
Worker Role
RoleEntry
Point
Sub-Process
JVM
Tomcat
server.xmlCatalina
Fabric
Controller
Load
Balancer
Table
Storage
Blob
Storage
Queue
Service
Bus
Access
Control
SQL
Database
new Process()
bind port(x)
http://instance:x
http://instance:y
listen port(x)
http://app:80
get
runtime
info
index.jsp
> Java How-To > Tomcat
11. • Boot-strapping code in WorkerRole.run()
• Service end point(s) in ServiceDefinition.csdef
Running Jetty in Windows Azure
> Java How-To > Jetty
string response = "";
try {
System.IO.StreamReader sr;
string port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpIn"].IPEndpoint.Port.ToString();
string roleRoot = Environment.GetEnvironmentVariable("RoleRoot");
string jettyHome = roleRoot + @"approotappjetty7";
string jreHome = roleRoot + @"approotappjre6";
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.FileName = String.Format(""{0}binjava.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>
12. Current constraints
Platform
– Dynamic networking
• <your app>.cloudapp.net
• no naked domain
• CNAME re-direct from custom domain
• sending traffic to loopback addresses not
allowed and cannot open arbitrary ports
– No OS-level access
– Non-persistent local file system
• allocate local storage directory
• read-only: Windows directory, machine
configuration files, service configuration
files
– Available registry resources
• read-only: HKEY_CLASSES_ROOT,
HKEY_LOCAL_MACHINE, HKEY_USERS,
HKEY_CURRENT_CONFIG
• full access: HKEY_CURRENT_USER
> Java How-To > Limitations
Java
– Sandboxed networking
• NIO (java.nio) not supported
• engine and host-level clustering
• JNDI, JMS, JMX, RMI, etc.
• need to configure networking
– Non-persistent local file system
• logging, configuration, etc.
– 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
13. Improvements on the way
Platform
– Networking modeling
• well known ports (or fixed VM ports)
• port ranges (for inbound traffic)
• load balancer control (on/off)
• network filters (inter-role access control)
– Improved automation
• startup tasks (execute OS-level scripts)
• role plugins (remote desktop, virtual
network, diagnostics, etc.)
– Full IIS
• multiple websites in same role
• virtual directories
• applications, modules
– Admin access
• full administrative access to role instances
• reboot/re-image support
> Java How-To > Platform Enhancements (Announced; Not Yet Released)
Java
– Traditional deployment models
• deploy your own Java EE stack
• configure internal networking
– More frameworks, packages, and
extended languages
• verify deployment and configuration
– Solution accelerators
• with bootstrapping and configuration
– Java API support
• Windows Azure SDK v2.0 (announced at
PDC10)
• www.windowsazure4j.org
– Development tools
• Windows Azure Tools for Eclipse/Java
(CTP 2010H2)
14. • Execute startup script in ServiceDefinition.csdef
• Service end point(s) in ServiceDefinition.csdef
Running Jetty with admin access + fixed ports
> Java How-To > Platform Enhancements (Announced; Not Yet Released)
<Startup>
<Task commandLine=“runme.cmd" executionContext=“elevated" TaskType=“background">
</Task>
</Startup>
<Endpoints>
<InputEndpoint name="HttpIn" protocol=“http" port="80" localPort="80" />
</Endpoints>
15. Running Fujitsu Interstage App Server
JavaEE 6
– Based on Glassfish 3.1
– Complete JavaEE execution environment
– Service Integrator SOA Platform
> Java How-To > Platform Enhancements (Announced; Not Yet Released)
Windows Azure 1.3 SDK
– Loopback adapter is no longer blocked
– Enabled Java NIO
– Enabled Port Ranges: for “inbound
traffic” (as opposed to 5 in the past)
Service end point(s) in ServiceDefinition.csdef
16. • Worker Role
– fabric sandbox native deployment
– automated, need additional code
– available now
• Admin Access
– script-based installation and execution
– automated, need scripts
– available shortly (not yet released)
• VM Role
– host your own pre-configured VM image
– automated, full control
– available later (not yet released)
Deployment Options
> Java How-To > Platform Enhancements (Announced; Not Yet Released)
17. • Runtime
– Multiple Java app servers
– Any Windows-based JRE
• Supports
– Windows Azure Storage
– Windows Azure Drive
– Windows Azure AppFabric
– SQL Azure
• One-click cloud deployment
• Integrated diagnostics,
monitoring, and logging
Windows Azure Tools for Eclipse/Java
> Java How-To > Platform Enhancements (Announced; Not Yet Released)
18. Accessing SQL Azure from Java
> Java How-To > SQL Azure
• SQL Azure Database
– Full relational Database as a Service
• Supports TDS & OData
• Direct connectivity to SQL Azure
– Connect with JDBC/ODBC using the latest driver
– Eclipse tooling support
• Interoperability using REST
– Easily wrap SQL Azure with WCF Data Services
– Restlet extension for OData (Java)
• Committed to OSS support and app compatibility
19. Accessing Windows Azure Storage from Java
> Java How-To > Windows Azure Storage
• Windows Azure SDK for Java
– Enables Java developers to develop against
Windows Azure Storage & Service Management
infrastructure using familiar & consistent
programming model
• Features
– Set of Java classes for Windows Azure Blobs,
Tables & Queues (for CRUD operations) & Service
Management
– Helper Classes for HTTP transport, AuhN/AuthZ,
REST & Error Management
– Manageability, Instrumentation & Logging(log4j)
• Open Source Project site:
– Developed by our Partner Soyatec
– www.windowsazure4j.org
Windows Azure SDK for Java
Blobs, Tables,
Queues
Manageability,
Instrumentation,
logging
Helper for Http,
Auth, REST, Error
Your Java application
REST
20. Accessing Windows Azure AppFabric from Java
> Java How-To > Windows Azure AppFabric
• Usage Patterns
– Extends reach of applications securely through the cloud
– Securely integrates partners outside of org boundaries
– Extends reach of on-premises web services layer
– Enables leveraging cloud quickly without having to rewrite apps
• App Fabric SDK for Java Developers
– Open source software development kit (SDK)
– a set of libraries, tools, Prescriptive guidance
– sample applications
• Open Source Project site:
– Developed by our partner Persistent Systems Limited
– www.jdotnetservices.com
22. 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 /day
Source: multiple articles, High Scalability
http://highscalability.com/
23. 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
24. 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
25. data storeapp server
Traditional scale-up architecture
> Architecting for Scale > Vertical Scaling
app serverweb
web
• When problems occur
– bigger failure impact
26. Traditional scale-up architecture
> Architecting for Scale > Vertical Scaling
app serverweb
data storeweb
• When problems occur
– bigger failure impact
– more complex recovery
27. 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
28. 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 recoverability
web data store
29. 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
30. 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
31. 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
32. 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
33. 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
34. 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
35. Live Journal (from Brad Fitzpatrick, then Founder at Live Journal, 2007)
> Architecting for Scale > Cloud Architecture Patterns
Partitioned Data
Distributed
Cache
Web Frontend
Distributed Storage
Apps & Services
36. Flickr (from Cal Henderson, then Director of Engineering at Yahoo, 2007)
> Architecting for Scale > Cloud Architecture Patterns
Partitioned Data Distributed
Cache
Web Frontend
Distributed Storage
Apps & Services
37. SlideShare (from John Boutelle, CTO at Slideshare, 2008)
> Architecting for Scale > Cloud Architecture Patterns
Partitioned Data
Distributed Cache
Web
Frontend
Distributed Storage
Apps &
Services
38. Twitter (from John Adams, Ops Engineer at Twitter, 2010)
> Architecting for Scale > Cloud Architecture Patterns
Partitioned
Data
Distributed
Cache
Web
Frontend
Distributed
Storage
Apps &
Services
Queues
Async
Processes
39. 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)
Partitioned
Data
Distributed
Cache
Web
Frontend
Distributed
Storage
Apps &
Services
Parallel
Processes
Async
Processes
40. Windows Azure platform components
Apps & Services
Services
Web Frontend
QueuesDistributed Storage
Distributed
Cache
Partitioned Data
> Architecting for Scale > Cloud Architecture Patterns
Content Delivery
Network
Load Balancer
IIS
Web Server
VM Role
Worker Role
Web Role
Caching
Queues Access Control
Composite App
Blobs
Relational
Database
Tables
Drives Service Bus
Reporting
DataSync
Virtual Network
Connect
42. 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.
43. Partitioned data
> Architecting for Scale > Fundamental Concepts
Shared nothing architecture
– transaction locality (partition based on an
entity that is the “atomic” target of
majority of transactional processing)
– loosened referential integrity (avoid
distributed transactions across shard and
entity boundaries)
– design for dynamic redistribution and
growth of data (elasticity)
Cloud computing friendly
– divide & conquer
– size growth with virtually no limits
– smaller failure surface
Windows Azure platform services
– Table Storage Service
– SQL Azure
– AppFabric Caching (coming soon)
– SQL Azure DB federation (coming soon)
Web Role
QueuesWeb Role
Web Role
Worker Role
Relational
Database
Relational
Database
Relational
Database
Web Role
read
write
44. Asynchronous processes & parallelization
> Architecting for Scale > Fundamental Concepts
Defer work as late as possible
– return to user as quickly as possible
– event-driven design (instead of request-
driven)
Cloud computing friendly
– distributes work to more servers (divide &
conquer)
– smaller resource usage/footprint
– smaller failure surface
– decouples process dependencies
Windows Azure platform services
– Queue Service
– AppFabric Service Bus
– inter-node communication
Worker Role
Web Role
Queues
Service BusWeb Role
Web Role
Web Role
Worker Role
Worker Role
Worker Role
45. Idempotent operations
> Architecting for Scale > Fundamental Concepts
Repeatable processes
– allow duplicates (additive)
– allow re-tries (overwrite)
– reject duplicates (optimistic locking)
– stateless design
Cloud computing friendly
– resiliency
Windows Azure platform services
– Queue Service
– AppFabric Service Bus
Worker Role
Service Bus Worker Role
Worker Role
46. At most two of these properties for any shared-data system
C A
P
Consistency + Availability
• High data integrity
• Single site, cluster database, LDAP, xFS file system, etc.
• 2-phase commit, data replication, etc.
C A
P
Consistency + Partition
• Distributed database, distributed locking, etc.
• Pessimistic locking, minority partition unavailable, etc.
C A
P
Availability + Partition
• High scalability
• Distributed cache, DNS, etc.
• Optimistic locking, expiration/leases, etc.
CAP (Consistency, Availability, Partition) Theorem
> Architecting for Scale > Fundamental Concepts
Source: “Towards Robust Distributed Systems”, Dr. Eric A. Brewer, UC Berkeley
47. 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
48. 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
Microsoft's Windows Azure platform is a virtualized and abstracted application platform that can be used to build highly scalable and reliable applications, with Java. The environment consists of a set of services such as NoSQL table storage, blob storage, queues, relational database service, internet service bus, access control, and more. Java applications can be built using these services via Web services APIs, and your own Java Virtual Machine, without worrying about the underlying server OS and infrastructure. Highlights of this session will include:
• An overview of the Windows Azure environment
• How to develop and deploy Java applications in Windows Azure
• How to architect horizontally scalable applications in Windows Azure
To build for big scale – use more of the same pieces, not bigger pieces; though a different approach may be needed