Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Lock Component - Lightning Talk - Symfony Live Paris 2017

Lock Component - Lightning Talk - Symfony Live Paris 2017

Lightning Talk about the new Symfony 3.3 Lock Component (french).

B2f426bbcfa510f7789b642c68b3838a?s=128

Fabien Bourigault

March 31, 2017
Tweet

Transcript

  1. Lock Component Symfony Live Paris 2017

  2. @fbourigault Développeur backend

  3. Cas d'utilisation Concurrence ? Exclusion mutuelle ! $room = $this->findRoom();

    $booking->setRoom($room);
  4. Lock Component Simple Fiable Évolutif

  5. Persistance locale use Symfony\Component\Lock\Factory; use Symfony\Component\Lock\Store\FlockStore; $store = new FlockStore();

    $factory = new Factory($store); $lock = $factory->createLock('find-room'); if ($lock->acquire(true)) { // The resource "find-room" is locked. $room = $this->findRoom(); $booking->setRoom($room); $lock->release(); }
  6. Persistance distribuée Scalabilité horizontale Tolérance aux pannes Redis et Memcached

  7. Persistance distribuée use Symfony\Component\Lock\Strategy\ConsensusStrategy; use Symfony\Component\Lock\Store\CombinedStore; use Symfony\Component\Lock\Store\RedisStore; $stores =

    []; foreach (['server1', 'server2', 'server3'] as $server) { $redis = new \Redis(); $redis->connect($server); $stores[] = new RedisStore($redis); } $store = new CombinedStore($stores, new ConsensusStrategy());
  8. Persistance distribuée $store = new CombinedStore($stores, new ConsensusStrategy()); $factory =

    new Factory($store); $lock = $factory->createLock('find-room'); if ($lock->acquire(true)) { // The resource "find-room" is locked. $room = $this->findRoom(); $booking->setRoom($room); $lock->release(); }
  9. Merci !