需要指导以增加我们项目的请求流量

如何解决需要指导以增加我们项目的请求流量

我们的项目遇到了数据库问题。

我们希望每秒支持至少 20 个请求,但是如果我们达到这个数字(使用压力测试设置),即使实际请求的代码被禁用,我们的数据库或设置中的其他内容也无法应对这种负载(这意味着 API 只检查用户是否是有效用户,而不是完成应该做的整个工作)。此时用户表不到100行10列。

堆栈是用 docker 构建的。我们使用 MySQL 8.0.14。该项目是在 yii2 上编写的,我们在每次查询时都使用 ActiveRecord 访问数据库。

一个请求的工作流程如下。当用户发出 API 请求时,会同时发送一个 JWT 令牌。然后 API 向 MongoDB 请求此令牌以验证它是我们的。如果是这种情况,那么使用来自 mongo 的 userId,我们会从 MySQL 中询问此用户的数据,该用户所需的所有信息都存储在何处。之后,我们执行请求的代码。

我们关注的压力测试查询是当我们模拟 500 个用户每 10 秒发出 1 个请求并运行 3 分钟时。在这个测试中,我们禁用了请求的代码,我们只让代码检查用户的有效性。结果如下:

我们用来模拟交通的程序here

正在运行:./hey -c 500 -q 0.1 -z 3m

  Summary:
  Total:        191.2756 secs
  Slowest:      19.9512 secs
  Fastest:      0.2022 secs
  Average:      9.1227 secs
  Requests/sec: 40.1306

Response time histogram:
  0.202 [1]     |
  2.177 [639]   |■■■■■■■■■■■■■
  4.152 [320]   |■■■■■■
  6.127 [750]   |■■■■■■■■■■■■■■■
  8.102 [1355]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■
  10.077 [881]  |■■■■■■■■■■■■■■■■■■
  12.052 [671]  |■■■■■■■■■■■■■
  14.026 [2012] |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  16.001 [527]  |■■■■■■■■■■
  17.976 [25]   |
  19.951 [12]   |

Status code distribution:
  [200] 6550 responses
  [500] 34 responses
  [502] 609 responses

可以找到更多测试here

仅验证用户时请求访问的表


