Run, config, run: how we speed up deploying configs in Badoo

Configuration files (configs) are an integral part of most applications, but, as practice shows, this is not the most popular topic for discussion. Most often, conversations about configs are limited to discussing working with them directly in the code: how to structure them, use environment variables or not, where to store passwords, etc. 





, , , โ€” (). , - .





, 1000+ . 





, Badoo , .






. , .





Badoo , . - , , . , ยซ - , ยป.





โ€” , , , ( , , , . .). 





โ€” , . , .





ยซ ยป (disable hosts). :





  • - , (, , );





  • Deploy;





  • , PHP-.





:





if (\DownChecker\Host::isDisabled($host)) {
   $this->errcode = self::ERROR_CONNECT_FAILED;
   return false;
}
      
      



ยซ ยป mcode. SSH .





:





  • tar-;





  • rsync scp;





  • ;





  • .





mcode โ€” , , . , , 99% (). โ€” , , -. - , . . 





, mcode . , .





, - . , (, ). -, . 





, . , . , .





: , () ?





, , , :





  • โ€” , , ;





  • , , , ; 





  • , , , OPCache, .





, ( ) , (, cron), . , , , . 





. 2000 , PHP-. / , (2k rps), . โ€” , Publisher-Subscriber (PubSub). Redis, ( Memcache, ). 





Consul, (watches)   . PubSub . Consul, AutoConfig.





AutoConfig

:





  • , ;





  • , Consul; , Consul ( );





  • Consul watch, -, ;





  • .





:









$record = \AutoConfig\AutoConfigRecord::initByKeyData('myKey', 'Hello, Habr!', 'Eugene Tupikov');
$storage = new \AutoConfig\AutoConfigStorage();
$storage->deployRecord($record);
      
      







$reader = new \AutoConfig\AutoConfigReader();
$config = $reader->getFromCurrentSpace('myKey');
      
      







$storage = new \AutoConfig\AutoConfigStorage();
$storage->removeKey('example');
      
      



Consul watch

Consul watch HTTP API, .





.





curl -X PUT --data 'hello, habr!' http://127.0.0.1:8500/v1/kv/habr-key
      
      







curl -v http://127.0.0.1:8500/v1/kv/habr-key
      
      



API , HTTP- X-Consul-Index , .





...
...
< X-Consul-Index: 266834870
< X-Consul-Knownleader: true
...
...
<
[
  {
    "LockIndex": 0,
    "Key": "habr-key",
    "Flags": 0,
    "Value": "aGVsbG8sIGhhYnIh",
    "CreateIndex": 266833109,
    "ModifyIndex": 266834870
  }
]
      
      



X-Consul-Index index





curl http://127.0.0.1:8500/v1/kv/habr-key?index=266834870

  ...


      
      



index API , -.









curl -X PUT --data 'updated value' http://127.0.0.1:8500/v1/kv/habr-key
      
      



, ( Value ModifyIndex):





[
  {
    "LockIndex": 0,
    "Key": "habr-key",
    "Flags": 0,
    "Value": "dXBkYXRlZCB2YWx1ZQ==",
    "CreateIndex": 266833109,
    "ModifyIndex": 266835734
  }
]
      
      







consul watch -type=key -key=habr_key <handler>
      
      



Consul watch .





, . , auto_config.





consul watch -type=keyprefix -prefix=auto_config/ <handler>
      
      



. . , , . , .





GitHub Issue , , . Consul , .





, Consul . Consul Watch.





:





return [
    'value' => [
        'version' => 437036,
        'keys' => [
            'my/awesome/key' => '80003ff43027c2cc5862385fdf608a45',
            ...
            ...
        ],
        'created_at' => 1612687434
    ]
]
      
      



, :





  • ;





  • ( );





  • HTTP API ;





  • .





Consul

Consul โ€” , AutoConfig , .





( )





Consul โ€” , Raft. Consul โ€” 512 . , , , . 





. 512 . , , โ€” 64.





, :





  • ( 1000 ) , ;





  • AutoConfig 450 , ( );





  • , ,





    • N ;





    • , , .









Consul -. , - . , - , โ€” , . , (Retry), .





. , , Consul, .





 

, , โ€” .





, , .





, . , AutoConfig A/B-, , Service Discovery .





โ€” 16 000, โ€” 120 .





!





, .








All Articles