| 47 | } |
| 48 | |
| 49 | CacheOptions CacheOptions::MakeFromNetworkMetrics(int64_t time_to_first_byte_millis, |
| 50 | int64_t transfer_bandwidth_mib_per_sec, |
| 51 | double ideal_bandwidth_utilization_frac, |
| 52 | int64_t max_ideal_request_size_mib) { |
| 53 | // |
| 54 | // The I/O coalescing algorithm uses two parameters: |
| 55 | // 1. hole_size_limit (a.k.a max_io_gap): Max I/O gap/hole size in bytes |
| 56 | // 2. range_size_limit (a.k.a ideal_request_size): Ideal I/O Request size in bytes |
| 57 | // |
| 58 | // These parameters can be derived from network metrics (e.g. S3) as described below: |
| 59 | // |
| 60 | // In an S3 compatible storage, there are two main metrics: |
| 61 | // 1. Seek-time or Time-To-First-Byte (TTFB) in seconds: call setup latency of a new |
| 62 | // S3 request |
| 63 | // 2. Transfer Bandwidth (BW) for data in bytes/sec |
| 64 | // |
| 65 | // 1. Computing hole_size_limit: |
| 66 | // |
| 67 | // hole_size_limit = TTFB * BW |
| 68 | // |
| 69 | // This is also called Bandwidth-Delay-Product (BDP). |
| 70 | // Two byte ranges that have a gap can still be mapped to the same read |
| 71 | // if the gap is less than the bandwidth-delay product [TTFB * TransferBandwidth], |
| 72 | // i.e. if the Time-To-First-Byte (or call setup latency of a new S3 request) is |
| 73 | // expected to be greater than just reading and discarding the extra bytes on an |
| 74 | // existing HTTP request. |
| 75 | // |
| 76 | // 2. Computing range_size_limit: |
| 77 | // |
| 78 | // We want to have high bandwidth utilization per S3 connections, |
| 79 | // i.e. transfer large amounts of data to amortize the seek overhead. |
| 80 | // But, we also want to leverage parallelism by slicing very large IO chunks. |
| 81 | // We define two more config parameters with suggested default values to control |
| 82 | // the slice size and seek to balance the two effects with the goal of maximizing |
| 83 | // net data load performance. |
| 84 | // |
| 85 | // BW_util_frac (ideal bandwidth utilization): Transfer bandwidth utilization fraction |
| 86 | // (per connection) to maximize the net data load. 90% is a good default number for |
| 87 | // an effective transfer bandwidth. |
| 88 | // |
| 89 | // MAX_IDEAL_REQUEST_SIZE: The maximum single data request size (in MiB) to maximize |
| 90 | // the net data load. 64 MiB is a good default number for the ideal request size. |
| 91 | // |
| 92 | // The amount of data that needs to be transferred in a single S3 get_object |
| 93 | // request to achieve effective bandwidth eff_BW = BW_util_frac * BW is as follows: |
| 94 | // eff_BW = range_size_limit / (TTFB + range_size_limit / BW) |
| 95 | // |
| 96 | // Substituting TTFB = hole_size_limit / BW and eff_BW = BW_util_frac * BW, we get the |
| 97 | // following result: |
| 98 | // range_size_limit = hole_size_limit * BW_util_frac / (1 - BW_util_frac) |
| 99 | // |
| 100 | // Applying the MAX_IDEAL_REQUEST_SIZE, we get the following: |
| 101 | // range_size_limit = min(MAX_IDEAL_REQUEST_SIZE, |
| 102 | // hole_size_limit * BW_util_frac / (1 - BW_util_frac)) |
| 103 | // |
| 104 | DCHECK_GT(time_to_first_byte_millis, 0) << "TTFB must be > 0"; |
| 105 | DCHECK_GT(transfer_bandwidth_mib_per_sec, 0) << "Transfer bandwidth must be > 0"; |
| 106 | DCHECK_GT(ideal_bandwidth_utilization_frac, 0) |
nothing calls this directly
no outgoing calls
no test coverage detected