構成ファイル(configs)は、ほとんどのアプリケーションの不可欠な部分ですが、実践が示すように、これは議論の中で最も人気のあるトピックではありません。ほとんどの場合、構成に関する会話は、コード内で直接操作する方法について話し合うことに限定されています。構成の方法、環境変数の使用の有無、パスワードの保存場所などです。
, , , — (). , - .
, 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 .
!
, .