summaryrefslogtreecommitdiff
path: root/src/RequestGroupMan.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/RequestGroupMan.h')
-rw-r--r--src/RequestGroupMan.h165
1 files changed, 68 insertions, 97 deletions
diff --git a/src/RequestGroupMan.h b/src/RequestGroupMan.h
index d45014cf..566b77d3 100644
--- a/src/RequestGroupMan.h
+++ b/src/RequestGroupMan.h
@@ -62,10 +62,9 @@ class UriListParser;
class WrDiskCache;
class OpenedFileCounter;
-typedef IndexedList<a2_gid_t,
- std::shared_ptr<RequestGroup> > RequestGroupList;
-typedef IndexedList<a2_gid_t,
- std::shared_ptr<DownloadResult> > DownloadResultList;
+typedef IndexedList<a2_gid_t, std::shared_ptr<RequestGroup>> RequestGroupList;
+typedef IndexedList<a2_gid_t, std::shared_ptr<DownloadResult>>
+ DownloadResultList;
class RequestGroupMan {
private:
@@ -73,7 +72,13 @@ private:
RequestGroupList reservedGroups_;
DownloadResultList downloadResults_;
- int maxSimultaneousDownloads_;
+ int maxConcurrentDownloads_;
+
+ bool optimizeConcurrentDownloads_;
+ double optimizeConcurrentDownloadsCoeffA_;
+ double optimizeConcurrentDownloadsCoeffB_;
+ int optimizationSpeed_;
+ Timer optimizationSpeedTimer_;
// The number of simultaneous active downloads, excluding seed only
// item if PREF_BT_DETACH_SEED_ONLY is true. We rely on this
@@ -121,25 +126,26 @@ private:
// SHA1 hash value of the content of last session serialization.
std::string lastSessionHash_;
- void formatDownloadResultFull
- (OutputFile& out,
- const char* status,
- const std::shared_ptr<DownloadResult>& downloadResult) const;
+ void formatDownloadResultFull(
+ OutputFile& out, const char* status,
+ const std::shared_ptr<DownloadResult>& downloadResult) const;
- std::string formatDownloadResult
- (const char* status,
- const std::shared_ptr<DownloadResult>& downloadResult) const;
+ std::string formatDownloadResult(
+ const char* status,
+ const std::shared_ptr<DownloadResult>& downloadResult) const;
- void configureRequestGroup
- (const std::shared_ptr<RequestGroup>& requestGroup) const;
+ void configureRequestGroup(
+ const std::shared_ptr<RequestGroup>& requestGroup) const;
void addRequestGroupIndex(const std::shared_ptr<RequestGroup>& group);
- void addRequestGroupIndex
- (const std::vector<std::shared_ptr<RequestGroup> >& groups);
+ void addRequestGroupIndex(
+ const std::vector<std::shared_ptr<RequestGroup>>& groups);
+
+ int optimizeConcurrentDownloads();
+
public:
- RequestGroupMan(std::vector<std::shared_ptr<RequestGroup> > requestGroups,
- int maxSimultaneousDownloads,
- const Option* option);
+ RequestGroupMan(std::vector<std::shared_ptr<RequestGroup>> requestGroups,
+ int maxConcurrentDownloads, const Option* option);
~RequestGroupMan();
@@ -162,26 +168,23 @@ public:
// testing purpose.
void addRequestGroup(const std::shared_ptr<RequestGroup>& group);
- void addReservedGroup(const std::vector<std::shared_ptr<RequestGroup> >& groups);
+ void
+ addReservedGroup(const std::vector<std::shared_ptr<RequestGroup>>& groups);
void addReservedGroup(const std::shared_ptr<RequestGroup>& group);
- void insertReservedGroup
- (size_t pos, const std::vector<std::shared_ptr<RequestGroup> >& groups);
+ void
+ insertReservedGroup(size_t pos,
+ const std::vector<std::shared_ptr<RequestGroup>>& groups);
- void insertReservedGroup(size_t pos, const std::shared_ptr<RequestGroup>& group);
+ void insertReservedGroup(size_t pos,
+ const std::shared_ptr<RequestGroup>& group);
size_t countRequestGroup() const;
- const RequestGroupList& getRequestGroups() const
- {
- return requestGroups_;
- }
+ const RequestGroupList& getRequestGroups() const { return requestGroups_; }
- const RequestGroupList& getReservedGroups() const
- {
- return reservedGroups_;
- }
+ const RequestGroupList& getReservedGroups() const { return reservedGroups_; }
// Returns RequestGroup object whose gid is gid. This method returns
// RequestGroup either in requestGroups_ or reservedGroups_.
@@ -196,11 +199,17 @@ public:
// beyond the end of the queue, it moves the download to the
// beginning or the end of the queue respectively. Returns the
// destination position.
- size_t changeReservedGroupPosition(a2_gid_t gid, int pos,
- OffsetMode how);
+ size_t changeReservedGroupPosition(a2_gid_t gid, int pos, OffsetMode how);
bool removeReservedGroup(a2_gid_t gid);
+ bool getOptimizeConcurrentDownloads() const
+ {
+ return optimizeConcurrentDownloads_;
+ }
+
+ bool setupOptimizeConcurrentDownloads();
+
void showDownloadResults(OutputFile& o, bool full) const;
bool isSameFileBeingDownloaded(RequestGroup* requestGroup) const;
@@ -213,31 +222,25 @@ public:
int inProgress_;
int waiting_;
error_code::Value lastErrorResult_;
+
public:
- DownloadStat(int error,
- int inProgress,
- int waiting,
- error_code::Value lastErrorResult =
- error_code::FINISHED):
- error_(error),
- inProgress_(inProgress),
- waiting_(waiting),
- lastErrorResult_(lastErrorResult) {}
-
- error_code::Value getLastErrorResult() const
+ DownloadStat(int error, int inProgress, int waiting,
+ error_code::Value lastErrorResult = error_code::FINISHED)
+ : error_(error),
+ inProgress_(inProgress),
+ waiting_(waiting),
+ lastErrorResult_(lastErrorResult)
{
- return lastErrorResult_;
}
+ error_code::Value getLastErrorResult() const { return lastErrorResult_; }
+
bool allCompleted() const
{
return error_ == 0 && inProgress_ == 0 && waiting_ == 0;
}
- int getInProgress() const
- {
- return inProgress_;
- }
+ int getInProgress() const { return inProgress_; }
};
DownloadStat getDownloadStat() const;
@@ -259,10 +262,11 @@ public:
void addDownloadResult(const std::shared_ptr<DownloadResult>& downloadResult);
std::shared_ptr<ServerStat> findServerStat(const std::string& hostname,
- const std::string& protocol) const;
+ const std::string& protocol) const;
- std::shared_ptr<ServerStat> getOrCreateServerStat(const std::string& hostname,
- const std::string& protocol);
+ std::shared_ptr<ServerStat>
+ getOrCreateServerStat(const std::string& hostname,
+ const std::string& protocol);
bool addServerStat(const std::shared_ptr<ServerStat>& serverStat);
@@ -302,82 +306,49 @@ public:
return maxOverallUploadSpeedLimit_;
}
- void setMaxSimultaneousDownloads(int max)
- {
- maxSimultaneousDownloads_ = max;
- }
+ void setMaxConcurrentDownloads(int max) { maxConcurrentDownloads_ = 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 requestQueueCheck() { queueCheck_ = true; }
- void clearQueueCheck()
- {
- queueCheck_ = false;
- }
+ void clearQueueCheck() { queueCheck_ = false; }
- bool queueCheckRequested() const
- {
- return queueCheck_;
- }
+ bool queueCheckRequested() const { return queueCheck_; }
// Returns currently used hosts and its use count.
- void getUsedHosts(std::vector<std::pair<size_t, std::string> >& usedHosts);
+ void getUsedHosts(std::vector<std::pair<size_t, std::string>>& usedHosts);
const std::shared_ptr<ServerStatMan>& getServerStatMan() const
{
return serverStatMan_;
}
- void setMaxDownloadResult(size_t v)
- {
- maxDownloadResult_ = v;
- }
+ void setMaxDownloadResult(size_t v) { maxDownloadResult_ = v; }
void setUriListParser(const std::shared_ptr<UriListParser>& uriListParser);
- NetStat& getNetStat()
- {
- return netStat_;
- }
+ NetStat& getNetStat() { return netStat_; }
- WrDiskCache* getWrDiskCache() const
- {
- return wrDiskCache_.get();
- }
+ WrDiskCache* getWrDiskCache() const { return wrDiskCache_.get(); }
// Initializes WrDiskCache according to PREF_DISK_CACHE option. If
// its value is 0, cache storage will not be initialized.
void initWrDiskCache();
- void setKeepRunning(bool flag)
- {
- keepRunning_ = flag;
- }
+ void setKeepRunning(bool flag) { keepRunning_ = flag; }
- bool getKeepRunning() const
- {
- return keepRunning_;
- }
+ bool getKeepRunning() const { return keepRunning_; }
- size_t getNumStoppedTotal() const
- {
- return numStoppedTotal_;
- }
+ size_t getNumStoppedTotal() const { return numStoppedTotal_; }
void setLastSessionHash(std::string lastSessionHash)
{
lastSessionHash_ = std::move(lastSessionHash);
}
- const std::string& getLastSessionHash() const
- {
- return lastSessionHash_;
- }
+ const std::string& getLastSessionHash() const { return lastSessionHash_; }
const std::shared_ptr<OpenedFileCounter>& getOpenedFileCounter() const
{