Ali cloud RocketMQ performance test (a local test)

Due to business needs, the need for Ali cloud RocketMQ performance testing.

Environment, a windows system CPU: I7, Memory: 8G, 64-bit operating system.

Test both scenarios, in order to ensure consistency subscribe relationship (Ali cloud can go to the official website for subscription relationship consistency), consumption is divided into two modes.

1, according to Tag subscribe, subscribe to all Tag, consumer tests using three, three producers, each producer sent ten thousand data into the same Tag in correspondence with a ShardingKey, to ensure that the consumer order.

Test Results:

Ali cloud RocketMQ performance test (a local test)

2, according to subscribe Tag, a Tag each consumer subscription, each Tag in a packet inside.

Test Results:

Ali cloud RocketMQ performance test (a local test)

Paying particular attention to the second, subscription relationship consistency, inconsistency if three consumers in a group, subscription tag, consumption is a problem, it may not be the consumer.

in conclusion:

TPS is less than 100, the cloud-based local to Ali, to go public, the general effect will be behind Ali cloud-based testing within the network, so stay tuned.

Send Message Code:

public static void sendMqMessage( String topic, String tag, String message, String sharding ) {

        String key = UUID.randomUUID().toString();
        Message msg = new Message(
                // Message 所属的 Topic
                topic,
                // Message Tag, 可理解为 Gmail 中的标签,对消息进行再归类,方便 Consumer 指定过滤条件在消息队列 RocketMQ 的服务器过滤
                tag,
                // Message Body 可以是任何二进制形式的数据, 消息队列 RocketMQ 不做任何干预,需要 Producer 与 Consumer 协商好一致的序列化和反序列化方式
                message.getBytes()
        );
        // 设置代表消息的业务关键属性,请尽可能全局唯一。
        // 以方便您在无法正常收到消息情况下,可通过控制台查询消息并补发。
        // 注意:不设置也不会影响消息正常收发
        msg.setKey(key);
        // 分区顺序消息中区分不同分区的关键字段,sharding key 于普通消息的 key 是完全不同的概念。
        // 全局顺序消息,该字段可以设置为任意非空字符串。
        String shardingKey = sharding;
        try {
            SendResult sendResult = producer.send(msg, shardingKey);
            // 发送消息,只要不抛异常就是成功
            if (sendResult != null) {
                //System.out.println(message + tag + sharding);
                if(message.equals("10000")){
                    System.out.println(tag + ":发送完毕10000!");
                }
                //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                //System.out.println(dateFormat.format(new Date()) + "-发送消息成功-sharding:" + shardingKey + ",tag:" + tag + ",key:"+ key + ",msgId:" + sendResult.getMessageId());
            }
        }
        catch (Exception e) {
            // 消息发送失败,需要进行重试处理,可重新发送这条消息或持久化这条数据进行补偿处理
            System.out.println(new Date() + " Send mq message failed. Topic is:" + msg.getTopic());
            throw e;
        }
    }

Consumer Code:

public void consumerMqMessage() {
        String topic = "topic-test";
        String tags = "W3";//第一种模式使用*
        consumer = RocketMqConsumerSingleton.getInstance();
        // 在订阅消息前,必须调用 start 方法来启动 Consumer,只需调用一次即可。
        consumer.subscribe(
            // Message 所属的 Topic
            topic,
            // 订阅指定 Topic 下的 Tags:
            // 1. * 表示订阅所有消息
            // 2. TagA || TagB || TagC 表示订阅 TagA 或 TagB 或 TagC 的消息
            tags,
            new MessageOrderListener() {
                /**
                 * 1. 消息消费处理失败或者处理出现异常,返回 OrderAction.Suspend<br>
                 * 2. 消息处理成功,返回 OrderAction.Success
                 */
                @Override
                public OrderAction consume(Message message, ConsumeOrderContext context) {
                    String msg = new String(message.getBody());
                    //System.out.println(msg);

                    if(msg.equals("1")) {
                        System.out.println(message.getTag() + "开始:" + System.currentTimeMillis());
                    }
                    if(msg.equals("10000")) {
                        System.out.println(message.getTag() + "结束:" + System.currentTimeMillis());
                    }
                    //SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    //System.out.println(dateFormat.format(new Date()) + "-消费消息---sharding:" + message.getShardingKey() + ",tag:" + message.getTag() + ",key: " + message.getKey() + ",MsgId:" + message.getMsgID());
                    try {
                        //Thread.sleep(2000);
                        //System.out.println("-------------消费者睡2秒后----------");
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return OrderAction.Success;
                }
            });
        consumer.start();
    }

Guess you like

Origin blog.51cto.com/janephp/2408070