关于前端:Flutter-新闻客户端-17-headless-strapi-centos-发布部署-jmeter-压测

89次阅读

共计 4103 个字符,预计需要花费 11 分钟才能阅读完成。

本节指标

  • 上传代码到生产环境
  • 配置公布环境代码
  • docker-compose 形式启动我的项目
  • jmeter 做基线测试 调优服务器配置

视频

https://www.bilibili.com/vide…

<iframe src=”//player.bilibili.com/player.html?bvid=BV15v411q7CK&page=1″ scrolling=”no” border=”0″ frameborder=”no” framespacing=”0″ allowfullscreen=”true” width=”100%” height=”400px”> </iframe>

strapi 运行环境网盘下载

  • 网盘

链接:https://pan.baidu.com/s/13Ujy…
明码:yu82

  • 运行

本节下载 strapi-docker-compose-16.zip 这个文件

须要用 docker-compose 启动
账号 admin
明码 123456

# 启动
docker-compose up -d --remove-orphans
# 敞开
docker-compose down

注释

打包上传服务器

  • 服务器配置

思考到基线压测优化,所以一开始低些

服务器 cpu1 外围 2G 内存

  • 如何配置 centos 服务器

参考我之前的文章

https://ducafecat.tech/2020/0…

https://youtu.be/NJIwbs8qmDY

  • 把所有文件 tar、zip 打包后上传
> yum install -y zip unzip
> unzip filename.zip

批改 graphql 配置

  • 文件 ./config/plugins.js
module.exports = {
//
graphql: {
endpoint: "/graphql",
tracing: false,
shadowCRUD: true,
playgroundAlways: false,
depthLimit: 7,
amountLimit: 100,
},
};
名称 阐明
endpoint 对外门路
tracing 反馈性能报告
shadowCRUD 反对 CRUD 操作
playgroundAlways 显示调试界面
depthLimit 查问深度限度
amountLimit 查问我的项目个数
  • 参数阐明

批改 admin 面板地址

  • 文件 ./config/server.js
module.exports = ({env}) => ({host: env("HOST", "0.0.0.0"),
port: env.int("PORT", 1337),
admin: {url: "/dashboard",},
});

默认 admin 不平安,能够改成奇怪的门路 dfasdx97s7 这种

strapi build 编译

  • 装置 portainer
docker run -d -p 9000:9000 \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
--name portainer-local \
portainer/portainer
  • 用工具 portainer 进入容器

> strapi build

批改 docker-compose 命令

...
strapi-app:
image: strapi/strapi
container_name: strapi-app
restart: always
ports:
- 1337:1337
command: strapi start
environment:
...

jmeter 压第一轮 – 服务器 cpu1 外围 2G 内存

  • 测试工具

https://jmeter.apache.org/dow…

须要装置 java 运行环境 jre 1.8

  • 测试内容

新闻首页

post /graphql
{"operationName":"pageIndex","variables":{},"query":"query pageIndex {\n dictCategories(sort: \"sortNum:desc\") {\n code\n title\n}\n dictChannels(sort: \"sortNum:desc\") {\n code\n title\n icon {\n url\n}\n }\n busNews(where: {dict_categories: {code: \"news_hot\"}}) {\n title\n dict_channel {\n code\n title\n icon {\n url\n}\n }\n dict_categories {\n code\n title\n}\n author\n url\n addtime\n thumbnail {\n url\n}\n }\n}\n"}

  • 测试环境

压测机: 8 外围 32G 本机 macos,发动线程数 1000~2000 官网倡议单机数量
服务器: 1 外围 2G 虚拟机 centos

  • 服务器信息监控
> top
top - 23:41:47 up 45 min, 2 users, load average: 0.12, 2.10, 2.09
Tasks: 160 total, 1 running, 159 sleeping, 0 stopped, 0 zombie
%Cpu(s): 2.2 us, 1.2 sy, 0.0 ni, 96.3 id, 0.0 wa, 0.0 hi, 0.2 si, 0.0 st
KiB Mem : 1877360 total, 424344 free, 746224 used, 706792 buff/cache
KiB Swap: 6713340 total, 6713340 free, 0 used. 963492 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
31814 root 20 0 2099204 91620 23620 S 3.7 4.9 3:03.04 node
977 root 20 0 820140 47944 14876 S 2.0 2.6 0:40.63 containerd
9 root 20 0 0 0 0 S 0.3 0.0 0:01.84 rcu_sched
445 root 20 0 0 0 0 S 0.3 0.0 0:01.07 xfsaild/dm-0
995 root 20 0 783740 91376 29532 S 0.3 4.9 0:08.46 dockerd
1675 polkitd 20 0 1659672 119912 18932 S 0.3 6.4 2:15.62 mongod
31570 root 20 0 633704 38776 15156 S 0.3 2.1 0:13.24 node
1 root 20 0 191036 3940 2572 S 0.0 0.2 0:00.60 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
4 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:01.15 ksoftirqd/0
7 root rt 0 0 0 0 S 0.0 0.0 0:00.09 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh

ctrl + c 进行

  • GUI 压测

1000 个申请 10 秒内

  • 命令行 压测
jmeter -n -t strapi.jmx -l report/result.csv -j report/log.log -e -o report_html

jmeter 压第二轮 – 服务器 cpu4 外围 2G 内存

  • 测试环境

压测机: 8 外围 32G 本机 macos,发动线程数 1000~2000
服务器: 4 外围 2G 虚拟机 centos

1000 个申请 5 秒内

  • 压测报告
jmeter -n -t strapi.jmx -l report/result.csv -j report/log.log -e -o report_html

strapi 优化线程数

  • 装置 pm2 工具

https://pm2.keymetrics.io/doc…

  • 编写 启动代码 server.js
const strapi = require("strapi");
strapi().start();
  • 编写 配置文件 strapi.config.js
module.exports = {
apps: [
{
name: "strapi-app",
script: "./server.js",
instances: 4,
exec_mode: "cluster",
},
],
};

instances 等于你的外围数

  • 批改 docker-compose.yml
...
strapi-app:
image: strapi/strapi
container_name: strapi-app
restart: always
ports:
- 1337:1337
# command: strapi build
# command: strapi start
command:
- /bin/bash
- -c
- |
npm install pm2@latest -g
cd /srv/app
pm2-runtime start strapi.config.js
environment:
...

jmeter 压第三轮 – 服务器 cpu4 外围 2G 内存

2000 个申请 1 秒内

次要服务器指标

名称 阐明
CPU <= 40%
内存 <= 70%

其它次要指标 连接数、本机进出流量、内网带宽、外网带宽

总结

  • strapi 服务器部署配置
  • jmetre 基线测试方法、次要指标查看

参考

  • strapi 插件配置

https://strapi.io/documentati…

  • strapi 命令行

https://strapi.io/documentati…

  • strapi 部署阐明

https://strapi.io/documentati…

  • pm2 装置

https://pm2.keymetrics.io/doc…

  • pm2 配置文件

https://pm2.keymetrics.io/doc…

  • jmeter

https://jmeter.apache.org/dow…

  • jmeter 分布式

https://jmeter.apache.org/use…

资源

设计稿蓝湖预览

https://lanhuapp.com/url/lYuz1
明码: gSKl

蓝湖当初免费了,所以查看标记还请本人上传 xd 设计稿
商业设计稿文件不好间接分享, 能够加微信分割 ducafecat


© 猫哥

https://ducafecat.tech

正文完
 0