151-path-selection-improvements.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. Gathering 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, the minimum value for a reasonable fit appears
  26. to be on the order of 500 (MIN_CIRCUITS_TO_OBSERVE). However, to keep
  27. a good fit over the long term, we store 5000 most recent circuits in
  28. the array (NCIRCUITS_TO_OBSERVE).
  29. The Tor client will build test circuits at a rate of one per
  30. minute (BUILD_TIMES_TEST_FREQUENCY) up to the point of
  31. MIN_CIRCUITS_TO_OBSERVE. This allows a fresh Tor to have
  32. a CircuitBuildTimeout estimated within 8 hours after install,
  33. upgrade, or network change (see below).
  34. Long Term Storage
  35. The long-term storage representation is implemented by storing a
  36. histogram with BUILDTIME_BIN_WIDTH millisecond buckets (default 50) when
  37. writing out the statistics to disk. The format this takes in the
  38. state file is 'CircuitBuildTime <bin-ms> <count>', with the total
  39. specified as 'TotalBuildTimes <total>'
  40. Example:
  41. TotalBuildTimes 100
  42. CircuitBuildTimeBin 25 50
  43. CircuitBuildTimeBin 75 25
  44. CircuitBuildTimeBin 125 13
  45. ...
  46. Reading the histogram in will entail inserting <count> values
  47. into the circuit_build_times array each with the value of
  48. <bin-ms> milliseconds. In order to evenly distribute the values
  49. in the circular array, the Fisher-Yates shuffle will be performed
  50. after reading values from the bins.
  51. Learning the CircuitBuildTimeout
  52. Based on studies of build times, we found that the distribution of
  53. circuit buildtimes appears to be a Frechet distribution. However,
  54. estimators and quantile functions of the Frechet distribution are
  55. difficult to work with and slow to converge. So instead, since we
  56. are only interested in the accuracy of the tail, we approximate
  57. the tail of the distribution with a Pareto curve starting at
  58. the mode of the circuit build time sample set.
  59. We will calculate the parameters for a Pareto distribution
  60. fitting the data using the estimators at
  61. http://en.wikipedia.org/wiki/Pareto_distribution#Parameter_estimation.
  62. The timeout itself is calculated by using the Quartile function (the
  63. inverted CDF) to give us the value on the CDF such that
  64. BUILDTIME_PERCENT_CUTOFF (80%) of the mass of the distribution is
  65. below the timeout value.
  66. Thus, we expect that the Tor client will accept the fastest 80% of
  67. the total number of paths on the network.
  68. Detecting Changing Network Conditions
  69. We attempt to detect both network connectivity loss and drastic
  70. changes in the timeout characteristics.
  71. If more than MAX_RECENT_TIMEOUT_RATE (80%) of the past
  72. RECENT_CIRCUITS (20) time out, we assume the network connection
  73. has changed, and we discard all buildtimes history and compute
  74. a new timeout by estimating a new Pareto curve using the
  75. position on the Pareto Quartile function for the ratio of
  76. timeouts.
  77. Network connectivity loss is detected by recording a timestamp every
  78. time Tor either completes a TLS connection or receives a cell. If
  79. this timestamp is more than CircuitBuildTimeout*RECENT_CIRCUITS/3
  80. seconds in the past, circuit timeouts are no longer counted.
  81. Testing
  82. After circuit build times, storage, and learning are implemented,
  83. the resulting histogram should be checked for consistency by
  84. verifying it persists across successive Tor invocations where
  85. no circuits are built. In addition, we can also use the existing
  86. buildtime scripts to record build times, and verify that the histogram
  87. the python produces matches that which is output to the state file in Tor,
  88. and verify that the Pareto parameters and cutoff points also match.
  89. We will also verify that there are no unexpected large deviations from
  90. node selection, such as nodes from distant geographical locations being
  91. completely excluded.
  92. Dealing with Timeouts
  93. Timeouts should be counted as the expectation of the region of
  94. of the Pareto distribution beyond the cutoff. This is done by
  95. generating a random sample for each timeout at points on the
  96. curve beyond the current timeout cutoff.
  97. Future Work
  98. At some point, it may be desirable to change the cutoff from a
  99. single hard cutoff that destroys the circuit to a soft cutoff and
  100. a hard cutoff, where the soft cutoff merely triggers the building
  101. of a new circuit, and the hard cutoff triggers destruction of the
  102. circuit.
  103. It may also be beneficial to learn separate timeouts for each
  104. guard node, as they will have slightly different distributions.
  105. This will take longer to generate initial values though.
  106. Issues
  107. Impact on anonymity
  108. Since this follows a Pareto distribution, large reductions on the
  109. timeout can be achieved without cutting off a great number of the
  110. total paths. This will eliminate a great deal of the performance
  111. variation of Tor usage.