automatically caps files and connections by default to rlimit

This commit is contained in:
Arvid Norberg 2009-10-03 19:02:31 +00:00
parent 8dc2865c5d
commit 599543e889
3 changed files with 28 additions and 0 deletions

View File

@ -72,6 +72,7 @@
* improved support for sparse files on windows * improved support for sparse files on windows
* added ability to give seeding torrents preference to active slots * added ability to give seeding torrents preference to active slots
* added torrent_status::finished_time * added torrent_status::finished_time
* automatically caps files and connections by default to rlimit
release 0.14.7 release 0.14.7

View File

@ -61,6 +61,7 @@ namespace libtorrent
void release(void* st); void release(void* st);
void release(fs::path const& p); void release(fs::path const& p);
void resize(int size); void resize(int size);
int size_limit() const { return m_size; }
private: private:

View File

@ -307,6 +307,32 @@ namespace aux {
m_buffer_allocations = 0; m_buffer_allocations = 0;
#endif #endif
#if defined TORRENT_BSD || defined TORRENT_LINUX
// ---- auto-cap open files ----
struct rlimit rl;
if (getrlimit(RLIMIT_NOFILE, &rl) == 0)
{
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << "max number of open files: " << rl.rlim_cur << "\n";
#endif
// deduct some margin for epoll/kqueue, log files,
// futexes, shared objects etc.
rl.rlim_cur -= 20;
// 80% of the available file descriptors should go
m_max_connections = (std::min)(m_max_connections, int(rl.rlim_cur * 8 / 10));
// 20% goes towards regular files
m_files.resize((std::min)(m_files.size_limit(), int(rl.rlim_cur * 2 / 10)));
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
(*m_logger) << time_now_string() << " max connections: " << m_max_connections << "\n";
(*m_logger) << time_now_string() << " max files: " << m_files.size_limit() << "\n";
#endif
}
#endif // TORRENT_BSD || TORRENT_LINUX
// ---- generate a peer id ---- // ---- generate a peer id ----
static seed_random_generator seeder; static seed_random_generator seeder;