151-path-selection-improvements.txt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. Filename: 151-path-selection-improvements.txt
  2. Title: Improving Tor Path Selection
  3. Author: Fallon Chen, Mike Perry
  4. Created: 5-Jul-2008
  5. Status: Implemented
  6. Overview
  7. The performance of paths selected can be improved by adjusting the
  8. CircuitBuildTimeout and avoiding failing guard nodes. This proposal
  9. describes a method of tracking buildtime statistics at the client, and
  10. using those statistics to adjust the CircuitBuildTimeout.
  11. Motivation
  12. Tor's performance can be improved by excluding those circuits that
  13. have long buildtimes (and by extension, high latency). For those Tor
  14. users who require better performance and have lower requirements for
  15. anonymity, this would be a very useful option to have.
  16. Implementation
  17. Storing Build Times
  18. Circuit build times are stored in the circular array
  19. 'circuit_build_times' consisting of uint32_t elements as milliseconds.
  20. The total size of this array is based on the number of circuits
  21. it takes to converge on a good fit of the long term distribution of
  22. the circuit builds for a fixed link. We do not want this value to be
  23. too large, because it will make it difficult for clients to adapt to
  24. moving between different links.
  25. From our observations, this value appears to be on the order of 1000,
  26. but is configurable in a #define NCIRCUITS_TO_OBSERVE.
  27. Long Term Storage
  28. The long-term storage representation is implemented by storing a
  29. histogram with BUILDTIME_BIN_WIDTH millisecond buckets (default 50) when
  30. writing out the statistics to disk. The format this takes in the
  31. state file is 'CircuitBuildTime <bin-ms> <count>', with the total
  32. specified as 'TotalBuildTimes <total>'
  33. Example:
  34. TotalBuildTimes 100
  35. CircuitBuildTimeBin 0 50
  36. CircuitBuildTimeBin 50 25
  37. CircuitBuildTimeBin 100 13
  38. ...
  39. Reading the histogram in will entail inserting <count> values
  40. into the circuit_build_times array each with the value of
  41. <bin-ms> milliseconds. In order to evenly distribute the values
  42. in the circular array, the Fisher-Yates shuffle will be performed
  43. after reading values from the bins.
  44. Learning the CircuitBuildTimeout
  45. Based on studies of build times, we found that the distribution of
  46. circuit buildtimes appears to be a Pareto distribution.
  47. We will calculate the parameters for a Pareto distribution
  48. fitting the data using the estimators at
  49. http://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation.
  50. The timeout itself is calculated by using the Quartile function (the
  51. inverted CDF) to give us the value on the CDF such that
  52. BUILDTIME_PERCENT_CUTOFF (80%) of the mass of the distribution is
  53. below the timeout value.
  54. Thus, we expect that the Tor client will accept the fastest 80% of
  55. the total number of paths on the network.
  56. Detecting Changing Network Conditions
  57. We attempt to detect both network connectivty loss and drastic
  58. changes in the timeout characteristics. Network connectivity loss
  59. is detected by recording a timestamp every time Tor either completes
  60. a TLS connection or receives a cell. If this timestamp is more than
  61. 90 seconds in the past, circuit timeouts are no longer counted.
  62. If more than MAX_RECENT_TIMEOUT_RATE (80%) of the past
  63. RECENT_CIRCUITS (20) time out, we assume the network connection
  64. has changed, and we discard all buildtimes history and compute
  65. a new timeout by estimating a new Pareto curve using the
  66. position on the Pareto Quartile function for the ratio of
  67. timeouts.
  68. Testing
  69. After circuit build times, storage, and learning are implemented,
  70. the resulting histogram should be checked for consistency by
  71. verifying it persists across successive Tor invocations where
  72. no circuits are built. In addition, we can also use the existing
  73. buildtime scripts to record build times, and verify that the histogram
  74. the python produces matches that which is output to the state file in Tor,
  75. and verify that the Pareto parameters and cutoff points also match.
  76. Soft timeout vs Hard Timeout
  77. At some point, it may be desirable to change the cutoff from a
  78. single hard cutoff that destroys the circuit to a soft cutoff and
  79. a hard cutoff, where the soft cutoff merely triggers the building
  80. of a new circuit, and the hard cutoff triggers destruction of the
  81. circuit.
  82. Good values for hard and soft cutoffs seem to be 80% and 60%
  83. respectively, but we should eventually justify this with observation.
  84. When to Begin Calculation
  85. The number of circuits to observe (NCIRCUITS_TO_CUTOFF) before
  86. changing the CircuitBuildTimeout will be tunable via a #define. From
  87. our measurements, a good value for NCIRCUITS_TO_CUTOFF appears to be
  88. on the order of 100.
  89. Dealing with Timeouts
  90. Timeouts should be counted as the expectation of the region of
  91. of the Pareto distribution beyond the cutoff. The proposal will
  92. be updated with this value soon.
  93. Also, in the event of network failure, the observation mechanism
  94. should stop collecting timeout data.
  95. Client Hints
  96. Some research still needs to be done to provide initial values
  97. for CircuitBuildTimeout based on values learned from modem
  98. users, DSL users, Cable Modem users, and dedicated links. A
  99. radiobutton in Vidalia should eventually be provided that
  100. sets CircuitBuildTimeout to one of these values and also
  101. provide the option of purging all learned data, should any exist.
  102. These values can either be published in the directory, or
  103. shipped hardcoded for a particular Tor version.
  104. Issues
  105. Impact on anonymity
  106. Since this follows a Pareto distribution, large reductions on the
  107. timeout can be achieved without cutting off a great number of the
  108. total paths. This will eliminate a great deal of the performance
  109. variation of Tor usage.