Skip to content

Commit

Permalink
Reduce event loop overhead on delayed start
Browse files Browse the repository at this point in the history
  • Loading branch information
halfgaar committed Sep 12, 2021
1 parent 74a46cd commit f6c6149
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions MqttLoadSimulator/clientpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ ClientPool::ClientPool(QString hostname, quint16 port, QString username, QString
{
this->clientPoolRandomId = GetRandomString();

connectNextBatchTimer.setSingleShot(true);
connectNextBatchTimer.setSingleShot(delay == 0);
connectNextBatchTimer.setInterval(static_cast<int>(delay));
connect(&connectNextBatchTimer, &QTimer::timeout, this, &ClientPool::startClients);

if (delay > 0)
connectNextBatchTimer.start();

for (int i = 0; i < amount; i++)
{
OneClient *oneClient = new OneClient(hostname, port, username, password, pub_and_sub, i, clientIdPart, ssl, this->clientPoolRandomId,
Expand All @@ -37,7 +40,6 @@ void ClientPool::startClients()
// Doing this with the timer to avoid blocking the event loop and allowing other events to be processed first.
if (this->delay > 0)
{
connectNextBatchTimer.start();
break;
}
else
Expand All @@ -50,4 +52,9 @@ void ClientPool::startClients()
}
}
}

if (clientsToConnect.empty())
{
connectNextBatchTimer.stop();
}
}

0 comments on commit f6c6149

Please sign in to comment.