Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 1 | --- |
| 2 | layout: documentation |
Greg Estren | c081675 | 2020-02-20 13:04:29 -0800 | [diff] [blame] | 3 | title: Debugging remote cache hits for local execution |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 4 | --- |
| 5 | |
Googler | a85685a | 2021-01-08 16:53:49 -0800 | [diff] [blame] | 6 | # Debugging Remote Cache Hits for Local Execution |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 7 | |
| 8 | This page describes how to investigate cache misses in the context of local |
| 9 | execution. |
| 10 | |
| 11 | This page assumes that you have a build and/or test that successfully builds |
| 12 | locally and is set up to utilize remote caching, and that you want to ensure |
| 13 | that the remote cache is being effectively utilized. |
| 14 | |
Googler | f86ad69 | 2021-03-08 11:18:47 -0800 | [diff] [blame] | 15 | For tips on how to check your cache hit rate and how to compare the execution logs between two Bazel invocations, see [Debugging Remote Cache Hits for Remote Execution](/remote-execution-caching-debug.html). Everything presented in that guide also applies to remote caching with local execution. However, local execution presents some additional challenges. |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 16 | |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 17 | ## Checking your cache hit rate |
| 18 | |
| 19 | Successful remote cache hits will show up in the status line, similarly to |
| 20 | [Cache Hits rate with Remote |
Attila Olh | 4279f84 | 2021-02-22 06:13:09 -0800 | [diff] [blame] | 21 | Execution](/remote-execution-caching-debug.html#checking-your-cache-hit-rate). |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 22 | In the standard output of your Bazel run, you will see something like the |
| 23 | following: |
| 24 | |
| 25 | INFO: 7 processes: 3 remote cache hit, 4 linux-sandbox. |
| 26 | |
| 27 | This means that out of 7 attempted actions, 3 got a remote cache hit and 4 |
| 28 | actions did not have cache hits and were executed locally using `linux-sandbox` |
| 29 | strategy. Local cache hits are not included in this summary. If you are getting |
| 30 | 0 processes (or a number lower than expected), run `bazel clean` followed by |
| 31 | your build/test command. |
| 32 | |
| 33 | ## Troubleshooting cache hits |
| 34 | |
| 35 | If you are not getting the cache hit rate you are expecting, do the following: |
| 36 | |
| 37 | ### Ensure successful communication with the remote endpoint |
| 38 | |
| 39 | To ensure your build is successfully communicating with the remote cache, follow |
| 40 | the steps in this section. |
| 41 | |
| 42 | 1. Check your output for warnings |
| 43 | |
| 44 | With remote execution, a failure to talk to the remote endpoint would fail |
| 45 | your build. On the other hand, a cacheable local build would not fail if it |
| 46 | cannot cache. Check the output of your Bazel invocation for warnings, such |
| 47 | as: |
| 48 | |
| 49 | WARNING: Error reading from the remote cache: |
| 50 | |
| 51 | or |
| 52 | |
| 53 | WARNING: Error writing to the remote cache: |
| 54 | |
| 55 | Such warnings will be followed by the error message detailing the connection |
| 56 | problem that should help you debug: for example, mistyped endpoint name or |
Rai | dd38d22 | 2021-07-28 07:13:29 -0700 | [diff] [blame^] | 57 | incorrectly set credentials. Find and address any such errors. If the error |
| 58 | message you see does not give you enough information, try adding |
| 59 | `--verbose_failures`. |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 60 | |
| 61 | 2. Follow the steps from [Troubleshooting cache hits for remote |
| 62 | execution](/remote-execution-caching-debug.html#troubleshooting-cache-hits) to |
| 63 | ensure that your cache-writing Bazel invocations are able to get cache hits |
| 64 | on the same machine and across machines. |
| 65 | |
| 66 | 3. Ensure your cache-reading Bazel invocations can get cache hits. |
| 67 | |
| 68 | a. Since cache-reading Bazel invocations will have a different command-line set |
| 69 | up, take additional care to ensure that they are properly set up to |
ishikhman | e038a26 | 2019-04-03 07:06:58 -0700 | [diff] [blame] | 70 | communicate with the remote cache. Ensure the `--remote_cache` flag is set |
| 71 | and there are no warnings in the output. |
Googler | d96c908 | 2018-11-28 09:00:04 -0800 | [diff] [blame] | 72 | |
| 73 | b. Ensure your cache-reading Bazel invocations build the same targets as the |
| 74 | cache-writing Bazel invocations. |
| 75 | |
| 76 | c. Follow the same steps as to [ensure caching across |
| 77 | machines](/remote-execution-caching-debug.html#ensure-caching-across-machines), |
| 78 | to ensure caching from your cache-writing Bazel invocation to your |
| 79 | cache-reading Bazel invocation. |
| 80 | |