1、QPS:
每秒查询率(Queries-per-second)
QPS = req/sec = 请求数/秒
2、TPS
每秒处理的事务数目(Transactions-Per-Second)
TPS 的过程包括:客户端请求服务端、服务端内部处理、服务端返回客户端。
3、PV
页面访问次数:Page View
4、UV
访客数(去重复):Unique Visitor
通过日志估算QPS
①找到tomcat或者nginx的access log
②观察日志规律 127.0.0.1 - - [19/Aug/2019:23:55:27 +0800] “POST /home/index HTTP/1.1” 200 138
③执行命名统计 cat xxx.log |grep ‘xxx’ |cut -d ’ ’ -f4 |uniq -c |sort -n -r |head -n 100
④命令详解
cat xxx.log : 读文件内容
grep ‘xxx’ : 将文件内容按照 xxx 进行过滤
cut -d ’ ’ -f4 : 过滤出来的内容按照空格进行分割,取第四列内容
uniq -c : 每列旁边显示该行重复出现的次数
sort -n -r : 依照数值的大小排序
|head -n 100 :查看前100行
例如:
cat localhost_access_log.2021-07-10.txt |grep 'HEAD / HTTP/1.0' |cut -d ' ' -f4 |uniq -c |sort -n -r |head -n 100
MYSQL 估算QPS TPS
QPS
select VARIABLE_VALUE into @num_queries from GLOBAL_STATUS
where VARIABLE_NAME ='QUESTIONS';
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME ='UPTIME';
select @num_queries/@uptime;
TPS
select VARIABLE_VALUE into @num_com from GLOBAL_STATUS
where VARIABLE_NAME ='Handler_commit';
select VARIABLE_VALUE into @num_roll from GLOBAL_STATUS
where VARIABLE_NAME ='Handler_rollback';
select VARIABLE_VALUE into @uptime from GLOBAL_STATUS
where VARIABLE_NAME ='UPTIME';
select (@num_com+@num_roll)/@uptime;
tomcat配置说明
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
redirectPort="8443"
URIEncoding="UTF-8"
minSpareThreads="100"
maxSpareThreads="500"
maxThreads="1000"
acceptCount="700"
connectionTimeout="30000"
enableLookups="false"/>
maxIdleTime: 最大空闲时间,超过这个空闲时间,且线程数大于minSpareThreads的,都会被回收,默认值1分钟(60000ms);
minSpareThreads:最小空闲线程数,任何情况都会存活的线程数,即便超过了最大空闲时间,也不会被回收,默认值4;
maxSpareThreads:最大空闲线程数,在最大空闲时间(maxIdleTime)内活跃过,此时空闲,当空闲时间大于maxIdleTime则被回收,小则继续存活,等待被调度,默认值50;
maxThreads:最大线程数,大并发请求时,tomcat能创建来处理请求的最大线程数,超过则放入请求队列中进行排队,默认值为200;
acceptCount:当最大线程数(maxThreads)被使用完时,可以放入请求队列排队个数,超过这个数返回connection refused(请求被拒绝),一般设置和maxThreads一样,不过这个具体需要根据自己的应用实际访问峰值和平均值来权衡,默认值为100;
connectionTimeout:网络连接超时,假设设置为0表示永不超时,这样设置隐患巨大,通常可设置为30000ms,默认60000ms。