Add (local) statistics to check accuracy of predicted circuit mechanism
Tor clients build "preconstructed" circuits in anticipation of user requests, so that when the client request arrives, the circuit is ready for use, and Tor can handle the client request with less latency.
In recent work, we've started preconstructing circuits for onion service usage; and we've refactored that a bit for changing ideas of onion service paths (#23101 (moved)). We've also caused and fixed a difficult-to-notice bug here in #18859 (moved), that lingered around for quite a while.
That last bug suggests that we don't have enough analysis to determine whether this feature is working well. There are two possible errors we could be making:
- We could be preconstrucing circuits that are never used, thereby wasting resources.
- We could be failing to preconstruct circuits that we will obviously need, thereby causing needless latency.
We should add a mechanism for a client to keep track of how many preconstructed circuits it has made, and how many it has thrown away unused. Additionally, we should track the hit/miss rate of looking up a preconstructed circuit when we need one.