From fa1bccc12c5c4f9e201898f1e677633ccc129d4c Mon Sep 17 00:00:00 2001 From: Ben Osheroff Date: Fri, 20 Jan 2017 15:34:30 -0800 Subject: [PATCH] don't regex the topic unless needed This is worth about 6% of main-thread performance --- .../com/zendesk/maxwell/producer/MaxwellKafkaProducer.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/zendesk/maxwell/producer/MaxwellKafkaProducer.java b/src/main/java/com/zendesk/maxwell/producer/MaxwellKafkaProducer.java index 3c4b41fec..d178aa036 100644 --- a/src/main/java/com/zendesk/maxwell/producer/MaxwellKafkaProducer.java +++ b/src/main/java/com/zendesk/maxwell/producer/MaxwellKafkaProducer.java @@ -62,6 +62,7 @@ public class MaxwellKafkaProducer extends AbstractAsyncProducer { private final MaxwellKafkaPartitioner partitioner; private final MaxwellKafkaPartitioner ddlPartitioner; private final KeyFormat keyFormat; + private final boolean interpolateTopic; public MaxwellKafkaProducer(MaxwellContext context, Properties kafkaProperties, String kafkaTopic) { super(context); @@ -71,6 +72,7 @@ public MaxwellKafkaProducer(MaxwellContext context, Properties kafkaProperties, this.topic = "maxwell"; } + this.interpolateTopic = kafkaTopic.contains("%{"); this.kafka = new KafkaProducer<>(kafkaProperties, new StringSerializer(), new StringSerializer()); String hash = context.getConfig().kafkaPartitionHash; @@ -97,7 +99,10 @@ private Integer getNumPartitions(String topic) { } private String generateTopic(String topic, RowMap r){ - return topic.replaceAll("%\\{database\\}", r.getDatabase()).replaceAll("%\\{table\\}", r.getTable()); + if ( interpolateTopic ) + return topic.replaceAll("%\\{database\\}", r.getDatabase()).replaceAll("%\\{table\\}", r.getTable()); + else + return topic; } @Override