Advertisement
Advertisement

More Related Content

Similar to Using queues and offline processing to help speed up your application(20)

Advertisement

Using queues and offline processing to help speed up your application

  1. Using Queues and Offline Processing David Stockton Madison PHP - Oct 1, 2016
  2. Synchronous Processing
  3. Shopping Trip
  4. Car Wash
  5. DMV
  6. The Web Should Be Fast
  7. Customers Want It To Be Fast
  8. Think Work Order
  9. Asynchronous Processing
  10. Real-World Async
  11. Online Shopping
  12. Personal Assistants
  13. Personal Assistants
  14. Web Pages
  15. Infinite Scrollers
  16. Magical Parallelization
  17. Fake It Until You Make It
  18. Time Is Not On Our Side
  19. User Input
  20. Do The Needful Now Everything Else Can Wait
  21. Database Queue
  22. Data Synchronization
  23. Message Queues
  24. Work Producer
  25. Work Producer
  26. How does that help?
  27. Workers
  28. Workers
  29. Multiplicity
  30. Control Server Load
  31. Handle Load Spikes
  32. Workers as Assistants
  33. Ballottrax
  34. Data Loads
  35. Communication Rates • Email - 250 connections, 10 per seco • SMS - 30 per second • Voice - 1 per second, per phone number
  36. Splitting Work By Type
  37. Rate Limiting
  38. Queues to Queue Work
  39. Acceptable for Work
  40. Notification Filters
  41. Geocoding
  42. Producers Consumers
  43. DB Queue vs Pure MQ
  44. Feeding Queue from Database - Cron
  45. Feeding Queues from Database - Polling
  46. Polling - The Worst
  47. Events and Webhooks
  48. Magical Webhooks
  49. Automated Pull Requests
  50. Queues For Webhooks
  51. Install AMQPLib composer require php-amqplib/ php-amqplib
  52. Create Queue/Channel $connection = new PhpAmqpLibConnection AMQPStreamConnection($server, $port, $user, $password, $vhost);
 $channel = $connection->channel();
 $channel->queue_declare(
 $queueName,
 false, // Passive
 true, // Durable
 false, // Exclusive
 false // Auto Delete
 );
  53. Setting Channel Options $channel->basic_qos(null, 1, null);
 $channel->basic_consume(
 $queueName,
 '', // Consumer tag
 false, // No local
 false, // No ACK
 false, // Exclusive
 false, // No wait
 $callback
 );
  54. Do Some Work 
 while (count($channel->callbacks)) {
 $channel->wait();
 }
 
 $channel->close();
 $connection->close();
  55. The Callback $callback = function ($msg) {
 $message = (array) json_decode($msg- >body, false);
 // Do work
 
 $msg->delivery_info['channel'] ->basic_ack(
 $msg->delivery_info['delivery_tag']
 );
 };
  56. Creating a Message $message = new PhpAmqpLibMessageAMQPMessage(
 json_encode($data),
 [
 'delivery_mode' =>
 AMQPMessage::DELIVERY_MODE_PERSISTENT
 ]
 );
  57. Putting Message in the Queue try {
 $channel->basic_publish($message, '', $queueName);
 } catch (AMQPExceptionInterface $e) {
 $this->getLogger()->err( 'Error putting message into RabbitMQ', $e->getMessage() );
 return false;
 }
  58. Work Priority
  59. Recap
  60. Questions?
  61. David Stockton @dstockto https://davidstockton.com https://tddftw.com
Advertisement