JMeter 做压测

 

一、使用配置1

 

 

每发一次请求后,思考一秒。

 

最终结果如下:

 

如果此时改小思考时间:

 

 此时的并发是2.

 

此时,如果将线程数修改为2,则:

 

 

并发为4.

 

此时再修改思考时间为100ms,10个线程:

 

 

 

 则并发差不多为100:

 

如果要达到上千并发,则修改思考时间为10ms,看看能否达到:

 

实际上只发出了5000个请求,按理说,10个线程、每10ms发一个请求,(10个线程*10s*1000ms/10ms),按理有10000个请求,但是没达到。

应该是因为线程没办法10s发出一个,因为99% line都是46ms了。

 

如果修改为50个线程,再看看:

 

 此时的并发依然只有500的样子。而90%、95%、99%线达到了数百ms。

 

去掉思考定时器后:

 

看来该接口的并发大概只能支撑这么多了。

 

去掉接口中的分布式锁后,再进行压测:

 1 package com.ceiec.sys.mqservice.service.impl;
 2 
 3 import com.ceiec.sys.mqservice.controller.TestController;
 4 import com.ceiec.sys.mqservice.service.SecondKillService;
 5 import com.ceiec.sys.mqservice.utils.GUID;
 6 import com.ceiec.sys.mqservice.vo.SuccessSecondKillUser;
 7 import com.fasterxml.jackson.databind.ObjectMapper;
 8 import org.redisson.api.RLock;
 9 import org.redisson.api.RedissonClient;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12 import org.springframework.amqp.AmqpException;
13 import org.springframework.amqp.core.Message;
14 import org.springframework.amqp.core.MessagePostProcessor;
15 import org.springframework.amqp.rabbit.core.RabbitTemplate;
16 import org.springframework.amqp.rabbit.support.CorrelationData;
17 import org.springframework.beans.factory.annotation.Autowired;
18 import org.springframework.data.redis.core.ListOperations;
19 import org.springframework.data.redis.core.RedisTemplate;
20 import org.springframework.stereotype.Service;
21 
22 /**
23  * desc:
24  *
25  * @author : caokunliang
26  * creat_date: 2019/7/9 0009
27  * creat_time: 19:34
28  **/
29 @Service
30 public class SecondKillServiceImpl implements SecondKillService {
31     private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
32 
33     private static final Logger logger = LoggerFactory.getLogger(SecondKillServiceImpl.class);
34 
35     @Autowired
36     private RabbitTemplate rabbitTemplate;
37 
38     @Autowired
39     private RedisTemplate<String, Object> redisTemplate;
40 
41     private static final String SECOND_KILL_KEY = "phone";
42     @Autowired
43     private RedissonClient redissonClient;
44 
45     public static final String REDISSON_DISTRIBUTE_KEY="cache.redisson.distribute.lock";
46 
47     @Override
48     public void secondKill(String userId) {
49 //        RLock lock = redissonClient.getLock(REDISSON_DISTRIBUTE_KEY);
50 
51         try {
52 //            lock.lock();
53             //去redis 的队列取
54             ListOperations<String, Object> opsForList = redisTemplate.opsForList();
55             String phone = (String)opsForList.leftPop(SECOND_KILL_KEY);
56             if (phone == null) {
57                 logger.error("{} got phone failed.",userId);
58                 return;
59             }
60 
61             String exchange = "exchange.010";
62             String routingKey = "success-kill";
63 
64             SuccessSecondKillUser user = new SuccessSecondKillUser();
65             user.setUserId(userId);
66             user.setProductId(phone);
67 
68             CorrelationData data = new CorrelationData(phone);
69             try {
70                 //mq消息发送方法
71                 rabbitTemplate.convertAndSend(exchange, routingKey, OBJECT_MAPPER.writeValueAsBytes(user), new MessagePostProcessor() {
72                     //设置消息唯一ID
73                     @Override
74                     public Message postProcessMessage(Message message) throws AmqpException {
75                         message.getMessageProperties().setMessageId(GUID.generate());
76                         return message;
77                     }
78                 },data);
79             }catch (Exception e){
80                 logger.error("e:{}",e);
81                 opsForList.leftPush(SECOND_KILL_KEY,phone);
82             }
83         }catch (Exception e){
84             logger.error("{}",e);
85         }finally {
86 //            lock.unlock();
87         }
88 
89 
90     }
91 
92     @Override
93     public void init(){
94         ListOperations<String, Object> opsForList = redisTemplate.opsForList();
95         for (int i = 0; i < 100; i++) {
96             opsForList.leftPush(SECOND_KILL_KEY,"手机00" + i);
97         }
98     }
99 }

 

 

这下,接口的并发,达到了4000。看来分布式锁还是挺耗时的

posted @ 2019-07-10 10:20  三国梦回  阅读(187)  评论(0编辑  收藏  举报