Skip to content

Commit

Permalink
total req session boostificaiton
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-fastly committed Jan 29, 2024
1 parent 30cf283 commit cf59726
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/cpp/proxy/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
struct RequestSessionConnections {
Connection inspectedConnection;
Connection inspectErrorConnection;
Connection finishedConnection;
Connection finishedByAcceptConnection;
};

Expand Down Expand Up @@ -600,10 +601,10 @@ class Engine::Private : public QObject
rs->setAutoShare(autoShare);

// TODO: use callbacks for performance
connect(rs, &RequestSession::finished, this, &Private::rs_finished);
reqSessionConnectionMap[rs] = {
rs->inspected.connect(boost::bind(&Private::rs_inspected, this, boost::placeholders::_1, rs)),
rs->inspectError.connect(boost::bind(&Private::rs_inspectError, this, rs)),
rs->finished.connect(boost::bind(&Private::rs_finished, this, rs)),
rs->finishedByAccept.connect(boost::bind(&Private::rs_finishedByAccept, this, rs))
};

Expand Down Expand Up @@ -748,11 +749,8 @@ class Engine::Private : public QObject
doProxy(rs, &idata);
}

private slots:
void rs_finished()
void rs_finished(RequestSession *rs)
{
RequestSession *rs = (RequestSession *)sender();

if(!rs->isSockJs())
logFinished(rs);

Expand All @@ -763,7 +761,6 @@ private slots:
tryTakeNext();
}

private:
void rs_finishedByAccept(RequestSession *rs)
{
logFinished(rs, true);
Expand Down
11 changes: 5 additions & 6 deletions src/cpp/proxy/proxysession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ using std::map;
struct RequestSessionConnections {
Connection bytesWrittenConnection;
Connection errorRespondingConnection;
Connection finishedConnection;
Connection pausedConnection;
Connection headerBytesSentConnection;
Connection bodyBytesSentConnection;
Expand Down Expand Up @@ -249,10 +250,10 @@ class ProxySession::Private : public QObject

sessionItems += si;
sessionItemsBySession.insert(rs, si);
connect(rs, &RequestSession::finished, this, &Private::rs_finished);
reqSessionConnectionMap[rs] = {
rs->bytesWritten.connect(boost::bind(&Private::rs_bytesWritten, this, boost::placeholders::_1, rs)),
rs->errorResponding.connect(boost::bind(&Private::rs_errorResponding, this, rs)),
rs->finished.connect(boost::bind(&Private::rs_finished, this, rs)),
rs->paused.connect(boost::bind(&Private::rs_paused, this, rs)),
rs->headerBytesSent.connect(boost::bind(&Private::rs_headerBytesSent, this, boost::placeholders::_1, rs)),
rs->bodyBytesSent.connect(boost::bind(&Private::rs_bodyBytesSent, this, boost::placeholders::_1, rs))
Expand Down Expand Up @@ -1180,7 +1181,6 @@ class ProxySession::Private : public QObject
}
}

public slots:
void rs_bytesWritten(int count, RequestSession *rs)
{
log_debug("proxysession: %p response bytes written id=%s: %d", q, rs->rid().second.data(), count);
Expand All @@ -1198,10 +1198,8 @@ public slots:
tryResponseRead();
}

void rs_finished()
void rs_finished(RequestSession *rs)
{
RequestSession *rs = (RequestSession *)sender();

log_debug("proxysession: %p response finished id=%s", q, rs->rid().second.data());

SessionItem *si = sessionItemsBySession.value(rs);
Expand All @@ -1220,6 +1218,7 @@ public slots:

sessionItemsBySession.remove(rs);
sessionItems.remove(si);
reqSessionConnectionMap.erase(rs);
delete rs;

delete si;
Expand Down Expand Up @@ -1376,7 +1375,6 @@ public slots:
incCounter(Stats::ClientContentBytesSent, count);
}

public:
void acceptRequest_finished()
{
if(acceptRequest->success())
Expand Down Expand Up @@ -1407,6 +1405,7 @@ public slots:
foreach(RequestSession *rs, toDestroy)
{
q->requestSessionDestroyed(rs, true);
reqSessionConnectionMap.erase(rs);
delete rs;
if(!self)
return;
Expand Down
10 changes: 7 additions & 3 deletions src/cpp/proxy/requestsession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class RequestSession::Private : public QObject
isSockJs = true;
sockJsManager->giveRequest(zhttpRequest, route.sockJsPath.length(), route.sockJsAsPath, route);
zhttpRequest = 0;
QMetaObject::invokeMethod(q, "finished", Qt::QueuedConnection);
QMetaObject::invokeMethod(q, "doFinished", Qt::QueuedConnection);
return;
}
}
Expand Down Expand Up @@ -817,7 +817,7 @@ class RequestSession::Private : public QObject
if(zhttpRequest->isFinished())
{
cleanup();
emit q->finished();
q->finished();
}
}

Expand Down Expand Up @@ -867,7 +867,7 @@ class RequestSession::Private : public QObject
{
log_debug("requestsession: request error id=%s", rid.second.data());
cleanup();
emit q->finished();
q->finished();
}

void inspectRequest_finished()
Expand Down Expand Up @@ -962,6 +962,10 @@ class RequestSession::Private : public QObject
}

public slots:
void doFinished(){
q->finished();
}

void doResponseUpdate()
{
pendingResponseUpdate = false;
Expand Down
4 changes: 1 addition & 3 deletions src/cpp/proxy/requestsession.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class RequestSession : public QObject

Signal inspectError;
boost::signals2::signal<void(const InspectData&)> inspected;
Signal finished;
Signal finishedByAccept;
SignalInt bytesWritten;
Signal paused;
Expand All @@ -116,9 +117,6 @@ class RequestSession : public QObject
// should still wait for finished()
Signal errorResponding;

signals:
void finished();

private:
class Private;
friend class Private;
Expand Down

0 comments on commit cf59726

Please sign in to comment.