AusfĂĽhren, konfigurieren, ausfĂĽhren: Wie wir die Bereitstellung von Konfigurationen in Badoo beschleunigen

Konfigurationsdateien (Konfigurationen) sind ein wesentlicher Bestandteil der meisten Anwendungen, aber wie die Praxis zeigt, ist dies nicht das beliebteste Diskussionsthema. In den meisten Fällen beschränken sich Gespräche ĂĽber Konfigurationen darauf, die Arbeit mit ihnen direkt im Code zu diskutieren: wie man sie strukturiert, Umgebungsvariablen verwendet oder nicht, wo man Passwörter speichert usw. 





, , , — (). , - .





, 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