From df2fe42c4aadd2655425b3fc3b5626f22a2dc9ab Mon Sep 17 00:00:00 2001 From: Gaute Lindkvist Date: Thu, 6 Jun 2019 10:57:07 +0200 Subject: [PATCH] Python: gRPC timeout --- .../Application/RiaGuiApplication.cpp | 22 +++++++++++++++++-- .../GrpcInterface/RiaGrpcServer.cpp | 11 ++++++---- ApplicationCode/GrpcInterface/RiaGrpcServer.h | 2 +- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/ApplicationCode/Application/RiaGuiApplication.cpp b/ApplicationCode/Application/RiaGuiApplication.cpp index f6971f190b..b2180ef5cf 100644 --- a/ApplicationCode/Application/RiaGuiApplication.cpp +++ b/ApplicationCode/Application/RiaGuiApplication.cpp @@ -112,6 +112,7 @@ #include "cvfProgramOptions.h" #include "cvfqtUtils.h" +#include #include #include #include @@ -1238,7 +1239,7 @@ void RiaGuiApplication::launchGrpcServer() m_grpcServer->runInThread(); m_idleTimer = new QTimer(this); connect(m_idleTimer, SIGNAL(timeout()), this, SLOT(runIdleProcessing())); - m_idleTimer->start(0); + m_idleTimer->start(5); #endif } @@ -1696,7 +1697,24 @@ void RiaGuiApplication::runIdleProcessing() } else if (!caf::ProgressInfoStatic::isRunning()) { - m_grpcServer->processAllQueuedRequests(); + static int idleIterationCount = 0; + int iterationInterval = 0; + if (m_grpcServer->processAllQueuedRequests() > 0) + { + idleIterationCount = 0; + } + else + { + idleIterationCount = std::min(++idleIterationCount, 500); + if (idleIterationCount == 500) + { + iterationInterval = 5; + } + } + if (iterationInterval != m_idleTimer->interval()) + { + m_idleTimer->setInterval(iterationInterval); + } } #endif } diff --git a/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp b/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp index ddd1ff9082..6a98af95b3 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp +++ b/ApplicationCode/GrpcInterface/RiaGrpcServer.cpp @@ -61,7 +61,7 @@ public: void run(); void runInThread(); void initialize(); - void processAllQueuedRequests(); + size_t processAllQueuedRequests(); void quit(); private: @@ -168,7 +168,7 @@ void RiaGrpcServerImpl::initialize() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaGrpcServerImpl::processAllQueuedRequests() +size_t RiaGrpcServerImpl::processAllQueuedRequests() { std::list waitingRequests; { @@ -176,6 +176,8 @@ void RiaGrpcServerImpl::processAllQueuedRequests() std::lock_guard requestLock(m_requestMutex); waitingRequests.swap(m_unprocessedRequests); } + size_t count = waitingRequests.size(); + // Now free to receive new requests from client while processing the current ones. while (!waitingRequests.empty()) { @@ -183,6 +185,7 @@ void RiaGrpcServerImpl::processAllQueuedRequests() waitingRequests.pop_front(); process(method); } + return count; } //-------------------------------------------------------------------------------------------------- @@ -339,9 +342,9 @@ void RiaGrpcServer::initialize() //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -void RiaGrpcServer::processAllQueuedRequests() +size_t RiaGrpcServer::processAllQueuedRequests() { - m_serverImpl->processAllQueuedRequests(); + return m_serverImpl->processAllQueuedRequests(); } //-------------------------------------------------------------------------------------------------- diff --git a/ApplicationCode/GrpcInterface/RiaGrpcServer.h b/ApplicationCode/GrpcInterface/RiaGrpcServer.h index e6c42e3d7b..769bfd348e 100644 --- a/ApplicationCode/GrpcInterface/RiaGrpcServer.h +++ b/ApplicationCode/GrpcInterface/RiaGrpcServer.h @@ -41,7 +41,7 @@ public: bool isRunning() const; void run(); void runInThread(); - void processAllQueuedRequests(); + size_t processAllQueuedRequests(); void quit(); static int findAvailablePortNumber(int defaultPortNumber); static void setReceivedExitRequest();