6 Jmeter 压测
1 查询商品 goods/to_list
- 1000 * 10
2 10000 * 1
![]()
3 10000 * 10

2 查询用户 user/info

3 csv config
user,userToken
19860207586,beee92446e3349bdb3b2321c5eed6d24
4 JMeter 命令行
- 在windows上录好jmx
- 命令行:sh jmeter.sh -n -t XXX.jmx -l result.jtl
- 把result.jtl 导入到jmeter
5 redis 压测
- [100个并发连接,100000个请求]
redis-benchmark -h 10.23.23.25 -p 6379 -c 100 -n 100000
# 或者
redis-benchmark -h 127.0.0.1 -p 6379 -c 100 -n 100000 - 存取大小为100 字节的数据包
redis-benchmark -h 10.23.23.25 -p 6379 -q -d 100报错:(base) gigabyte@gigabyte-X299-UD4-Pro:~$ redis-benchmark -h 127.0.0.1 -p 6379 -c 100 -n 100000
ERROR: NOAUTH Authentication required.
ERROR: failed to fetch CONFIG from 127.0.0.1:6379
分析: 应该是需要验证密码
解决:redis-benchmark -h
发现 -a

redis-benchmark -h 10.23.23.25 -p 6379 -c 100 -n 100000 -a 123

redis-benchmark -h 10.23.23.25 -p 6379 -q -d 100 -a 123
6 命令行下压测
- 1 先去启动后台程序
sudo nohup java -jar miaosha.jar >> miaosha.out 2>&1 &- 2 将jmeter上传至服务器
![]()
- 3 执行命令
./apache-jmeter-5.4.1/bin/jmeter.sh -n -t good_list.jmx -l result.jtl 

- 4 查看处理器
cat /proc/cpu info | grep processor
![]()
- 5 下载result.jtl,放回jmeter中查看
![]()
7 生成user插入到数据库中
List<MiaoshaUser> users = new ArrayList<MiaoshaUser>(count);//生成用户for(int i=0;i<count;i++) {
MiaoshaUser user = new MiaoshaUser(); user.setId(13000000000L+i); user.setLoginCount(1); user.setNickname("user"+i); user.setRegisterDate(new Date()); user.setSalt("1a2b3c"); user.setPassword(MD5Util.inputPassToDbPass("123456", user.getSalt())); users.add(user);}
System.out.println("create user");//插入数据库Connection conn = DBUtil.getConn();String sql = "insert into miaosha_user(login_count, nickname, register_date, salt, password, id)values(?,?,?,?,?,?)";PreparedStatement pstmt = conn.prepareStatement(sql);System.out.println("users.size(): " + users.size());for(int i=0;i<users.size();i++) {
MiaoshaUser user = users.get(i); pstmt.setInt(1, user.getLoginCount()); pstmt.setString(2, user.getNickname()); pstmt.setTimestamp(3, new Timestamp(user.getRegisterDate().getTime())); pstmt.setString(4, user.getSalt()); pstmt.setString(5, user.getPassword()); pstmt.setLong(6, user.getId()); pstmt.addBatch();}
pstmt.executeBatch();pstmt.close();conn.close();System.out.println("insert to db");8 登录,生成token
- 1 修改login/do_login
@RequestMapping("/do_login")
@ResponseBodypublic Result<Boolean> doLogin(HttpServletResponse response, @Valid LoginVo loginVo){
log.info(loginVo.toString()); Boolean b = miaoshaUserService.login(response, loginVo); return Result.success(true);}
# -- > 变成
@RequestMapping("/do_login")
@ResponseBodypublic Result<String> doLogin(HttpServletResponse response, @Valid LoginVo loginVo) {
log.info(loginVo.toString()); //登录 String token = miaoshaUserService.login(response, loginVo); return Result.success(token);}
# service 里
// return true; return token;//登录,生成tokenString urlString = "http://10.23.23.25:8080/login/do_login";File file = new File("D:/tokens.txt");if(file.exists()) {
file.delete();}
RandomAccessFile raf = new RandomAccessFile(file, "rw");file.createNewFile();raf.seek(0);for(int i=0;i<users.size();i++) {
MiaoshaUser user = users.get(i); URL url = new URL(urlString); HttpURLConnection co = (HttpURLConnection)url.openConnection(); co.setRequestMethod("POST"); co.setDoOutput(true); OutputStream out = co.getOutputStream(); String params = "mobile="+user.getId()+"&password="+MD5Util.inputPassFormPass("123456"); out.write(params.getBytes()); out.flush(); InputStream inputStream = co.getInputStream(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); byte buff[] = new byte[1024]; int len = 0; while((len = inputStream.read(buff)) >= 0) {
bout.write(buff, 0 ,len); }
inputStream.close(); bout.close(); String response = new String(bout.toByteArray()); JSONObject jo = JSON.parseObject(response); String token = jo.getString("data"); System.out.println("create token : " + user.getId()); String row = user.getId()+","+token; raf.seek(raf.length()); raf.write(row.getBytes()); raf.write("\r\n".getBytes()); System.out.println("write to file : " + user.getId());}
raf.close();System.out.println("over.................");9 jmeter上配置

修改miaosha.jmx文件

./apache-jmeter-5.4.1/bin/jmeter.sh -n -t miaosha.jmx -l miaosha_result.jtl 





浙公网安备 33010602011771号