north east user group tour

58
© All rights reserved. Zend Technologies, Inc . Northeast User Group Tour – April 2011 By Kevin Schroeder Technology Evangelist Zend Technologies

Upload: kevin-schroeder

Post on 17-May-2015

696 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Northeast User Group Tour – April 2011

By Kevin Schroeder

Technology Evangelist

Zend Technologies

Page 2: North east user group tour

©All rights reserved. Zend Technologies, Inc.

About Kevin

Past: Programming/Sys Admin

Current: Technology Evangelist/Author/Composer

@kpschrade

Page 3: North east user group tour

©All rights reserved. Zend Technologies, Inc.

What do we do?

Page 4: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Page 5: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Linux(rpm/web repositories)

IBM i(PTF)

Windows(MSI)

ApplicationPerformance

Acceleration

Optimization

Caching

Reliability &Management

Monitoring

Root-Cause

Configuration

Scale-Out

Clustering

Job Queue

Downloads

Enterprise Enablement

Hot Fixes

Support

Java Bridge

Zend Framework

PHP

Zend Server

Zen

d S

tudio

(Ecl

ipse

-base

d)

Colla

bora

teD

ebug

Pro

file

Test

Page 6: North east user group tour

©All rights reserved. Zend Technologies, Inc.

A quick word on something new…

Page 7: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Page 8: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Wanna try it?1. Go to

http://prerelease.adobe.com/callout/?callid=6C1235C63BDC414896951DDCEC01D5E8

… or go to http://www.eschrade.com/fbphp :-)

2. Email me at [email protected] (this will help expedite your approval)

Page 9: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Things we’re giving away

Page 10: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• 1 Zend Certification Test (you still have to pass it)

• 1 copy of Zend Studio

• ElePHPants

• Books

• Dart Boards

• Little Note Books (the paper kind)

Page 11: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Queuing

Page 12: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Could your PHP apps benefit from being able to process data or execute

asynchronously?

Twtpoll results

Page 13: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Performance Execute logic apart from the main request (asynchronicity)

• Scalability The ability to handle non-immediate logic as resources are

available

Why would you want to queue?

Page 14: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• People often say that performance and scalability are separate things.

This is inaccurate (consider Google)

• Performance is the speed by which a request is executed

• Scalability is the ability of that request to maintain its performance as load/infrastructure increases

Performance & Scalability

Page 15: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• DON’T!!

• You are not Facebook

• You probably won’t be

• Don’t overcomplicate your problems by trying to be

So how do you scale to Facebook size?

Page 16: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Typical anatomy of a PHP Application

| 16

Presentation

Application Control

Database Access

Business Logic

Presentation

Application Control

Business Logic

Presentation

Bad for scala-bility!

Page 17: North east user group tour

©All rights reserved. Zend Technologies, Inc. | Apr 12, 2023

| 17

Presentation

Database Access

Business Logic

Application Control

Something.phtml

Something.phtml

Something.phtml

Something.phtml

Something.phtml

Something.phtml

Something.phtml

Something.phtml

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Something.p

hp

Good for Scalabilit

y

Page 18: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Defined tasks

Loose coupling

Resource discovery

What helps make software scalable?

Page 19: North east user group tour

©All rights reserved. Zend Technologies, Inc.

The Golden Rule of Scalability

“It can probably wait”

Page 20: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Pre-caching data

• Data analysis

• Pre-analysis (predicting where your users will go)

• Data processing

• Pre-calculating (preparing data for the next request)

Data is “out of date” once it leaves the web server

Immediacy is seldom necessary

Asynchronous execution uses

Page 21: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• A sledgehammer can hit a machine Scalability and High Availability are yin and yang

• A site that can’t keep running is not scalable

• A site that can’t scale will fail (if it gets really popular)

• Machines can be added and removed at will Not “cloudy” necessarily

• No single point of failure Data exists in at least two, preferably at least three, places

Characteristics

Page 22: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Waste disk space

• Control usage (don’t let users do anything they want)

• Pre-calculate as much as possible Calculate and cache/store

• Don’t scan large amounts of data

• Keep data processing off the front end servers

• Don’t just cache Don’t let it substitute for thought

Cache hit rates can be meaningless if you have hundreds of cache hits for a request

Considerations

Page 23: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Build a deployment mechanism with NO hardcoded values like directory or resource locations• Make as much as possible configurable/discoverable

• Decouple/Partition Don’t tie everything (relationships and such) into the

database

• Use queues/messaging Stomp interfaces are really good for PHP – Can also use

Java Bridge

Zend_Queue has several interfaces