CREATE TABLE `user_profile` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,`company_id` int(10) unsigned NOT NULL,`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,`system_status` tinyint(3) unsigned NOT NULL,`email` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,`telephone` varchar(15) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,`last_login_datetime` datetime DEFAULT NULL,`creation_datetime` datetime NOT NULL,`modification_datetime` datetime NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `user_profile@email_uniqueIdx` (`email`),UNIQUE KEY `user_profile@telephone_uniqueIdx` (`telephone`),KEY `user_profile@company_id_idx` (`company_id`),CONSTRAINT `fk_user_profile_w_company` FOREIGN KEY (`company_id`) REFERENCES `company` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_c



CREATE TABLE `user_profile_role` (
 `user_profile_id` int(10) unsigned NOT NULL,`role` tinyint(3) unsigned NOT NULL,PRIMARY KEY (`user_profile_id`,`role`),CONSTRAINT `fk_user_profile_role_w_user_profile` FOREIGN KEY (`user_profile_id`) REFERENCES `user_profile` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci




CREATE TABLE `company` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,`website` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,UNIQUE KEY `company@name_uniqueIdx` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci



mongo db


* This is the model class for table "UserProfileJsonWebToken".
*
* @property ObjectId $_id
* @property int $userProfileId
* @property string $value
* @property int $acquireCount
* @property int $systemStatus
* @property string $lastUseDatetime
* @property string $creationDatetime
* @property string $modificationDatetime
*/

当 DB 未加载时,启用代码的请求需要 361 毫秒

发布请求的 Yii 调试日志 here


1.更新 禁用调试模式并添加缓存后


main-db.php

        'enableSchemaCache' => true,'schemaCacheDuration' => 86400,'schemaCache' => 'cache',

main.php

    'components' => [
        'cache' => [

            'class' => 'yii\caching\FileCache',],

我得到了这个结果

Summary:
  Total:        187.0877 secs
  Slowest:      7.3969 secs
  Fastest:      0.1197 secs
  Average:      3.5332 secs
  Requests/sec: 48.1058

  Total data:   1239578 bytes
  Size/request: 143 bytes

Response time histogram:
  0.120 [1]     |
  0.847 [187]   |■■■■■
  1.575 [1633]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  2.303 [1078]  |■■■■■■■■■■■■■■■■■■■■■■■■■■
  3.031 [1102]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■
  3.758 [811]   |■■■■■■■■■■■■■■■■■■■■
  4.486 [628]   |■■■■■■■■■■■■■■■
  5.214 [1172]  |■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
  5.941 [905]   |■■■■■■■■■■■■■■■■■■■■■■
  6.669 [687]   |■■■■■■■■■■■■■■■■■
  7.397 [455]   |■■■■■■■■■■■


Latency distribution:
  10% in 1.1331 secs
  25% in 1.8714 secs
  50% in 3.3492 secs
  75% in 5.1533 secs
  90% in 6.2478 secs
  95% in 6.7027 secs
  99% in 7.2395 secs

Details (average,fastest,slowest):
  DNS+dialup:   0.0100 secs,0.1197 secs,7.3969 secs
  DNS-lookup:   0.0000 secs,0.0000 secs,0.0000 secs
  req write:    0.0001 secs,0.0115 secs
  resp wait:    3.5052 secs,0.1163 secs,7.3231 secs
  resp read:    0.0001 secs,0.0024 secs

Status code distribution:
  [200] 7446 responses
  [502] 1213 responses

Error distribution:
  [341]Post "http://127.0.0.1/api/v1/vehicle-locations": EOF

我有很大的进步,但需要做更多的工作

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-
参考1 参考2 解决方案 # 点击安装源 协议选择 http:// 路径填写 mirrors.aliyun.com/centos/8.3.2011/BaseOS/x86_64/os URL类型 软件库URL 其他路径 # 版本 7 mirrors.aliyun.com/centos/7/os/x86
报错1 [root@slave1 data_mocker]# kafka-console-consumer.sh --bootstrap-server slave1:9092 --topic topic_db [2023-12-19 18:31:12,770] WARN [Consumer clie
错误1 # 重写数据 hive (edu)> insert overwrite table dwd_trade_cart_add_inc > select data.id, > data.user_id, > data.course_id, > date_format(
错误1 hive (edu)> insert into huanhuan values(1,'haoge'); Query ID = root_20240110071417_fe1517ad-3607-41f4-bdcf-d00b98ac443e Total jobs = 1
报错1:执行到如下就不执行了,没有显示Successfully registered new MBean. [root@slave1 bin]# /usr/local/software/flume-1.9.0/bin/flume-ng agent -n a1 -c /usr/local/softwa
虚拟及没有启动任何服务器查看jps会显示jps,如果没有显示任何东西 [root@slave2 ~]# jps 9647 Jps 解决方案 # 进入/tmp查看 [root@slave1 dfs]# cd /tmp [root@slave1 tmp]# ll 总用量 48 drwxr-xr-x. 2
报错1 hive> show databases; OK Failed with exception java.io.IOException:java.lang.RuntimeException: Error in configuring object Time taken: 0.474 se
报错1 [root@localhost ~]# vim -bash: vim: 未找到命令 安装vim yum -y install vim* # 查看是否安装成功 [root@hadoop01 hadoop]# rpm -qa |grep vim vim-X11-7.4.629-8.el7_9.x
修改hadoop配置 vi /usr/local/software/hadoop-2.9.2/etc/hadoop/yarn-site.xml # 添加如下 <configuration> <property> <name>yarn.nodemanager.res