Преглед изворни кода

2010-03-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Only execute RequestGroupMan::fillRequestGroupFromReserver() when
	queue maintenance is requested by RequestGroup to avoid to call
	the function unnecessarily.
	* src/FillRequestGroupCommand.cc
	* src/RequestGroup.cc
	* src/RequestGroup.h
	* src/RequestGroupMan.cc
	* src/RequestGroupMan.h
Tatsuhiro Tsujikawa пре 15 година
родитељ
комит
fe8fea56ca
6 измењених фајлова са 61 додато и 8 уклоњено
  1. 11 0
      ChangeLog
  2. 12 7
      src/FillRequestGroupCommand.cc
  3. 7 0
      src/RequestGroup.cc
  4. 8 0
      src/RequestGroup.h
  5. 3 1
      src/RequestGroupMan.cc
  6. 20 0
      src/RequestGroupMan.h

+ 11 - 0
ChangeLog

@@ -1,3 +1,14 @@
+2010-03-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Only execute RequestGroupMan::fillRequestGroupFromReserver() when
+	queue maintenance is requested by RequestGroup to avoid to call
+	the function unnecessarily.
+	* src/FillRequestGroupCommand.cc
+	* src/RequestGroup.cc
+	* src/RequestGroup.h
+	* src/RequestGroupMan.cc
+	* src/RequestGroupMan.h
+
 2010-03-05  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Don't use hash for Peer::id. Simple concatenation of ip address

+ 12 - 7
src/FillRequestGroupCommand.cc

@@ -40,6 +40,7 @@
 #include "message.h"
 #include "Logger.h"
 #include "DownloadContext.h"
+#include "ServerStatMan.h"
 
 namespace aria2 {
 
@@ -60,13 +61,17 @@ bool FillRequestGroupCommand::execute()
   if(_e->isHaltRequested()) {
     return true;
   }
-  try {
-    _e->_requestGroupMan->fillRequestGroupFromReserver(_e);
-  } catch(RecoverableException& ex) {
-    logger->error(EX_EXCEPTION_CAUGHT, ex);
-  }
-  if(_e->_requestGroupMan->downloadFinished()) {
-    return true;
+  SharedHandle<RequestGroupMan> rgman = _e->_requestGroupMan;
+  if(rgman->queueCheckRequested()) {
+    try {
+      rgman->fillRequestGroupFromReserver(_e);
+      rgman->clearQueueCheck();
+    } catch(RecoverableException& ex) {
+      logger->error(EX_EXCEPTION_CAUGHT, ex);
+    }
+    if(rgman->downloadFinished()) {
+      return true;
+    }
   }
   _e->addRoutineCommand(this);
   return false;

+ 7 - 0
src/RequestGroup.cc

@@ -130,6 +130,7 @@ RequestGroup::RequestGroup(const SharedHandle<Option>& option):
   _maxDownloadSpeedLimit(option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)),
   _maxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)),
   _belongsToGID(0),
+  _requestGroupMan(0),
   _logger(LogFactory::getInstance())
 {
   _fileAllocationEnabled = _option->get(PREF_FILE_ALLOCATION) != V_NONE;
@@ -799,6 +800,12 @@ void RequestGroup::increaseNumCommand()
 void RequestGroup::decreaseNumCommand()
 {
   --_numCommand;
+  if(!_numCommand && _requestGroupMan) {
+    if(_logger->debug()) {
+      _logger->debug("GID#%d - Request queue check", _gid);
+    }
+    _requestGroupMan->requestQueueCheck();
+  }
 }
 
 

+ 8 - 0
src/RequestGroup.h

@@ -67,6 +67,7 @@ class CheckIntegrityEntry;
 class DownloadResult;
 class URISelector;
 class URIResult;
+class RequestGroupMan;
 #ifdef ENABLE_BITTORRENT
 class BtRuntime;
 class PeerStorage;
@@ -162,6 +163,8 @@ private:
   // RequestGroup.
   int32_t _belongsToGID;
 
+  RequestGroupMan* _requestGroupMan;
+
   Logger* _logger;
 
   void validateFilename(const std::string& expectedFilename,
@@ -488,6 +491,11 @@ public:
     return _belongsToGID;
   }
 
+  void setRequestGroupMan(RequestGroupMan* requestGroupMan)
+  {
+    _requestGroupMan = requestGroupMan;
+  }
+
   static void resetGIDCounter() { _gidCounter = 0; }
 
   static int32_t newGID();

+ 3 - 1
src/RequestGroupMan.cc

@@ -83,7 +83,8 @@ RequestGroupMan::RequestGroupMan
   _maxOverallDownloadSpeedLimit
   (option->getAsInt(PREF_MAX_OVERALL_DOWNLOAD_LIMIT)),
   _maxOverallUploadSpeedLimit(option->getAsInt(PREF_MAX_OVERALL_UPLOAD_LIMIT)),
-  _xmlRpc(option->getAsBool(PREF_ENABLE_XML_RPC))
+  _xmlRpc(option->getAsBool(PREF_ENABLE_XML_RPC)),
+  _queueCheck(true)
 {}
 
 bool RequestGroupMan::downloadFinished()
@@ -497,6 +498,7 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
       }
       configureRequestGroup(groupToAdd);
       createInitialCommand(groupToAdd, commands, e);
+      groupToAdd->setRequestGroupMan(this);
       _requestGroups.push_back(groupToAdd);
       ++count;
       e->addCommand(commands);

+ 20 - 0
src/RequestGroupMan.h

@@ -77,6 +77,8 @@ private:
   // truf if XML-RPC is enabled.
   bool _xmlRpc;
 
+  bool _queueCheck;
+
   std::string
   formatDownloadResult(const std::string& status,
                        const SharedHandle<DownloadResult>& downloadResult) const;
@@ -254,6 +256,24 @@ public:
   {
     _maxSimultaneousDownloads = max;
   }
+
+  // Call this function if _requestGroups queue should be maintained.
+  // This function is added to reduce the call of maintenance, but at
+  // the same time, it provides fast maintenance reaction.
+  void requestQueueCheck()
+  {
+    _queueCheck = true;
+  }
+
+  void clearQueueCheck()
+  {
+    _queueCheck = false;
+  }
+
+  bool queueCheckRequested() const
+  {
+    return _queueCheck;
+  }
 };
 
 typedef SharedHandle<RequestGroupMan> RequestGroupManHandle;