Skip to content

Commit d2bc632

Browse files
authored
Perf fixes (#22)
* Fixed tight spin lock at poll which can result in 100% CPU if no new messages * Fixed leak in processor object use * Updated travis to also publish to local gh-pages if on SolaceDev * Fine-tuned spin turns for poll
1 parent 0abc783 commit d2bc632

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,20 @@ after_success:
2727
git remote add origin-pages https://${GH_TOKEN}@github.com/SolaceProducts/pubsubplus-connector-kafka-source.git > /dev/null 2>&1;
2828
git push --quiet --set-upstream origin-pages gh-pages;
2929
echo "Updated and pushed GH pages!";
30+
elif [ "$TRAVIS_PULL_REQUEST" = "false" ] && ! [ $(echo $TRAVIS_REPO_SLUG | grep "SolaceProducts") ]; then
31+
git config --global user.email "travis@travis-ci.org";
32+
git config --global user.name "travis-ci";
33+
mkdir gh-pages; # Now update gh-pages
34+
git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG gh-pages > /dev/null 2>&1;
35+
rm gh-pages/downloads/pubsubplus-connector-kafka-source*
36+
mv build/distributions/pubsubplus-connector-kafka-source* gh-pages/downloads
37+
cd gh-pages;
38+
pushd downloads
39+
cp index.template index.html; FILENAME=`find . | grep *.zip | cut -d'/' -f2 | sed 's/.\{4\}$//'`; sed -i "s/CONNECTOR_NAME/$FILENAME/g" index.html;
40+
popd;
41+
git add -f .;
42+
git commit -m "Latest connector distribution on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages";
43+
git remote add origin-pages https://${GH_TOKEN}@github.com/$TRAVIS_REPO_SLUG.git > /dev/null 2>&1;
44+
git push --quiet --set-upstream origin-pages gh-pages;
45+
echo "Updated and pushed GH pages!";
3046
fi

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=2.0.1
1+
version=2.0.2

src/main/java/com/solace/connector/kafka/connect/source/SolaceSourceTask.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,12 @@
2424
import com.solacesystems.jcsmp.JCSMPException;
2525
import com.solacesystems.jcsmp.JCSMPProperties;
2626
import com.solacesystems.jcsmp.JCSMPSession;
27-
import com.solacesystems.jcsmp.JCSMPSessionStats;
28-
import com.solacesystems.jcsmp.statistics.StatType;
29-
3027
import java.util.ArrayList;
3128
import java.util.Collections;
32-
import java.util.Enumeration;
3329
import java.util.List;
3430
import java.util.Map;
3531
import java.util.concurrent.BlockingQueue;
3632
import java.util.concurrent.LinkedBlockingQueue;
37-
import java.util.concurrent.TimeUnit;
38-
import java.util.concurrent.atomic.AtomicBoolean;
39-
4033
import org.apache.kafka.connect.source.SourceRecord;
4134
import org.apache.kafka.connect.source.SourceTask;
4235
import org.slf4j.Logger;
@@ -59,7 +52,7 @@ public class SolaceSourceTask extends SourceTask { // implements XMLMessageListe
5952
String skafkaTopic;
6053
SolaceSourceTopicListener topicListener = null;
6154
SolaceSourceQueueConsumer queueConsumer = null;
62-
55+
private int spinTurns = 0;
6356
private volatile boolean shuttingDown = false;
6457

6558
// private Class<?> cProcessor;
@@ -74,6 +67,16 @@ public String version() {
7467
public void start(Map<String, String> props) {
7568

7669
connectorConfig = new SolaceSourceConnectorConfig(props);
70+
try {
71+
processor = connectorConfig
72+
.getConfiguredInstance(SolaceSourceConstants
73+
.SOL_MESSAGE_PROCESSOR, SolMessageProcessorIF.class);
74+
} catch (Exception e) {
75+
log.info(
76+
"================ Encountered exception in creating the message processor."
77+
+ " Cause: {}, Stacktrace: {} ",
78+
e.getCause(), e.getStackTrace());
79+
}
7780
skafkaTopic = connectorConfig.getString(SolaceSourceConstants.KAFKA_TOPIC);
7881
solSessionHandler = new SolSessionHandler(connectorConfig);
7982
try {
@@ -106,20 +109,23 @@ public void start(Map<String, String> props) {
106109
public synchronized List<SourceRecord> poll() throws InterruptedException {
107110

108111
if (shuttingDown || ingressMessages.size() == 0) {
109-
return null; // Nothing to do, return control
112+
spinTurns++;
113+
if (spinTurns > 100) {
114+
spinTurns = 0;
115+
Thread.sleep(1);
116+
}
117+
return null; // Nothing to do, return control
110118
}
111119
// There is at least one message to process
120+
spinTurns = 0; // init spinTurns again
112121
List<SourceRecord> records = new ArrayList<>();
113122
int processedInIhisBatch = 0;
114123
int count = 0;
115124
int arraySize = ingressMessages.size();
116125
while (count < arraySize) {
117126
BytesXMLMessage msg = ingressMessages.take();
118127
try {
119-
processor = connectorConfig
120-
.getConfiguredInstance(SolaceSourceConstants
121-
.SOL_MESSAGE_PROCESSOR, SolMessageProcessorIF.class)
122-
.process(connectorConfig.getString(SolaceSourceConstants.SOL_KAFKA_MESSAGE_KEY), msg);
128+
processor.process(connectorConfig.getString(SolaceSourceConstants.SOL_KAFKA_MESSAGE_KEY), msg);
123129
} catch (Exception e) {
124130
log.info(
125131
"================ Encountered exception in message processing....discarded."

src/main/java/com/solace/connector/kafka/connect/source/VersionUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public class VersionUtil {
77
*/
88
public static String getVersion() {
99

10-
return "2.0.1";
10+
return "2.0.2";
1111

1212
}
1313

0 commit comments

Comments
 (0)