zeromq in php

34
Socket programming brought to your web app Ømq and CakePHP

Upload: jose-rodriguez

Post on 01-Sep-2014

6.994 views

Category:

Technology


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: ZeroMQ in PHP

Socket programming brought to your web app

Ømq and CakePHP

Page 2: ZeroMQ in PHP

What is Ømq?

Intelligent socket library for messaging

Incredibly flexible, you can build your own patterns

Fast as hell

Fault tolerant

Language agnostic

Page 3: ZeroMQ in PHP

What is not Ømq?

A message queue, it literally has zero message queues

A server you can connect to

Persistent

Out of the box solution (sorry to let you down)

Page 4: ZeroMQ in PHP

Why use Ømq instead of X?It’s a paradigm change, you can hardly compare it to “other solutions”

When your system require more advanced network interactions (or patterns)

You need cheap and easy parallel processing

You don’t want a single point of failure

You need exceptional speed

Page 5: ZeroMQ in PHP

Transports

Page 6: ZeroMQ in PHP

Supported transports

INPROC (in-process communication)

IPC (inter-process communication)

Multicast (using a pgm multicast)

TCP

Page 7: ZeroMQ in PHP

Let’s talk about patterns

Page 8: ZeroMQ in PHP

Patterns is all what Ømq is about

You can choose to use any of the patterns or combine them all in a single application

Combining patterns help you build more advanced distributed systems

Page 9: ZeroMQ in PHP

Request - Reply

Client ServerICANHAZ?

Page 10: ZeroMQ in PHP

Request - Replyclient.php

Page 11: ZeroMQ in PHP

Request - Replyserver.php

Page 12: ZeroMQ in PHP

Wait a minute...

This looks way too slow, a single php process won’t cope the load of multiple clients.

Page 13: ZeroMQ in PHP

We need a solution

Page 14: ZeroMQ in PHP

The solution

Start more servers on different ports

Bind your clients to multiple servers using the same socket

Ømq will automatically load balance them for you

Drawback: You need to hardcode server addresses on each client

Page 15: ZeroMQ in PHP

Load Balanced Requests

More on balancing later...

Page 16: ZeroMQ in PHP

Publisher - Subscriber

ServerClient

Client

Client

Client

Page 17: ZeroMQ in PHP

Publisherpublisher.php

Page 18: ZeroMQ in PHP

Subscriberclient.php

Page 19: ZeroMQ in PHP

Pub - Sub

Like a radio broadcast, if you tune in late you’ll miss part of the show

If client crashes the it will also lose messages

It is possible to attach multiple filters to a connection

You can listen on multiple addresses at once

Page 20: ZeroMQ in PHP

Pub -Sub

Ømq will buffer the messages in the subscriber if it is a “slow listener”

It will drop messages if buffer gets too big

That is extremely cool

Page 21: ZeroMQ in PHP

Push - Pull (Pipeline)

Client Worker Worker Worker

Fan

Worker

Worker

Worker

Sink

more steps

Page 22: ZeroMQ in PHP

Push - Pullventilator.php

Page 23: ZeroMQ in PHP

Push - Pulltask.php

Page 24: ZeroMQ in PHP

Push - Pullsink.php

Page 25: ZeroMQ in PHP

Push - Pull

One way only

PUSH is used for “fanning out” tasks

PULL is used for fan-in or sink processes

Workers can hop-in at any time

Only one worker gets the task at a time and they are load balanced

Page 26: ZeroMQ in PHP

Push - Pull

Ømq will buffer the messages if there are no peers to get them

It will block at some point if buffering too much

That is also extremely cool

Page 27: ZeroMQ in PHP

Devices

Page 28: ZeroMQ in PHP

Devices or Brokers

Devices are programs that will route messages between two nodes

Devices are usually small but they can also be trusted with larger tasks, such as persisting messages

Used to solve hard problems but also introduce single points of failure

Page 29: ZeroMQ in PHP

We needed a solution

Page 30: ZeroMQ in PHP

Devices as balancersClient Client Client

Dealer

Server Server Server

Page 31: ZeroMQ in PHP

A simple brokerbroker.php

Page 32: ZeroMQ in PHP

Devices

Clients will connect to localhost:5559

Servers will connect to localhost:5560

Load balancing is done by Ømq

If dealer fails everything breaks :(

You can install failover dealers! :)

Page 33: ZeroMQ in PHP

Devices

Allow you to create more complex topologies

Help you route requests to anonymous workers

Good place for handling/persisting/retrying messages extra logic

Can be written in any language supported by Ømq!

Page 34: ZeroMQ in PHP

Let’s see some examples