Skip to content

Commit

Permalink
handler: replace remaining use of qtimer with rtimer (#48127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkarneges authored Feb 19, 2025
1 parent 5dac624 commit b7cd15d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
15 changes: 9 additions & 6 deletions src/handler/handlerengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#include <assert.h>
#include <algorithm>
#include <QTimer>
#include <QUrlQuery>
#include <QJsonDocument>
#include <QJsonObject>
Expand Down Expand Up @@ -1156,6 +1155,8 @@ class AcceptWorker : public Deferred
}
};

#define TIMERS_PER_SUBSCRIPTION 1

class Subscription : public QObject
{
Q_OBJECT
Expand Down Expand Up @@ -1185,8 +1186,8 @@ class Subscription : public QObject

void start()
{
timer_ = new QTimer(this);
connect(timer_, &QTimer::timeout, this, &Subscription::timer_timeout);
timer_ = new RTimer;
timer_->timeout.connect(boost::bind(&Subscription::timer_timeout, this));
timer_->setSingleShot(true);
timer_->start(SUBSCRIBED_DELAY);
}
Expand All @@ -1195,9 +1196,8 @@ class Subscription : public QObject

private:
QString channel_;
QTimer *timer_;
RTimer *timer_;

private slots:
void timer_timeout()
{
subscribed();
Expand Down Expand Up @@ -1339,7 +1339,10 @@ class HandlerEngine::Private : public QObject
{
config = _config;

int timersPerSession = qMax(TIMERS_PER_HTTPSESSION, TIMERS_PER_WSSESSION);
// includes worst-case subscriptions and update registrations
int timersPerSession = qMax(TIMERS_PER_HTTPSESSION, TIMERS_PER_WSSESSION) +
(config.connectionSubscriptionMax * TIMERS_PER_SUBSCRIPTION) +
TIMERS_PER_UNIQUE_UPDATE_REGISTRATION;

// enough timers for sessions, plus an extra 100 for misc
RTimer::init((config.connectionsMax * timersPerSession) + 100);
Expand Down
15 changes: 7 additions & 8 deletions src/handler/httpsessionupdatemanager.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Fanout, Inc.
* Copyright (C) 2025 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand All @@ -22,8 +23,8 @@

#include "httpsessionupdatemanager.h"

#include <QTimer>
#include <QUrl>
#include "rtimer.h"
#include "defercall.h"
#include "httpsession.h"

Expand All @@ -38,12 +39,12 @@ class HttpSessionUpdateManager::Private : public QObject
QPair<int, QUrl> key;
QSet<HttpSession*> sessions;
QSet<HttpSession*> deferredSessions;
QTimer *timer;
RTimer *timer;
};

HttpSessionUpdateManager *q;
QHash<QPair<int, QUrl>, Bucket*> buckets;
QHash<QTimer*, Bucket*> bucketsByTimer;
QHash<RTimer*, Bucket*> bucketsByTimer;
QHash<HttpSession*, Bucket*> bucketsBySession;

Private(HttpSessionUpdateManager *_q) :
Expand Down Expand Up @@ -115,10 +116,8 @@ class HttpSessionUpdateManager::Private : public QObject
bucket = new Bucket;
bucket->key = key;
bucket->sessions += hs;
bucket->timer = new QTimer(this);
QObject::connect(bucket->timer, &QTimer::timeout, [this, timer=bucket->timer]() {
this->timer_timeout(timer);
});
bucket->timer = new RTimer;
bucket->timer->timeout.connect(boost::bind(&Private::timer_timeout, this, bucket->timer));

buckets[key] = bucket;
bucketsByTimer[bucket->timer] = bucket;
Expand All @@ -143,7 +142,7 @@ class HttpSessionUpdateManager::Private : public QObject
}

private:
void timer_timeout(QTimer *timer)
void timer_timeout(RTimer *timer)
{
Bucket *bucket = bucketsByTimer.value(timer);
if(!bucket)
Expand Down
3 changes: 3 additions & 0 deletions src/handler/httpsessionupdatemanager.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016 Fanout, Inc.
* Copyright (C) 2025 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand All @@ -25,6 +26,8 @@

#include <QObject>

#define TIMERS_PER_UNIQUE_UPDATE_REGISTRATION 1

class QUrl;
class HttpSession;

Expand Down
9 changes: 4 additions & 5 deletions src/handler/ratelimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <QList>
#include <QMap>
#include <QTimer>
#include "rtimer.h"
#include "defercall.h"

#define MIN_BATCH_INTERVAL 25
Expand Down Expand Up @@ -74,7 +74,7 @@ class RateLimiter::Private : public QObject
bool batchWaitEnabled;
QMap<QString, Bucket> buckets;
QString lastKey;
QTimer *timer;
RTimer *timer;
bool firstPass;
int batchInterval;
int batchSize;
Expand All @@ -90,8 +90,8 @@ class RateLimiter::Private : public QObject
batchSize(-1),
lastBatchEmpty(false)
{
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &Private::timeout);
timer = new RTimer;
timer->timeout.connect(boost::bind(&Private::timeout, this));
}

~Private()
Expand Down Expand Up @@ -290,7 +290,6 @@ class RateLimiter::Private : public QObject
return true;
}

private slots:
void timeout()
{
if(!processBatch())
Expand Down
10 changes: 5 additions & 5 deletions src/handler/sequencer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (C) 2016-2021 Fanout, Inc.
* Copyright (C) 2025 Fastly, Inc.
*
* This file is part of Pushpin.
*
Expand All @@ -23,8 +24,8 @@
#include "sequencer.h"

#include <QDateTime>
#include <QTimer>
#include "log.h"
#include "rtimer.h"
#include "defercall.h"
#include "publishitem.h"
#include "publishlastids.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ class Sequencer::Private : public QObject
PublishLastIds *lastIds;
QHash<QString, ChannelPendingItems> pendingItemsByChannel;
QMap<QPair<qint64, PendingItem*>, PendingItem*> pendingItemsByTime;
QTimer *expireTimer;
RTimer *expireTimer;
int pendingExpireMSecs;
int idCacheTtl;
QHash<QPair<QString, QString>, CachedId*> idCacheById;
Expand All @@ -81,8 +82,8 @@ class Sequencer::Private : public QObject
pendingExpireMSecs(DEFAULT_PENDING_EXPIRE),
idCacheTtl(-1)
{
expireTimer = new QTimer(this);
connect(expireTimer, &QTimer::timeout, this, &Private::expireTimer_timeout);
expireTimer = new RTimer;
expireTimer->timeout.connect(boost::bind(&Private::expireTimer_timeout, this));
}

~Private()
Expand Down Expand Up @@ -230,7 +231,6 @@ class Sequencer::Private : public QObject
}
}

private slots:
void expireTimer_timeout()
{
qint64 now = QDateTime::currentMSecsSinceEpoch();
Expand Down

0 comments on commit b7cd15d

Please sign in to comment.