From 37c551bae7418deaead07cb5495b6d95712c82b7 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 8 Jun 2016 15:43:59 +0100 Subject: [PATCH] Fix for HTTP/curl waiting on update This improves responsiveness of TerraSync with small files and general throughout dramatically. --- simgear/io/HTTPClient.cxx | 11 +++++++++-- simgear/scene/tsync/terrasync.cxx | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/simgear/io/HTTPClient.cxx b/simgear/io/HTTPClient.cxx index 2e3192f6..bc0a84fe 100644 --- a/simgear/io/HTTPClient.cxx +++ b/simgear/io/HTTPClient.cxx @@ -161,7 +161,15 @@ void Client::setMaxPipelineDepth(unsigned int depth) void Client::update(int waitTimeout) { - int remainingActive, messagesInQueue; + if (d->requests.empty()) { + // curl_multi_wait returns immediately if there's no requests active, + // but that can cause high CPU usage for us. + SGTimeStamp::sleepForMSec(waitTimeout); + return; + } + + int remainingActive, messagesInQueue, numFds; + curl_multi_wait(d->curlMulti, NULL, 0, waitTimeout, &numFds); curl_multi_perform(d->curlMulti, &remainingActive); CURLMsg* msg; @@ -202,7 +210,6 @@ void Client::update(int waitTimeout) SG_LOG(SG_IO, SG_ALERT, "unknown CurlMSG:" << msg->msg); } } // of curl message processing loop - SGTimeStamp::sleepForMSec(waitTimeout); } void Client::makeRequest(const Request_ptr& r) diff --git a/simgear/scene/tsync/terrasync.cxx b/simgear/scene/tsync/terrasync.cxx index bc8b14ac..56aa2cc8 100644 --- a/simgear/scene/tsync/terrasync.cxx +++ b/simgear/scene/tsync/terrasync.cxx @@ -570,7 +570,7 @@ void SGTerraSync::WorkerThread::runInternal() { while (!_stop) { try { - _http.update(100); + _http.update(10); } catch (sg_exception& e) { SG_LOG(SG_TERRASYNC, SG_WARN, "failure doing HTTP update" << e.getFormattedMessage()); }