• Try to use stateless interfaces polling is more scalable than idle connections; introduces

lag

Considerations

Page 24: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Use Cron /w PHP CLI (probably shouldn’t do this)

• Use Gearman

• Use home-grown (don’t do this)

• Use pcntl_fork() (NEVER do this)

• Use Zend Server Job Queue

Options

Page 25: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Gearman* Zend Server Job Queue

FreeLightweightOpen Source(mostly) language agnosticDistributed queuing

Ready to goIntegrates with Event MonitoringIntegrates with Code TracingRuns over a widely known protocolLoad distribution can be accomplished outside of the queue

Your only real options

* I am not an expert on Gearman. Corrections will be taken in the spirit that they are given.

Very cloud friendly

For obvious reasons, I will focus on Zend Server

Page 26: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Schedule jobs in the future

• Set recurring jobs

• Execute immediately, as resources are available (my fav)

• Utilize ZendJobQueue()

Using the Zend Server Job Queue

Page 27: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Job Queue Architecture – Elastic Backend

Users!

Web Server /w

JQ

Web Server /w

JQ

Web Server /w

JQ

Web Server

Web Server

Web Server

Load B

ala

nce

r

• Pros Scale the backend as necessary

Default (easy) mechanism

• Cons Getting the job status requires using a DB

Page 28: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Job Queue Architecture – Elastic Frontend

Users!

Web Server

Web Server

Web Server

Web Server /w

JQ

Web Server /w

JQ

Web Server /w

JQ

Load B

ala

nce

r

• Pros• Easy to communicate with the Job Queue server handling the job

Cons• Requires you to build your own interface

Page 29: North east user group tour

©All rights reserved. Zend Technologies, Inc.

• Create a task-handling controller

• Create an abstract task class Understands the Job Queue

Self contained• If Elastic Backend: connects to localhost

• If Elastic Frontend: connects to load balancer (my preferred), load balanced JQ servers manage themselves

• Execute the task, have it serialize itself and send it to send to the task handler

Kevin’s favorite way to implement it

Page 30: North east user group tour

©All rights reserved. Zend Technologies, Inc.

com\zend\jobqueue\Manager

Handles connecting to the queue and passing results back and forth

com\zend\jobqueue\JobAbstract

Abstract class that a job would be based off of

com\zend\jobqueue\Response

The response from the manager when a job is queued. Contains the server name and job number

org\eschrade\jobs\Scandir

The actual job that scans the directory

org\eschrade\jobs\ScandirResult

An object that represents the data found

Classes involved in the demo

Page 31: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Create job and set data

Execute job• Job passes itself to the queue manager

• Manager serializes job

• Manager uses HTTP call through a load balancer to queue the job

• The queue on the other end returns the job id and server name

• Job ID and server name is passed to the client

Client polls the manager to get a completed job• When the job is returned pass the serialized version of the

executed job

Execution Flow

Page 32: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Let’s write some code

(no I’m not copping out with slides. We’re all told to show our work in grade skool)

Page 33: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment

Page 34: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Agenda

• What we will be talking about Development->Testing->Staging->Production

Rsync/SVN/PEAR/yum mechanisms

• What we will not be talking about Build tools (Phing, Maven, etc.)

Database versioning/deployment

Continuous Integration

MSI installs (Sorry MS folks, I really wanted to but, y’know, time)

Test-Driven Development

Page 35: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Before we get started

• Who here is a developer?

• Who here is a system administrator?

• Who here has an existing deployment strategy?

• Who here has edited a file in production?

• Who here has wished they didn’t?

Page 36: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Application Stages

| 36

Increasing Maturity of PHP Applications

Development Testing/QA Staging Production

Page 37: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Maturity

| 37

Increasing Maturity of PHP Applications

Testing & Validating

Application

Testing & Validating

Environment

Benefit

Structure

Distinct Dev Environments

Uptime!!

Where are you?

Page 38: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Development

• Purpose To provide developers an environment to write their code

• Characteristics Should be similar to production, though it usually isn’t

Often security is more open

Usually local to the developer

Page 39: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Consider Virtualization

Page 40: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Testing

• Purpose To provide a non-programming environment to test

functionality

• Characteristics Continuous Integration could be included

Generally no development occurs, only testing

Developers should not do the testing, if possible

Restricted outbound networking– Use Zend Server Monitoring and Code Tracing to help reproduce

errors

Page 41: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Prepared for and handed off to System Administrators

(the stuff we’re here to talk about)

Page 42: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Staging

• Purpose To test your deployment process/scripting (not your code)

