From 649f95c9321799dba0471ac642f37a275e5f6a84 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 12 May 2009 18:05:04 +0000 Subject: [PATCH] added session_settings presets for low memory usage and seed box environments --- docs/manual.rst | 45 +++++++++++++++-- include/libtorrent/session.hpp | 3 ++ src/session.cpp | 91 ++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 5 deletions(-) diff --git a/docs/manual.rst b/docs/manual.rst index b7746a560..a7612f9a0 100644 --- a/docs/manual.rst +++ b/docs/manual.rst @@ -3281,13 +3281,48 @@ reset to 0 on reconnect. ``progress`` is the progress of the peer. -session_settings -================ +session customization +===================== -You have some control over tracker requests through the ``session_settings`` object. You +You have some control over session configuration through the ``session_settings`` object. You create it and fill it with your settings and then use ``session::set_settings()`` -to apply them. You have control over proxy and authorization settings and also the user-agent -that will be sent to the tracker. The user-agent is a good way to identify your client. +to apply them. + +You have control over proxy and authorization settings and also the user-agent +that will be sent to the tracker. The user-agent will also be used to identify the +client with other peers. + +presets +------- + +The default values of the session settings are set for a regular bittorrent client running +on a desktop system. There are functions that can set the session settings to pre set +settings for other environments. These can be used for the basis, and should be tweaked to +fit your needs better. + +:: + + session_settings min_memory_usage(); + session_settings high_performance_seed(); + +``min_memory_usage`` returns settings that will use the minimal amount of RAM, at the +potential expense of upload and download performance. It adjusts the socket buffer sizes, +disables the disk cache, lowers the send buffer watermarks so that each connection only has +at most one block in use at any one time. It lowers the outstanding blocks send to the disk +I/O thread so that connections only have one block waiting to be flushed to disk at any given +time. It lowers the max number of peers in the peer list for torrents. It performs multiple +smaller reads when it hashes pieces, instead of reading it all into memory before hashing. + +This configuration is inteded to be the starting point for embedded devices. It will +significantly reduce memory usage. + +``high_performance_seed`` returns settings optimized for a seed box, serving many peers +and that doesn't do any downloading. It has a 128 MB disk cache and has a limit of 400 files +in its file pool. It support fast upload rates by allowing large send buffers. + + +session_settings +---------------- :: diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index 47d5afdbd..151dc7aab 100644 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -118,6 +118,9 @@ namespace libtorrent namespace fs = boost::filesystem; + session_settings min_memory_usage(); + session_settings high_performance_seed(); + namespace aux { // workaround for microsofts diff --git a/src/session.cpp b/src/session.cpp index 43de651cd..030eab15b 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -110,6 +110,97 @@ namespace libtorrent } } + // this function returns a session_settings object + // which will optimize libtorrent for minimum memory + // usage, with no consideration of performance. + session_settings min_memory_usage() + { + session_settings set; + // setting this to a low limit, means more + // peers are more likely to request from the + // same piece. Which means fewer partial + // pieces and fewer entries in the partial + // piece list + set.whole_pieces_threshold = 2; + set.use_parole_mode = false; + set.prioritize_partial_pieces = true; + + // only have 4 files open at a time + set.file_pool_size = 4; + + // we want to keep the peer list as small as possible + set.allow_multiple_connections_per_ip = false; + set.max_failcount = 2; + set.inactivity_timeout = 120; + + // whenever a peer has downloaded one block, write + // it to disk, and don't read anything from the + // socket until the disk write is complete + set.max_outstanding_disk_bytes_per_connection = 0; + + // don't keep track of all upnp devices, keep + // the device list small + set.upnp_ignore_nonrouters = true; + + // never keep more than one 16kB block in + // the send buffer + set.send_buffer_watermark = 9; + + // don't use any disk cache + set.cache_size = 0; + set.use_read_cache = false; + + set.close_redundant_connections = true; + + set.max_peerlist_size = 500; + + // udp trackers are cheaper to talk to + set.prefer_udp_trackers = true; + + set.max_rejects = 10; + + set.recv_socket_buffer_size = 16 * 1024; + set.send_socket_buffer_size = 16 * 1024; + + // use less memory when checking pieces + set.optimize_hashing_for_speed = false; + + // use less memory when reading and writing + // whole pieces + set.coalesce_reads = false; + set.coalesce_writes = false; + + return set; + } + + session_settings high_performance_seed() + { + session_settings set; + + // only have 4 files open at a time + set.file_pool_size = 400; + + // as a seed box, we must accept multiple peers behind + // the same NAT + set.allow_multiple_connections_per_ip = true; + + // support high upload rates + set.send_buffer_watermark = 64 * 1024; + + // use 128 MB of cache + set.cache_size = 8192; + set.use_read_cache = true; + + set.close_redundant_connections = true; + + set.max_rejects = 10; + + // use less memory when checking pieces + set.optimize_hashing_for_speed = true; + + return set; + } + session::session( fingerprint const& id , std::pair listen_port_range