Queue/throttle fix.

If AIPerService::add_queued_to fails because a new request is throttled,
then do not add the request to the end of the queue, nor remove it from
the queue: do nothing: it makes no sense to move the request to the back
because they all belong to the same service and all of them will be
either throttled or not.

Note: Still need to fix that in this case we should look in queues of
other services.
This commit is contained in:
Aleric Inglewood
2013-05-12 18:10:49 +02:00
parent f8aac1f3dd
commit 67e88561dc
3 changed files with 15 additions and 5 deletions

View File

@@ -287,7 +287,11 @@ void AIPerService::add_queued_to(curlthread::MultiHandle* multi_handle)
{ {
if (!mQueuedRequests.empty()) if (!mQueuedRequests.empty())
{ {
multi_handle->add_easy_request(mQueuedRequests.front()); if (!multi_handle->add_easy_request(mQueuedRequests.front(), true))
{
// Throttled.
return;
}
mQueuedRequests.pop_front(); mQueuedRequests.pop_front();
if (mQueuedRequests.empty()) if (mQueuedRequests.empty())
{ {

View File

@@ -1331,7 +1331,7 @@ void AICurlThread::process_commands(AICurlMultiHandle_wat const& multi_handle_w)
case cmd_boost: // FIXME: future stuff case cmd_boost: // FIXME: future stuff
break; break;
case cmd_add: case cmd_add:
multi_handle_w->add_easy_request(AICurlEasyRequest(command_being_processed_r->easy_request())); multi_handle_w->add_easy_request(AICurlEasyRequest(command_being_processed_r->easy_request()), false);
PerService_wat(*AICurlEasyRequest_wat(*command_being_processed_r->easy_request())->getPerServicePtr())->removed_from_command_queue(); PerService_wat(*AICurlEasyRequest_wat(*command_being_processed_r->easy_request())->getPerServicePtr())->removed_from_command_queue();
break; break;
case cmd_remove: case cmd_remove:
@@ -1701,7 +1701,7 @@ CURLMsg const* MultiHandle::info_read(int* msgs_in_queue) const
static U32 curl_max_total_concurrent_connections = 32; // Initialized on start up by startCurlThread(). static U32 curl_max_total_concurrent_connections = 32; // Initialized on start up by startCurlThread().
void MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request) bool MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request, bool from_queue)
{ {
bool throttled = true; // Default. bool throttled = true; // Default.
AIPerServicePtr per_service; AIPerServicePtr per_service;
@@ -1731,7 +1731,12 @@ void MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request)
llassert(sTotalAdded == mAddedEasyRequests.size()); llassert(sTotalAdded == mAddedEasyRequests.size());
Dout(dc::curl, "MultiHandle::add_easy_request: Added AICurlEasyRequest " << (void*)easy_request.get_ptr().get() << Dout(dc::curl, "MultiHandle::add_easy_request: Added AICurlEasyRequest " << (void*)easy_request.get_ptr().get() <<
"; now processing " << mAddedEasyRequests.size() << " easy handles [running_handles = " << AICurlInterface::Stats::running_handles << "]."); "; now processing " << mAddedEasyRequests.size() << " easy handles [running_handles = " << AICurlInterface::Stats::running_handles << "].");
return; return true;
}
if (from_queue)
{
// Throttled. Do not add to queue, because it is already in the queue.
return false;
} }
// The request could not be added, we have to queue it. // The request could not be added, we have to queue it.
PerService_wat(*per_service)->queue(easy_request); PerService_wat(*per_service)->queue(easy_request);
@@ -1739,6 +1744,7 @@ void MultiHandle::add_easy_request(AICurlEasyRequest const& easy_request)
// Not active yet, but it's no longer an error if next we try to remove the request. // Not active yet, but it's no longer an error if next we try to remove the request.
AICurlEasyRequest_wat(*easy_request)->mRemovedPerCommand = false; AICurlEasyRequest_wat(*easy_request)->mRemovedPerCommand = false;
#endif #endif
return true;
} }
CURLMcode MultiHandle::remove_easy_request(AICurlEasyRequest const& easy_request, bool as_per_command) CURLMcode MultiHandle::remove_easy_request(AICurlEasyRequest const& easy_request, bool as_per_command)

View File

@@ -59,7 +59,7 @@ class MultiHandle : public CurlMultiHandle
~MultiHandle(); ~MultiHandle();
// Add/remove an easy handle to/from a multi session. // Add/remove an easy handle to/from a multi session.
void add_easy_request(AICurlEasyRequest const& easy_request); bool add_easy_request(AICurlEasyRequest const& easy_request, bool from_queue);
CURLMcode remove_easy_request(AICurlEasyRequest const& easy_request, bool as_per_command = false); CURLMcode remove_easy_request(AICurlEasyRequest const& easy_request, bool as_per_command = false);
// Reads/writes available data from a particular socket (non-blocking). // Reads/writes available data from a particular socket (non-blocking).