do you queue

26
Do you queue? Characteristics of scalability Kevin Schroeder Technology Evangelist Zend Technologies

Upload: kevin-schroeder

Post on 17-May-2015

4.913 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Do you queue

Do you queue? Characteristics of scalabilityKevin Schroeder

Technology Evangelist

Zend Technologies

Page 2: Do you queue

2

• Kevin Schroeder Technology Evangelist for Zend

Programmer

Sys Admin

Author• IBM i Programmer’s Guide to PHP

• You want to do WHAT with PHP?

Race Ferraris on the weekend• My Honda has a dismal win record

About me

Page 3: Do you queue

3

I blog at eschrade.com

Follow us!(good things will happen to you)

Zend Technologies

http://twitter.com/zend

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

Page 4: Do you queue

4

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

asynchronously?

Twtpoll results

Page 5: Do you queue

5

• 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 6: Do you queue

6

• People often say that performance and scalability are two completely different things.

This is inaccurate

• 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 7: Do you queue

7

• 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 8: Do you queue

8

Typical anatomy of a PHP Application

| 8

Presentation

Application Control

Database Access

Business Logic

Presentation

Application Control

Business Logic

Presentation

Bad for scala-bility!

Page 9: Do you queue

9 | Apr 12, 2023

| 9

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 10: Do you queue

10

Defined tasks

Loose coupling

Resource discovery

What helps make software scalable?

Page 11: Do you queue

11

The Golden Rule of Scalability

“It can probably wait”

Page 12: Do you queue

12

• Pre-caching data

• Data analysis

• 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 13: Do you queue

13

• 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 14: Do you queue

14

• 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 15: Do you queue

15

• 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)

Considerations

Page 16: Do you queue

16

• 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 17: Do you queue

17

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 18: Do you queue

18

• 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 19: Do you queue

19

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 20: Do you queue

20

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 21: Do you queue

21

• 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 22: Do you queue

22

Q_Manager

Handles connecting to the queue and passing results back and forth

Q_JobAbstract

Abstract class that a job would be based off of

Q_Response

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

Job_Scandir

The actual job that scans the directory

Job_ScandirResult

An object that represents the data found

Classes involved in the demo

Page 23: Do you queue

23

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 24: Do you queue

24

Let’s write some code

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

Page 25: Do you queue

25

Follow us!

Zend Technologies

http://twitter.com/zend

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

Page 26: Do you queue

26

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