Fix for HTTP/curl waiting on update

This improves responsiveness of TerraSync with small files and general
throughout dramatically.
This commit is contained in:
James Turner 2016-06-08 15:43:59 +01:00
parent 0ccf3e1629
commit 37c551bae7
2 changed files with 10 additions and 3 deletions

View File

@ -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)

View File

@ -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());
}