bazel icon indicating copy to clipboard operation
bazel copied to clipboard

Add bazel flag for max_cas_entry size.

Open amishra-u opened this issue 3 years ago • 13 comments

Description of the feature request:

As of today, the max_cas_entry_size is declared at the server side. In the event that Bazel sends a write request containing a digest larger than the specified max_cas_entry_size, the remote cache throws an 'out_of_range' error. By introducing a Bazel flag for max_cas_entry_size, it becomes possible to validate it on the client side, potentially eliminating the need for a round trip to the server. This improvement has the potential to enhance build performance.

What underlying problem are you trying to solve with this feature?

Improved build performance with remote cache.

amishra-u avatar May 19 '23 08:05 amishra-u

@tjgq @sgowroji @Pavank1992 could you give an estimate of how much work this is? I'd be willing to help, but need to know roughly how much work it is. Sounds like passing through an argument and putting a conditional somewhere around the upload logic, but not sure if it is that simple

diegohavenstein avatar Oct 12 '23 15:10 diegohavenstein

Before we decide to add a flag: is this something that could be negotiated with the server during the initial handshake? (We already negotiate other things, like the digest hash function used by the CAS.)

tjgq avatar Oct 12 '23 15:10 tjgq

@tjgq yes, remote-cache can send the max supported cas entry size on getcapablities call, this way we will not need to add any bazel flag (seems better option). but we may need to add new property in the repsonse. https://github.com/bazelbuild/remote-apis/blob/main/build/bazel/remote/execution/v2/remote_execution.proto#L1968

amishra-u avatar Oct 12 '23 17:10 amishra-u

In that case, could you bring this up as a potential addition to the spec by filing an issue at https://github.com/bazelbuild/remote-apis?

tjgq avatar Oct 12 '23 17:10 tjgq

Sounds like a better approach indeed

@amishra-u can you please also update the feature request here and assign it to me? (I can't edit) Thx!

diegohavenstein avatar Oct 13 '23 07:10 diegohavenstein

@diegohavenstein same here, I don't have permission to assign the task to anyone.

amishra-u avatar Oct 13 '23 17:10 amishra-u

@diegohavenstein I have assigned to you. Thanks!

coeuvre avatar Oct 16 '23 08:10 coeuvre

@coeuvre I am taking over for Diego, he left our team. Can you assign the issue to me?

axeluhlig avatar Feb 12 '25 17:02 axeluhlig

@axeluhlig are you still interested in fixing this?

meisterT avatar Aug 05 '26 13:08 meisterT

@meisterT interested yes, but I am lacking the time to finish this one. Sorry about that. The API change is merged, the required changes in the Bazel client are still missing.

Please unassign me.

axeluhlig avatar Sep 08 '26 08:09 axeluhlig

@meisterT axeluhlig stepped aside on this one last week, so I would like to pick it up if nobody else has it.

tjgq asked back in 2023 whether this could be negotiated at the handshake rather than being a flag, and that is what happened: max_cas_blob_size_bytes landed in CacheCapabilities and is already vendored in third_party/remoteapis. Nothing in the Java client reads it yet.

What I have locally: CombinedCache resolves the limit lazily from the server capabilities, with --experimental_remote_max_cas_blob_size as an override for servers that advertise nothing. Oversized blobs are skipped in uploadFileToRemote and uploadBlobToRemote, and if an output was skipped the action result is not written to the remote AC, so no dangling entry is left behind. Downloads are untouched, since the proto says a server may still serve larger blobs. Disk cache and remote execution input uploads are unaffected.

Is that the shape you want before I open a PR?

gauranshahuja avatar Sep 11 '26 19:09 gauranshahuja

What I have locally: CombinedCache resolves the limit lazily from the server capabilities, with --experimental_remote_max_cas_blob_size as an override for servers that advertise nothing. Oversized blobs are skipped in uploadFileToRemote and uploadBlobToRemote, and if an output was skipped the action result is not written to the remote AC

@gauranshahuja could you share your local changes? I'd like to help develop and review the feature.

I met a problem with large output (about 5 GiB) . it make our remote cache upload expensive. currently, the workaround is --modify_execution_info=^CppLink$=+no-remote-cache-upload. However, it disables uploads for all CppLink acitons. Actions with small outputs are affected too.

PikachuHyA avatar Oct 09 '26 11:10 PikachuHyA

@PikachuHyA sure, here it is: https://github.com/bazelbuild/bazel/compare/master...gauranshahuja:bazel:18449/remote-max-cas-entry-size

One commit, 6 files:

  • RemoteOptions: new --experimental_remote_max_cas_blob_size (same ByteSizeConverter as --experimental_disk_cache_gc_max_size, default 0).
  • CombinedCache: the effective limit is the flag if it is set, otherwise max_cas_blob_size_bytes from the server's CacheCapabilities, resolved lazily on first use like Chunking. 0 from both means no limit. uploadFileToRemote / uploadBlobToRemote skip blobs above it.
  • UploadManifest: an oversized missing output is not uploaded, and the action result then goes to the disk cache only, not the remote AC, so a later remote hit cannot reference a blob the server never received.
  • Downloads are not filtered, since the proto allows a server to serve larger blobs.
  • CombinedCacheTest: 7 tests (flag limit, server limit, no limit, flag over server, file upload still writes the disk cache, manifest withholds the remote AC, download over the limit).

For your case that would be --experimental_remote_max_cas_blob_size=1G (uppercase; the converter accepts K/M/G/T): the 5 GiB link outputs stay out of the remote cache, every smaller CppLink output is still uploaded, and the no-remote-cache-upload workaround is not needed.

Two caveats:

  1. I have not compiled it yet, so treat it as a sketch until I push a build-verified revision.
  2. One open question: uploadFileToRemote skips the check when the server supports chunked uploads, but UploadManifest checks before uploading and ignores chunking, so the two disagree. For your use case (cost, not a server limit) I think the flag should apply even with chunking, and only the server-advertised limit should exempt chunked uploads. I'll make them consistent once that is settled.

@meisterT does this direction look right to you, and what would you prefer on the chunking question? I'll open the PR once it builds and the tests pass.

gauranshahuja avatar Oct 10 '26 20:10 gauranshahuja