图床项目之公网发布和测试

一、http服务测试

在这里插入图片描述

启动项目,使用ab命令进行http请求测试。

1.1、ab http压力测试

ab命令全称为 Apache bench 是Apache自带的压力测试工具。ab命令非常实用,它不仅可以对Apache服务器进行网站访问压力测试,也可以对或其它类型的服务器进行压力测试,ab命令会创建多个并发线程,模拟多个访问者同时对某一个url地址进行访问,实现压力测试。
(1)ab安装:

sudo apt-get install apache2-utils

ab -V

版本显示:

This is ApacheBench, Version 2.3 <$Revision: 1807734 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

(2)参数说明:ab -h

Usage: ab [options] [http[s]://]hostname[:port]/path
Options are:
    -n requests     Number of requests to perform
    -c concurrency  Number of multiple requests to make at a time
    -t timelimit    Seconds to max. to spend on benchmarking
                    This implies -n 50000
    -s timeout      Seconds to max. wait for each response
                    Default is 30 seconds
    -b windowsize   Size of TCP send/receive buffer, in bytes
    -B address      Address to bind to when making outgoing connections
    -p postfile     File containing data to POST. Remember also to set -T
    -u putfile      File containing data to PUT. Remember also to set -T
    -T content-type Content-type header to use for POST/PUT data, eg.
                    'application/x-www-form-urlencoded'
                    Default is 'text/plain'
    -v verbosity    How much troubleshooting info to print
    -w              Print out results in HTML tables
    -i              Use HEAD instead of GET
    -x attributes   String to insert as table attributes
    -y attributes   String to insert as tr attributes
    -z attributes   String to insert as td or th attributes
    -C attribute    Add cookie, eg. 'Apache=1234'. (repeatable)
    -H attribute    Add Arbitrary header line, eg. 'Accept-Encoding: gzip'
                    Inserted after all normal header lines. (repeatable)
    -A attribute    Add Basic WWW Authentication, the attributes
                    are a colon separated username and password.
    -P attribute    Add Basic Proxy Authentication, the attributes
                    are a colon separated username and password.
    -X proxy:port   Proxyserver and port number to use
    -V              Print version number and exit
    -k              Use HTTP KeepAlive feature
    -d              Do not show percentiles served table.
    -S              Do not show confidence estimators and warnings.
    -q              Do not show progress when doing more than 150 requests
    -l              Accept variable document length (use this for dynamic pages)
    -g filename     Output collected data to gnuplot format file.
    -e filename     Output CSV file with percentages served
    -r              Don't exit on socket receive errors.
    -m method       Method name
    -h              Display usage information (this message)
    -I              Disable TLS Server Name Indication (SNI) extension
    -Z ciphersuite  Specify SSL/TLS cipher suite (See openssl ciphers)
    -f protocol     Specify SSL/TLS protocol
                    (SSL2, TLS1, TLS1.1, TLS1.2 or ALL)

1.2、post测试(注册请求和登录请求)

(1)注册请求测试:

ab -n 100 -c 4 -p reg.txt -T application/json http://114.215.169.66/api/reg

reg.txt内容:

{
    
    
"email": "[email protected]", 
"firstPwd": "e10adc3949ba59abbe56e057f20f883e", 
"nickName": "lucky", 
"phone": "18888888888", 
"userName": "FLY." }

测试结果:

(2)登录请求:

ab -n 100 -c 4 -p login.txt -T application/json http://114.215.169.66/api/login

login.txt内容:

{
    
    "pwd": "e10adc3949ba59abbe56e057f20f883e", 
"user": "FLY." }

测试结果:

(3)开启登录注册的线程数量:在tc_http_server.conf文件的TreadNum配置。
(4)注意:在发布之前,要把一些打印信息去掉,不然会影响性能。

二、性能测试

使用TPS指标:
TPS Transactions Per Second 也就是事务数/秒。一个事务是指一个客户机向服务器发送请求然后服务器做出反应的过程。客户机在发送请求时开始计时,收到服务器响应后结束计时,以此来计算使用的时间和完成的事务个数。

2.1、生成测试脚本

编译
cd fastdfs/test
make
生成
test_upload
test_delete
test_download
执行./gen_files,
生成6中不同大小的测试文件
上传能力测试,
单机可以模拟多个客户端,比如10代表10个客户端。
./test_upload.sh 10
下载能力测试,
单机可以模拟多个客户端,比如10代表10个客户端。
./test_download.sh 10
删除能力测试,
单机可以模拟多个客户端,比如10代表10个客户端。
./test_delete.sh 10

注意:test_download和test_delete依赖于test_upload产生的文件。

小规模测试的时候,建议一台客户端机器只模拟一个客户端 ./test_upload.sh 1。

cd ~/tuchuang/fastdfs/test 
make

2.2、上传测试

对应的测试程序test_upload.c + test_upload.sh。可以模拟十个并发客户端。.0、.1、…、.9只是客户端序号。

测试结果在fastdfs/test/upload目录。
(1)fail.x是存储上传失败的文件。
(2)file_id.x是存储上传成功的文件。
(3)stat_by_file_type.x是耗时统计。
(4)stat_by_overall.x包含总上传数、成功次数、耗时。
(5)stat_by_storage_ip.x是不同storage的统计。

测试结果显示:

使用6种不同大小的文件进行测试,分别为:

文件规格 测试次数
5K 1 000 000
50K 2 000 000
200K 1 000 000
1M 2 000 000
10M 20 000
100M 1 000

或者

文件规格 测试次数
5K 50 000
50K 10 000
200K 5 000
1M 500
10M 50
100M 10

2.2.1、单客户端测试本地上传到本机服务器

2.2.2、如果使用集群的方式进行测试

先考虑磁盘写入能力:
机械硬盘的写入速度和读写速度一般约为120MB/S。
SATA协议的固态硬盘速度约为500MB/S。
NVMe协议(PCIe 3.0×2)的固态硬盘速度约为1800MB/S。
NVMe协议(PCIe 3.0×4)的固态硬盘速度约为3500MB/S。

外网带宽:
通常是千M网是极限

内网带宽:
非I/O优化的实例为千兆共享带宽,I/O优化的实例为万兆或25G共享带宽。
由于是共享网络,因此无法保证带宽速度是不变的。

性能会怎么样? 本质而言要考虑的点:
网络带宽。
磁盘读写速度。
文件大小。
同组storage的个数,因为storage直接要相互同步影响源文件写入的性能。比如 1台服务器写入能力。

举例:
比如三个storage:
磁盘写入能力为:500MB/s,即是4000Mbps
服务器带宽:1000Mbps
局域网带宽:10000Mbps
此时要同时三个storage上传带宽都达到1000M极限,则需要磁盘的写入能力至少是3000Mbps起,而且局域网的带宽至少要达到3000Mpbs,因为局域网之间是需要通过路由去交换数据,并不是两个服务器直连的。
再考虑到方案如果是先上传到nginx,然后再转到fastdfs,则写入能力还要再加上1000Mbps, 所以磁盘写能力至少要达到4000Mbps。

2.3、下载测试

test_download.c + test_upload.sh,他们依赖test_upload后产生的upload里面的file_id.x文件,里面记录了要下载文件的file id。

./test_download 1

测试结果在fastdfs/test/download目录。

2.4、删除测试

test_delete.c + test_delete.sh,他们依赖test_upload后产生的upload里面的file_id.x文件,里面记录了要删除的文件的file id。

./test_delete 1

2.5、测试性能总结

2.5.1 上传文件

提升上传性能的方法:

  1. 增加group(水平扩展)。
  2. 增加带宽(带宽能力)。
  3. 使用读写性能高的磁盘。

单纯增加每个group的storage只能应对上传峰值,不能从根本上提升上传能力。

2.5.2、下载文件

提升下载性能的方法:

  1. 增加storage(少写多读的场景)。
  2. 增加group。
  3. 增加带宽。
  4. 使用读写性能高的磁盘。

fastdfs打满千M带宽是很容易的。

总结

  1. 测试上传中,会受带宽的限制,特别是云服务器qps限制;同时也会收到磁盘写入、读取能力限制。
  2. 单机能做到20k左右数据,tps=5000。

在图床项目中,公网发布和测试是非常重要的步骤,它们有助于确保项目在实际应用环境中的稳定性和可靠性。下面是公网发布和测试的一些总结:

测试:

  1. 功能测试:确保图床项目的基本功能能够正常工作,如上传图片、生成链接、展示图片等。
  2. 性能测试:通过模拟多个用户并发访问图床项目,测试服务器的负载能力和响应速度。可以使用工具(如Apache JMeter)来进行性能测试。
  3. 安全性测试:测试图床项目的安全性,如防止恶意文件上传、防止跨站脚本攻击(XSS)等。可以使用安全测试工具(如OWASP ZAP)来进行安全性测试。
  4. 兼容性测试:确保图床项目在不同的浏览器和操作系统上都能正常运行和显示图片。
  5. 异常情况测试:模拟各种异常情况,如网络中断、数据库故障等,测试图床项目的容错能力和恢复能力。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Long_xu/article/details/127860303