Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

ZeroMQ in PHP

12.726 Aufrufe

Veröffentlicht am

Veröffentlicht in: Technologie

ZeroMQ in PHP

  1. 1. Ømq and CakePHPSocket programming brought to your web app
  2. 2. What is Ømq?Intelligent socket library for messagingIncredibly flexible, you can build your own patternsFast as hellFault tolerantLanguage agnostic
  3. 3. What is not Ømq?A message queue, it literally has zero message queuesA server you can connect toPersistentOut of the box solution (sorry to let you down)
  4. 4. Why use Ømq instead of X?It’s a paradigm change, you can hardly compare it to “othersolutions”When your system require more advanced networkinteractions (or patterns)You need cheap and easy parallel processingYou don’t want a single point of failureYou need exceptional speed
  5. 5. Transports
  6. 6. Supported transportsINPROC (in-process communication)IPC (inter-process communication)Multicast (using a pgm multicast)TCP
  7. 7. Let’s talk about patterns
  8. 8. Patterns is all what Ømq is aboutYou can choose to use any of the patterns or combine themall in a single applicationCombining patterns help you build more advanceddistributed systems
  9. 9. ICANHAZ?Client ServerRequest - Reply
  10. 10. Request - Reply client.php
  11. 11. Request - Reply server.php
  12. 12. Wait a minute...This looks way too slow, a single php process won’t cope theload of multiple clients.
  13. 13. We need a solution
  14. 14. The solutionStart more servers on different portsBind your clients to multiple servers using the same socketØmq will automatically load balance them for youDrawback: You need to hardcode server addresses on eachclient
  15. 15. Load Balanced Requests More on balancing later...
  16. 16. Client Client Server Client ClientPublisher - Subscriber
  17. 17. Publisher publisher.php
  18. 18. Subscriber client.php
  19. 19. Pub - SubLike a radio broadcast, if you tune in late you’ll miss part ofthe showIf client crashes the it will also lose messagesIt is possible to attach multiple filters to a connectionYou can listen on multiple addresses at once
  20. 20. Pub -SubØmq will buffer the messages in the subscriber if it is a “slowlistener”It will drop messages if buffer gets too bigThat is extremely cool
  21. 21. Client Worker Worker Worker more steps WorkerFan Worker Sink Worker Push - Pull (Pipeline)
  22. 22. Push - Pull ventilator.php
  23. 23. Push - Pull task.php
  24. 24. Push - Pull sink.php
  25. 25. Push - PullOne way onlyPUSH is used for “fanning out” tasksPULL is used for fan-in or sink processesWorkers can hop-in at any timeOnly one worker gets the task at a time and they are loadbalanced
  26. 26. Push - PullØmq will buffer the messages if there are no peers to getthemIt will block at some point if buffering too muchThat is also extremely cool
  27. 27. Devices
  28. 28. Devices or BrokersDevices are programs that will route messages between twonodesDevices are usually small but they can also be trusted withlarger tasks, such as persisting messagesUsed to solve hard problems but also introduce single pointsof failure
  29. 29. We needed a solution
  30. 30. Devices as balancers Client Client Client Dealer Server Server Server
  31. 31. A simple broker broker.php
  32. 32. DevicesClients will connect to localhost:5559Servers will connect to localhost:5560Load balancing is done by ØmqIf dealer fails everything breaks :(You can install failover dealers! :)
  33. 33. DevicesAllow you to create more complex topologiesHelp you route requests to anonymous workersGood place for handling/persisting/retrying messages extralogicCan be written in any language supported by Ømq!
  34. 34. Let’s see some examples