因为一体化后管理资源数量可能超过10w台,后台准备使用etcd作为配置和服务管理中心,和小爽一起做了目录层级和深度以及集群性能的初测。
单机测试:8核8G
单节点路径长度测试,路径长度为100+是否正常set,生成100层目录,正常。
curl http://127.0.0.1:2379/v2/keys/test/0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44/45/46/47/48/49/50/51/52/53/54/55/56/57/58/59/60/61/62/63/64/65/66/67/68/69/70/71/72/73/74/75/76/77/78/79/80/81/82/83/84/85/86/87/88/89/90/91/92/93/94/95/96/97/98/99/100
{"action":"get","node":{"key":"/test/0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44/45/46/47/48/49/50/51/52/53/54/55/56/57/58/59/60/61/62/63/64/65/66/67/68/69/70/71/72/73/74/75/76/77/78/79/80/81/82/83/84/85/86/87/88/89/90/91/92/93/94/95/96/97/98/99/100","value":"hello etcd","modifiedIndex":502079,"createdIndex":502079}}
单节点路径深度测试,程序创建50万层目录深度,查看是否正常set和get,50w层正常
-bash-4.1# curl http://127.0.0.1:2379/v2/keys/foo/0
{"action":"get","node":{"key":"/foo/0","value":"Hello world","modifiedIndex":10024,"createdIndex":10024}}
-bash-4.1# curl http://127.0.0.1:2379/v2/keys/foo/500000
{"action":"get","node":{"key":"/foo/500000","value":"Hello 500000","modifiedIndex":510028,"createdIndex":510028}}
单节点set效率测试,使用Apache ab测试-n 10万 -c 100并发,1666/s,set foo/0 10w次,index修改正常
more p.txt
value='hello aaa'
Concurrency Level: 100
Time taken for tests: 60.003 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 41315281 bytes
Total PUT: 18211284
HTML transferred: 20707659 bytes
Requests per second: 1666.58 [#/sec] (mean)
Time per request: 60.003 [ms] (mean)
Time per request: 0.600 [ms] (mean, across all concurrent requests)
Transfer rate: 672.41 [Kbytes/sec] received
296.39 kb/s sent
968.81 kb/s total
查看set正常:
curl http://127.0.0.1:2379/v2/keys/foo/0
curl: /usr/local/lib/libidn.so.11: no version information available (required by /usr/local/lib/libcurl.so.4)
{"action":"get","node":{"key":"/foo/0","value":"'hello aaa'\n","modifiedIndex":625767,"createdIndex":625767}}
集群测试,使用三台机器,编写monitor,26是leader。3台机器做ab测试set,效率为1500/s没有明显下降,shutdown一台集群get、set、存储均不受影响。
Paste_Image.png
ps:常用功能
TTL,五秒key自动消失,常用作服务注册
-bash-4.1# curl http://127.0.0.1:2379/v2/keys/test/0/1/2/3/4/5/6/7/8/9/10 -XPUT -d value='hello etcd' -d ttl=5
{"action":"set","node":{"key":"/test/0/1/2/3/4/5/6/7/8/9/10","value":"hello etcd","expiration":"2017-06-01T09:46:52.232946216Z","ttl":5,"modifiedIndex":471890,"createdIndex":471890}}
watch功能,服务管理
当前key watch
curl http://192.168.6.26:2379/v2/keys/foo/test?wait=true
{"action":"set","node":{"key":"/foo/test","value":"Hello world","modifiedIndex":11,"createdIndex":11},"prevNode":{"key":"/foo/test","value":"Hello world","modifiedIndex":10,"createdIndex":10}}
子目录watch
curl 'http://192.168.6.26:2379/v2/keys/foo?wait=true&recursive=true'
{"action":"set","node":{"key":"/foo/qqq","value":"Hello","modifiedIndex":21,"createdIndex":21},"prevNode":{"key":"/foo/qqq","value":"Hello","modifiedIndex":20,"createdIndex":20}}
事件查询
curl 'http://192.168.6.26:2379/v2/keys/foo?wait=true&recursive=true&waitIndex=21'
{"action":"set","node":{"key":"/foo/qqq","value":"Hello","modifiedIndex":21,"createdIndex":21},"prevNode":{"key":"/foo/qqq","value":"Hello","modifiedIndex":20,"createdIndex":20}}
遍历某key
-bash-4.1# curl -s http://192.168.6.151:2379/v2/keys/?recursive=true| jq .
{
"node": {
"dir": true
},
"action": "get"
}