为什么使用BatcherBuilder.KEY_BASED反而慢了呢?

    @Bean("createPulsarProducer2_myTopic1")
    public Producer createPulsarProducer2_myTopic1() throws PulsarClientException {
        Producer<String> stringProducer = pulsarClient.newProducer(Schema.STRING).topic(myTopic1).create();
        return stringProducer;
    }

    @Bean("createPulsarProducer3_myTopic1")
    public Producer createPulsarProducer3_myTopic1() throws PulsarClientException {
        Producer<String> stringProducer = pulsarClient.newProducer(Schema.STRING).topic(myTopic1).batcherBuilder(BatcherBuilder.KEY_BASED).create();
        return stringProducer;
    }
    @RequestMapping("sendMessage2")
    public String sendMessage2() throws PulsarClientException {
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            producer2.newMessage().key("key1").value("key1_消息1").sendAsync();
            producer2.newMessage().key("key2").value("key2_消息1").sendAsync();
            producer2.newMessage().key("key3").value("key3_消息1").sendAsync();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("sendMessage2耗时:" + (endTime - beginTime));
        return "成功生产2";
    }


    @RequestMapping("sendMessage3")
    public String sendMessage3() throws PulsarClientException {
        long beginTime = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            producer3.newMessage().key("key1").value("key1_消息" + (i + 1)).sendAsync();
            producer3.newMessage().key("key2").value("key2_消息" + (i + 1)).sendAsync();
            producer3.newMessage().key("key3").value("key3_消息" + (i + 1)).sendAsync();
        }
        long endTime = System.currentTimeMillis();
        System.out.println("sendMessage3耗时:" + (endTime - beginTime));
        return "成功生产3";
    }

跑出来的结果是sendMessage3比sendMessage2慢,不知道什么原因,感谢。

慢了,也就失去批处理的意义了。不知道哪里有问题,感谢。

已自行已解决!感谢,和禁用enablebatch有关