eclipse-paho / eclipse-paho/paho.mqtt.java

Connection takes too long because of Thread.sleep(100) in some threads of client

Open
#945 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

We found a MqttAsyncClient needs almost 350ms to complete its connection, intuitively, a connection itself should not take so much time...

Then we noticed this may be caused by the following codes in CommsSender, CommsReceiver, CommsCallback

eg. CommsSender

public void start(String threadName, ExecutorService executorService) {
this.threadName = threadName;
synchronized (lifecycle) {
if (current_state == State.STOPPED && target_state == State.STOPPED) {
target_state = State.RUNNING;
if (executorService == null) {
new Thread(this).start();
} else {
senderFuture = executorService.submit(this);
}
}
}
while (!isRunning()) {
try { Thread.sleep(100); } catch (Exception e) { }
}
}

So do they really need to sleep 100ms before running? isRunning() would return true and end the while loop in 5ms around in our tests. Thread.sleep(100) seems to slow down the connection and affect the performance of paho client.

Anyway, this procedure only needs 50ms actually but now it takes 350ms... What do the developers think about this problem? Are there any further considerations about this?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.