diff --git a/Options.cpp b/Options.cpp index 71f36203..4c603acd 100644 --- a/Options.cpp +++ b/Options.cpp @@ -152,7 +152,6 @@ static const char* OPTION_CURSESNZBNAME = "CursesNzbName"; static const char* OPTION_CURSESTIME = "CursesTime"; static const char* OPTION_CURSESGROUP = "CursesGroup"; static const char* OPTION_CRCCHECK = "CrcCheck"; -static const char* OPTION_THREADLIMIT = "ThreadLimit"; static const char* OPTION_DIRECTWRITE = "DirectWrite"; static const char* OPTION_WRITEBUFFERSIZE = "WriteBufferSize"; static const char* OPTION_NZBDIRINTERVAL = "NzbDirInterval"; @@ -185,6 +184,7 @@ static const char* OPTION_RETRYONCRCERROR = "RetryOnCrcError"; static const char* OPTION_ALLOWREPROCESS = "AllowReProcess"; static const char* OPTION_POSTPROCESS = "PostProcess"; static const char* OPTION_LOADPARS = "LoadPars"; +static const char* OPTION_THREADLIMIT = "ThreadLimit"; const char* BoolNames[] = { "yes", "no", "true", "false", "1", "0", "on", "off", "enable", "disable", "enabled", "disabled" }; const int BoolValues[] = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; @@ -516,7 +516,6 @@ Options::Options(int argc, char* argv[]) m_bCursesGroup = false; m_bCrcCheck = false; m_bDirectWrite = false; - m_iThreadLimit = 0; m_iWriteBufferSize = 0; m_iNzbDirInterval = 0; m_iNzbDirFileAge = 0; @@ -863,7 +862,6 @@ void Options::InitDefault() SetOption(OPTION_CURSESTIME, "no"); SetOption(OPTION_CURSESGROUP, "no"); SetOption(OPTION_CRCCHECK, "yes"); - SetOption(OPTION_THREADLIMIT, "100"); SetOption(OPTION_DIRECTWRITE, "yes"); SetOption(OPTION_WRITEBUFFERSIZE, "0"); SetOption(OPTION_NZBDIRINTERVAL, "5"); @@ -1037,7 +1035,6 @@ void Options::InitOptions() m_iLogBufferSize = ParseIntValue(OPTION_LOGBUFFERSIZE, 10); m_iUMask = ParseIntValue(OPTION_UMASK, 8); m_iUpdateInterval = ParseIntValue(OPTION_UPDATEINTERVAL, 10); - m_iThreadLimit = ParseIntValue(OPTION_THREADLIMIT, 10); m_iWriteBufferSize = ParseIntValue(OPTION_WRITEBUFFERSIZE, 10); m_iNzbDirInterval = ParseIntValue(OPTION_NZBDIRINTERVAL, 10); m_iNzbDirFileAge = ParseIntValue(OPTION_NZBDIRFILEAGE, 10); @@ -2494,7 +2491,8 @@ bool Options::ValidateOptionName(const char * optname) } if (!strcasecmp(optname, OPTION_RETRYONCRCERROR) || !strcasecmp(optname, OPTION_ALLOWREPROCESS) || - !strcasecmp(optname, OPTION_LOADPARS)) + !strcasecmp(optname, OPTION_LOADPARS) || + !strcasecmp(optname, OPTION_THREADLIMIT)) { ConfigWarn("Option \"%s\" is obsolete, ignored", optname); return true; diff --git a/Options.h b/Options.h index 74417e20..0acddc39 100644 --- a/Options.h +++ b/Options.h @@ -286,7 +286,6 @@ private: bool m_bCursesTime; bool m_bCursesGroup; bool m_bCrcCheck; - int m_iThreadLimit; bool m_bDirectWrite; int m_iWriteBufferSize; int m_iNzbDirInterval; @@ -447,7 +446,6 @@ public: bool GetCursesTime() { return m_bCursesTime; } bool GetCursesGroup() { return m_bCursesGroup; } bool GetCrcCheck() { return m_bCrcCheck; } - int GetThreadLimit() { return m_iThreadLimit; } bool GetDirectWrite() { return m_bDirectWrite; } int GetWriteBufferSize() { return m_iWriteBufferSize; } int GetNzbDirInterval() { return m_iNzbDirInterval; } diff --git a/QueueCoordinator.cpp b/QueueCoordinator.cpp index 8dae81a8..2c16fa58 100644 --- a/QueueCoordinator.cpp +++ b/QueueCoordinator.cpp @@ -117,6 +117,17 @@ void QueueCoordinator::Run() m_mutexDownloadQueue.Unlock(); + // compute maximum number of allowed download threads + m_iDownloadsLimit = 2; // two extra threads for completing files (when connections are not needed) + for (ServerPool::Servers::iterator it = g_pServerPool->GetServers()->begin(); it != g_pServerPool->GetServers()->end(); it++) + { + NewsServer* pNewsServer = *it; + if (pNewsServer->GetLevel() == 0) + { + m_iDownloadsLimit += pNewsServer->GetMaxConnections(); + } + } + m_tStartServer = time(NULL); m_tLastCheck = m_tStartServer; bool bWasStandBy = true; @@ -139,7 +150,7 @@ void QueueCoordinator::Run() bool bHasMoreArticles = GetNextArticle(pFileInfo, pArticleInfo); bArticeDownloadsRunning = !m_ActiveDownloads.empty(); m_bHasMoreJobs = bHasMoreArticles || bArticeDownloadsRunning; - if (bHasMoreArticles && !IsStopped() && Thread::GetThreadCount() < g_pOptions->GetThreadLimit()) + if (bHasMoreArticles && !IsStopped() && (int)m_ActiveDownloads.size() < m_iDownloadsLimit) { StartArticleDownload(pFileInfo, pArticleInfo, pConnection); bArticeDownloadsRunning = true; diff --git a/QueueCoordinator.h b/QueueCoordinator.h index 2302f229..70020f55 100644 --- a/QueueCoordinator.h +++ b/QueueCoordinator.h @@ -63,6 +63,7 @@ private: QueueEditor m_QueueEditor; Mutex m_mutexDownloadQueue; bool m_bHasMoreJobs; + int m_iDownloadsLimit; // statistics static const int SPEEDMETER_SLOTS = 30; diff --git a/UrlCoordinator.cpp b/UrlCoordinator.cpp index 0263cb88..407ebe62 100644 --- a/UrlCoordinator.cpp +++ b/UrlCoordinator.cpp @@ -142,7 +142,7 @@ void UrlCoordinator::Run() bool bHasMoreUrls = GetNextUrl(pDownloadQueue, pUrlInfo); bool bUrlDownloadsRunning = !m_ActiveDownloads.empty(); m_bHasMoreJobs = bHasMoreUrls || bUrlDownloadsRunning; - if (bHasMoreUrls && !IsStopped() && Thread::GetThreadCount() < g_pOptions->GetThreadLimit()) + if (bHasMoreUrls && !IsStopped()) { StartUrlDownload(pUrlInfo); } diff --git a/nzbget.conf b/nzbget.conf index ff990b54..e56b767d 100644 --- a/nzbget.conf +++ b/nzbget.conf @@ -175,7 +175,7 @@ Server1.Encryption=no # select cipher for TLS" if the cipher string is not valid. Server1.Cipher= -# Maximal number of simultaneous connections to this server (0-999). +# Maximum number of simultaneous connections to this server (0-999). Server1.Connections=4 # Second server, on level 0. @@ -550,29 +550,6 @@ ConnectionTimeout=60 # Do not use small values! TerminateTimeout=600 -# Set the (approximate) maximum number of allowed threads (10-999). -# -# Sometimes under certain circumstances the program may create way to many -# download threads. Most of them are in wait-state. That is not bad, -# but threads are usually a limited resource. If a program creates to many -# of them, operating system may kill it. The option prevents that. -# -# NOTE: The number of threads is not the same as the number of connections -# opened to NNTP-servers. Do not use the option to limit the -# number of connections. Use the appropriate options -# instead. -# -# NOTE: The actual number of created threads can be slightly larger as -# defined by the option. Important threads may be created even if the -# number of threads is exceeded. The option prevents only the creation of -# additional download threads. -# -# NOTE: In most cases you should leave the default value "100" unchanged. -# However you may increase that value if you need more than 90 connections -# (that's very unlikely) or decrease the value if the OS does not allow so -# many threads. But the most OSes should not have problems with 100 threads. -ThreadLimit=100 - # Set the maximum download rate on program start (kilobytes/sec). # # Value "0" means no speed control. @@ -651,7 +628,7 @@ DeleteCleanupDisk=no # that can be achieved with the option . KeepHistory=7 -# Maximal number of simultaneous connections for nzb URL downloads (0-999). +# Maximum number of simultaneous connections for nzb URL downloads (0-999). # # When NZB-files are added to queue via URL, the program downloads them # from the specified URL. The option limits the maximal number of connections