Les fichiers de configuration (configs) font partie intégrante de la plupart des applications, mais, comme le montre la pratique, ce n'est pas le sujet de discussion le plus populaire. Le plus souvent, les conversations sur les configurations se limitent à discuter du travail avec elles directement dans le code: comment les structurer, utiliser ou non des variables d'environnement, où stocker les mots de passe, 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 . , , , .
, :
( 1000 ) , ;
AutoConfig 450 , ( );
, ,
N ;
, , .
Consul -. , - . , - , — , . , (Retry), .
. , , Consul, .
, , — .
, , .
, . , AutoConfig A/B-, , Service Discovery .
— 16 000, — 120 .
!
, .