• Characteristics Developers generally do not have access, unless they are

also the sysadmin

Very restricted outbound networking

Mirrors production as best as possible

Page 43: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Change Control

• A formal process used to ensure that changes are introduced in a controlled and coordinated manner

• Protect against unnecessary changes introduced to a system without forethought

• Requires documenting the release process Software version number

Plans for rollback (tested? y/n)

Expected outage time

Customer impact

• Done prior to doing anything in production

Page 44: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Pre-Production (Optional)

• Purpose Test the code in the production environment without

impacting customers

• Characteristics Not likely to have use in the cloud or large scale

deployments

Deployed in production immediately prior to making it live

Test the application with production settings without customer interaction

Page 45: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Production

• Purpose• Do whatever it is that it’s supposed to be doing

• Characteristics• Developers do not have access (as they might be tempted

to fix something)

• Deployment should be done without requiring developer input

• Very limited inbound traffic – generally only the service that is being served. i.e. HTTP

Page 46: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Application considerations

• Build the application to be aware of different environments Zend_Config_* is good at this

• Do not set the environment type in your code Environment variables can be placed in server config

• It means that you won’t accidentally keep your development settings turned on in production

• Make production your default environment Keeps accidental data leakage to a minimum

Page 47: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 1 – rsync

• Benefits Easy

Already installed on your system

• Drawbacks No deployment script can be run

Not integrated with either PHP or the OS

Rollbacks require rolling back the entire source server• Does not understand versioning

– One option is to move the source tree prior to the rsync

• Uses xinetd

Page 48: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 2 – Source Control

• Benefits Easy

You should already be using source control

Has versioning

Can have pre/post install scripts

Easy to do automatic deployments

• Drawbacks Do you want to put details on how to access your source

code on your production box?

Requires that your source control is accessible from production

Deny access to .svn directories

Page 49: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 3 – PEAR• Benefits

Designed for PHP

Very scriptable• Natural for doing things like clearing a cache

Has a better understanding of PHP

Cross platform compatible

• Drawbacks Requires admins to be familiar with PHP code

Limited to PHP deployment

Available tooling is restrictive/build your own package.xml

Define standardized locations (www, library, etc.)

Page 50: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 3 – PEAR

Creating your PEAR Channel

pear channel-discover pear.pirum-project.org

pear install pirum/Pirum-beta

vi /var/www/pear/pirum.xml

<server>  <name>localhost/pear</name>  <summary>OurOrg PEAR channel</summary>  <alias>helloworld</alias>  <url>http://localhost/pear/</url></server>

php ./pirum build /var/www/pear/

Page 51: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 3 - PEAR

Creating your PEAR package

php ./build-pear.php

pear package

pirum add /var/www/pear/ HelloWorld-0.1.3.tgz

Page 52: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deploying your app

pear channel-discover localhost/pear

pear config-set www_dir /var/www

pear install helloworld/HelloWorld

pear clear-cache

pear upgrade helloworld/HelloWorld

Roll Back

pear uninstall helloworld/HelloWorld

pear install helloworld/HelloWorld-0.1.3

Page 53: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Deployment Option 4 - OS-based

• Benefits Easily added as part of your server deployment

• Very cloud friendly

Admins already know how to use it

Can describe OS-requirements/dependencies

Downtime limited to actual install, not network transfer time

• Drawbacks Depends on environment

Any PHP deployment scripting needs to be deployed with the application and executed in %post hook

Page 54: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Which should you use?

• Need something simple? rsync

• Need to deploy to multiple disparate platforms? PEAR

• Need to deploy internally/with minimal developer input?OS (yum/apt) If using the OS consider maintaining an internal “blessed”

repository instead of depending on the distribution

Page 55: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Continuous Deployment

• Using automated deployment

• Very tight end-to-end integration

• Requires a lot of trust that the developers have a fully tested application w/ backend and frontend code

• Probably more work to manage if you can count the servers in your production environment with your fingers

• Could be beneficial but make sure you know what you’re doing You will need to have several testing experts

Page 56: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Takeaways

• No need for copy-and-paste deployment

• No need for (S)FTP (Kinda not good for deployment)

• Have an easy rollback mechanism

• Prepare for errors in deployment

• Try to minimize the amount of scripting needed for deployment

• Consider using VMs on anything important to keep downtime to zero

bit.ly/phpDepAll

Page 57: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Follow us! Zend Technologies

http://twitter.com/zend

http://twitter.com/kpschrade (me!)

Page 58: North east user group tour

©All rights reserved. Zend Technologies, Inc.

Get this information and all the examples at eschrade.com…