欢迎访问我的GitHub
这里分类和汇总了欣宸的全部原创(含配套源码):
https://github.com/zq2599/blog_demos
本篇概览
实战步骤
- 内存资源从256M提升到512M;
- 内存资源从512M提升到1G;
- 内存资源从1G提升到2G;
- CPU资源从0.1提升到1;
- CPU资源从1提升到2;
注意:每次纵向扩容之前,需要停止和删除原有的deployment和service,扩容后,第一次测试的成绩请丢弃,因为JIT在理论上对结果有影响;
如何停止和删除原有的deployment和service
- 执行以下命令即可先删除service,再删除deployment:
kubectl delete service tomcathost && kubectl delete deployment tomcathost
内存资源从256M提升到512M
- 打开上一章我们搭建web服务时创建的tomcat.yaml文件,内容如下:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: tomcathost
spec:
replicas: 1
template:
metadata:
labels:
name: tomcathost
spec:
containers:
- name: tomcathost
image: bolingcavalry/k8stomcatdemo:0.0.5
tty: true
ports:
- containerPort: 8080
resources:
requests:
memory: "256Mi"
cpu: "100m"
limits:
memory: "256Mi"
cpu: "100m"
- 如上所示,找到resources节点下的两个memory节点,将值从"256Mi"改成"512Mi";
- 执行AB测试:
ab -n 20000 -c 100 http://192.168.119.153:30008/getserverinfo
Concurrency Level: 100
Time taken for tests: 68.527 seconds
Complete requests: 20000
Failed requests: 0
Total transferred: 3700000 bytes
HTML transferred: 1040000 bytes
Requests per second: 291.86 [#/sec] (mean)
Time per request: 342.635 [ms] (mean)
Time per request: 3.426 [ms] (mean, across all concurrent requests)
Transfer rate: 52.73 [Kbytes/sec] received
# Samples |
Average |
Median |
90% Line |
95% Line |
99% Line |
Min |
Max |
Error % |
Throughput |
Received KB/sec |
Sent KB/sec |
20000 |
489 |
294 |
1100 |
1608 |
3696 |
0 |
10899 |
0.00% |
188.8/sec |
30.61 |
25.45 |
继续提升内存
- 继续修改tomcat.yaml的内存参数,记录下来每次AB和JMeter的测试结果,这里就不赘述了,稍后在表格中统一给出;
升级CPU
- 继续修改tomcat.yaml,将内存恢复为256Mi,将CPU从100m改成1000m,也就是从0.1CPU改为1CPU,然后再从1CPU改为2CPU,分别记录下来每次AB和JMeter的测试结果;
小结纵向扩容
内存 |
CPU |
吞吐率(AB) |
吞吐率(JMeter) |
256M |
0.1 |
33.77 |
31.21 |
512M |
0.1 |
291.86 |
188.80 |
1G |
0.1 |
326.19 |
324.58 |
2G |
0.1 |
340.61 |
340.10 |
256M |
1 |
81.36 |
80.61 |
256M |
2 |
86.62 |
82.11 |
- 内存扩容在1G之前是有显著提升的,但过了1G提升就不明显了;
- CPU资源增大到原有的10倍后,吞吐量有3倍左右提升,继续加倍CPU资源,也无法带来明显提升;
- 这里要注意的是此次测试的后台代码很简单,并未涉及RPC、数据库、缓存等,数值不能作为生产环境的参考,因为每个实际的业务都有其自身的特征,此处仅提出一种扩容和验证扩容效果的手段;
- 至此,纵向扩容的测试就完成了,接下来的章节,咱们一起测试一下横向扩容的效果;
欢迎关注阿里云开发者社区博客:程序员欣宸
学习路上,你不孤单,欣宸原创一路相伴...