• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Asynchronous processing with PHP and Symfony2. Do it simple
 

Asynchronous processing with PHP and Symfony2. Do it simple

on

  • 5,121 views

The presentation for Symfony Camp UA 2013 about asynchronous processing. ...

The presentation for Symfony Camp UA 2013 about asynchronous processing.

We will talk about a near real-time processing of a business logic which does not require synchronous actions.

How to do it fast.
How to do it simple.
And how to do not ask PHP to struggle through alone.

We will analyze our experience, bad decisions and will try to get Zen of simplicity.

Statistics

Views

Total Views
5,121
Views on SlideShare
5,072
Embed Views
49

Actions

Likes
2
Downloads
11
Comments
0

3 Embeds 49

https://twitter.com 46
http://de.pinterest.com 2
http://dev.symfony2developer.com 1

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • {}

Asynchronous processing with PHP and Symfony2. Do it simple Asynchronous processing with PHP and Symfony2. Do it simple Presentation Transcript

  • Asynchronous processing with PHP and Symfony2 Do it simple Kirill chEbba Chebunin
  • Overview. The Problem REQUEST RESPONSE Expected Response Complete Logic Kirill chEbba Chebunin
  • Overview. Examples • Data transfer and manipulation ! • File upload! • Video conversion! • Massive business logic ! • Billing! • Social! • 3rd-party communication! • API calls ! • Notifications Kirill chEbba Chebunin
  • Overview. The Solution REQUEST RESPONSE Required Logic Remaining Logic Kirill chEbba Chebunin
  • Experience. The Real Project http://hopeliesat24framespersecond.files.wordpress.com/2011/12/love_actually_movie_image_bill_nighy_01.jpg Kirill chEbba Chebunin
  • Experience. Billing Partners Billing Aggregator Service Providers Kirill chEbba Chebunin
  • Experience. Billing. 2012 Worker Worker Worker Worker Master Worker Worker Kirill chEbba Chebunin
  • Experience. Billing. Revolution Made b y Vasily coyl Ku lakov http://darkroom.baltimoresun.com/wp-content/uploads/2012/05/REU-CUBA-MAYDAY-1.jpg Kirill chEbba Chebunin
  • Theory http://marketmybook.in/wp-content/uploads/2013/05/Library-Books.jpg Kirill chEbba Chebunin
  • Theory. Master-Worker Worker Worker Master Worker Kirill chEbba Chebunin
  • Theory. Master-Worker. Conclusions • Process control! • Resources in workers! • Long living workers! • Memory control! • Signal support Kirill chEbba Chebunin
  • Theory. RabbitMQ http://www.rabbitmq.com/img/tutorials/intro/hello-world-example-routing.png Kirill chEbba Chebunin
  • RabbitMQ • 1 exchange => multiple queries = topic! • Query = Worker type! • Durable exchanges/queries! • Persistent messages! • autoAck=false Kirill chEbba Chebunin
  • Experience. Billing. Review http://bi.gazeta.pl/im/84/96/d8/z14194308Q,Najglupsze-pomysly-mistrzow-prowizorki.jpg Kirill chEbba Chebunin
  • New world. Master • Master process => supervisor! • Start workers! • Worker count! • Signaled shutdown! • Auto-restart on failure! • Memory control! • …………. Kirill chEbba Chebunin
  • New world. Supervisor Example config ! [program:billing_statistics] process_name=%(program_name)s_%(process_num)d numprocs=4 stdout_logfile=/var/log/supervisor/%(program_name)s.out.log stderr_logfile=/var/log/supervisor/%(program_name)s.error.log command=billing rabbitmq:consumer statistics autorestart=true autostart=true Kirill chEbba Chebunin
  • New world. Publish/Subscribe • oldsound/rabbitmq-bundle! • Exchange/Queue setup! • Producers! • Consumers! • Command = worker! • Events! • Special event name! • Producer Listener Kirill chEbba Chebunin
  • Experience. Billing. 2013 Worker Worker Worker Worker Worker Worker Supervisor Kirill chEbba Chebunin
  • Profit? Kirill chEbba Chebunin
  • Future. Publish/Subscribe. Improve! • Send any event to async processing! • Use listeners as workers! • Different message bus Kirill chEbba Chebunin
  • Future Kirill chEbba Chebunin
  • EventBand EventBand http://baadu.ru/ph/8/polosy_na_stene_1280x1024.jpg Kirill chEbba Chebunin
  • EventBand. Overview Dispatcher Band#1 Listener Listener Band#2 Listener Band#3 Event Listener Listener Listener Listener Listener Listener Listener Band#4 Listener Listener Band#5 Listener Listener Band#6 Listener Current Listener Default Band Kirill chEbba Chebunin
  • EventBand. Architecture PublishListener Listener Listener Listener Listener T R A N S P O R T Listener Band#1 Listener Listener Band#2 Listener Listener Band#3 Listener Kirill chEbba Chebunin
  • EventBand. Architecture • Dispatcher! • Band support! • Abstract Subscribers! • Adapters (Symfony, ZF, …)! • Transport! • Setup! • Publisher! • Storage! • Routing! • Consumer! • Adapters (RabbitMQ, ActiveMQ, Gearman, …) Kirill chEbba Chebunin
  • EventBand. Utilities • Event Serialization! • Native! • JMS! • Event Routing! • By name! • By properties (PropertyAccess) Kirill chEbba Chebunin
  • EventBand. Example. Code Dispatch: ! $dispatcher->dispatch('foo.bar', new FooEvent($foo, $bar)); ! ………………………………………………………… ! Subscribe: ! public function logFooBar(FooEvent $event) { $this->service->saveLog($event->getFoo(), $event->getBar()); } ! ! <service id="log_subscriber" class="FooBarLogSubscriber"> <tag name="kernel.event_subscriber" band=“foo.bar.log" /> </service> Kirill chEbba Chebunin
  • EventBand. Example. Config transports: amqp: driver: amqplib connections: default: ~ exchanges: foo: ~ queues: foo.bar.log: bind: foo: "foo.bar" ! publishers: foo: events: "foo.#" ! consumers: foo.bar.log: ~ Kirill chEbba Chebunin
  • EventBand. Wanna Play? https://packagist.org/packages/event-band/ Kirill chEbba Chebunin
  • Experience. Patterns • Identified Event! • id, time, sequence, process! • logging (sqlite)! • Delayed Event! • original event, delay! • delay time => queue! • ordered queue! • sleep until delay Kirill chEbba Chebunin
  • Experience. Troubleshooting • Doctrine! • SqlLogger! • Unit of Work! • flush, detach! • Array properties Kirill chEbba Chebunin
  • Questions? Cool Image with Cats and Boobs Kirill chEbba Chebunin iam@chebba.org https://github.com/chEbba https://twitter.com/iamchEbba Kirill chEbba Chebunin