TUNING 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. Most operating systems limit an amount of TCP sockets that can be used
  2. simultaneously. It is possible for a busy Tor relay to run into these
  3. limits, thus being unable to fully utilize the bandwidth resources it
  4. has at its disposal. Following system-specific tips might be helpful
  5. to alleviate the aforementioned problem.
  6. Linux
  7. -----
  8. Use 'ulimit -n' to raise an allowed number of file descriptors to be
  9. opened on your host at the same time.
  10. FreeBSD
  11. -------
  12. Tune the followind sysctl(8) variables:
  13. * kern.maxfiles - maximum allowed file descriptors (for entire system)
  14. * kern.maxfilesperproc - maximum file descriptors one process is allowed
  15. to use
  16. * kern.ipc.maxsockets - overall maximum numbers of sockets for entire
  17. system
  18. * kern.ipc.somaxconn - size of listen queue for incoming TCP connections
  19. for entire system
  20. See also:
  21. * https://www.freebsd.org/doc/handbook/configtuning-kernel-limits.html
  22. * https://wiki.freebsd.org/NetworkPerformanceTuning
  23. Mac OS X
  24. --------
  25. Since Mac OS X is BSD-based system, most of the above hold for OS X as well.
  26. However, launchd(8) is known to modify kern.maxfiles and kern.maxfilesperproc
  27. when it launches tor service (see launchd.plist(5) manpage). Also,
  28. kern.ipc.maxsockets is determined dynamically by the system and thus is
  29. read-only on OS X.
  30. OpenBSD
  31. -------
  32. For recent versions of OpenBSD (5.5 and 5.6, and probably older releases
  33. as well), the maximum number of file descriptors that can be opened is
  34. 7030:
  35. http://unix.stackexchange.com/questions/104929/does-openbsd-have-a-limit-to-the-number-of-file-descriptors/104948#104948
  36. The maximum number of file descriptors that an OpenBSD machine can have
  37. open is stored in the sysctl variable kern.maxfiles. This value defaults
  38. to 7030 - to verify this, run sysctl kern.maxfiles.
  39. To immediately change a running system's file descriptor limit to, for
  40. example, 20,000 files, run sudo sysctl kern.maxfiles=20000. All sysctl
  41. variables are reset upon reboot using defaults and /etc/sysctl.conf, so
  42. to make your change permanent you must add the line kern.maxfiles=20000
  43. to /etc/sysctl.conf.
  44. One can also change a maximum number of allowed file descriptors for Tor
  45. daemon alone by editing /etc/rc.d/tor and adding the following lines:
  46. tor:\
  47. :openfiles-max=8192:\
  48. :tc=daemon:
  49. However, there are stricter limits set on users. This is a security
  50. feature intended to prevent one user from choking out others by opening
  51. all possible file descriptors.
  52. The stricter limits are set in /etc/login.conf. This config file sets
  53. resource access rules for user classes. You should be running
  54. Tor as a non-privileged daemon user '_tor', which belongs to the 'daemon'
  55. class. It will therefore be subject to the 'default' and 'daemon' rules.
  56. There are two relevant rules: openfiles-cur and openfiles-max. The prior
  57. is the initial limit upon login - the soft limit. The latter is the maximum
  58. limit that can be set using 'ulimit -n' or setrlimit() without editing
  59. /etc/login.conf and rebooting. This is known as the hard limit.
  60. Without editing /etc/login.conf, daemon-owned processes have
  61. soft limit of 512 open files and a hard limit of 1024 open files.
  62. Tor can increase the soft limit as needed, so you will therefore
  63. eventually get warnings about running out of available file descriptors
  64. once Tor reaches ~1024 open files.
  65. To increase the hard limit, add the following line to the daemon class
  66. rules in /etc/login.conf:
  67. tor:\
  68. :openfiles-max=8192:\
  69. :tc=daemon:
  70. Upon restarting the machine, Tor will be able to open up to 6500 file
  71. descriptors.
  72. Be aware that, by doing this, you are bypassing a security and stability
  73. feature of the OS. If you are running your relay on a weak or old system,
  74. watch your system load to ensure that it can handle this many open files.
  75. Also, Tor may interfere with any other programs that open many files.
  76. Disclaimer
  77. ----------
  78. Do note that this document is a draft and above information may be
  79. technically incorrect and/or incomplete. If so, please open a ticket
  80. on https://trac.torproject.org or post to tor-relays mailing list.
  81. Are you running a busy Tor relay? Let us know how you are solving
  82. the out-of-sockets problem on your system.