From cf8b14ff5746085eb6d0ed11b9f58ff351955864 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Thu, 12 Sep 2024 16:36:24 +0200 Subject: [PATCH 01/10] Added the Remote cache experiments for transforms script --- transforms-caching-experiment/README.md | 26 ++++++ .../remote-cache-experiment-transforms.sh | 85 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 transforms-caching-experiment/README.md create mode 100644 transforms-caching-experiment/remote-cache-experiment-transforms.sh diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md new file mode 100644 index 000000000..e02e96561 --- /dev/null +++ b/transforms-caching-experiment/README.md @@ -0,0 +1,26 @@ +# Remote cache experiments for transforms + +## Overview + +This script is used to test the performance of remote caching for transforms. + +It will run 3 builds: + +1. Init/seed build, that writes to remote build cache. The scan for this buld will have a tag of `remote-cache-experiment-init`. +2. Transform caching enabled - pulls from remote cache. The scan for this buld will have a tag of `baseline-transforms`. +3. Transform caching disabled - executes the transforms. The scan for this buld will have a tag of `disabled-cache-transforms`. + +You can then compare the build times to see how transforms caching affects your builds. + +## Usage + +1. Copy the script into your project directory. +2. Modify the script to specify your Develocity instance URL in the `develocityUrl` variable and set the gradle version used in the `gradleVersion` variable - minimum gradle version supported is 8.9. +3. Having the key set in the environment is expected - note that remote build cache write is requiered. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`. +4. Run the script with `./transforms-caching-experiment.sh`. It will run the gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. +5. Inspect and compare build times + +## Advanced usage - disabling specific transforms caching + +If you are sure you are only suffering negative avoidance savings because of a select list of transforms retreiving outputs from cache you can disable only caching for those. To disable specific transforms caching, you can uncomment the line 48 in the script to enable running also experiments with specific transforms caching disabled. You will also need to modify the `disabledTransforms` variable in the script to specify the transforms you want to disable - there is an example supplied in the script. This will run the last two builds again, but with the specified transforms caching disabled - the tags added in scans for those build will be `baseline-transforms-selected` and `disabled-cache-transforms-selected`. + diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh new file mode 100644 index 000000000..154695e39 --- /dev/null +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# Note: +# This is a script to run the transforms remote caching experiments. You need to update it to use your server url, gradle version (8.9+) and set up the access key with remote cache write permission (you can also export it in the terminal if you wish to share the script with teammates). When executing, you can also supply a different task to run this with, it defaults to help. It will run 3 builds: +# 1. Init/seed build, that writes to remote build cache +# 2. Transform caching enabled - pulls from remote cache +# 3. Transform caching disabled - executes the transforms +# You can then compare the build times to see how transforms caching affects your builds + +# --------- Required ----------- + +develocityUrl="https://" +gradleVersion="8.9" # at least 8.9 is required + +# Having the key set in the environment is expected - note that remote build cache write is requiered +#export DEVELOCITY_ACCESS_KEY=$develocityUrl= + +# --------- End of required ----------- + + +homeDir=build/HOME + +# Set 'task' to the first argument or 'help' if no arguments are provided +task=${1:-help} + +# Initialize empty Gradle User Home with settings to run build, including Develocity access keys +echo "Initializing Gradle User Home directory at $homeDir" +rm -rf $homeDir +mkdir -p $homeDir +mkdir -p $homeDir/caches/$gradleVersion/ +cp ~/.gradle/gradle.properties $homeDir +cp -r ~/.gradle/caches/$gradleVersion/generated-gradle-jars $homeDir/caches/$gradleVersion/ + +# Note: This is expecting that CCUD gradle plugin is applied +export GRADLE_CACHE_REMOTE_PUSH=true +export GRADLE_CACHE_REMOTE_PATH="cache/$USER-exp-non-task" +export GRADLE_CACHE_REMOTE_URL="$develocityUrl/cache/$USER-exp-non-task" # Needed if the HTTP cache connector is used + +echo "------------------------------------------------------------" +echo "Priming build with task '$task' and HOME=$homeDir" +echo "------------------------------------------------------------" +set -x +./gradlew $task -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl +set +x + +cache='transforms' +runs='transforms' +# runs='transforms transforms-selected' # Uncomment to test with selected transforms disabled + +for run in $runs +do + # Set args based on cache + if [ "$run" == 'transforms' ] + then + disabledCacheArgs='-Dorg.gradle.internal.transform-caching-disabled' + elif [ "$run" == 'transforms-selected' ] + then + # Specify the transforms to disable. Example below: + disabledTransforms='org.jetbrains.kotlin.gradle.internal.transforms.BuildToolsApiClasspathEntrySnapshotTransform,org.jetbrains.kotlin.gradle.internal.transforms.ClasspathEntrySnapshotTransform' + disabledCacheArgs="-Dorg.gradle.internal.transform-caching-disabled=$disabledTransforms" + fi + + for args in "-Dscan.tag.baseline-$run" "-Dscan.tag.disabled-cache-$run $disabledCacheArgs" + do + echo "------------------------------------------------------------" + echo "Test caches/*/$cache removal with $args" + echo "------------------------------------------------------------" + set -x + ./gradlew --stop + killall -9 java + + # git clean -dfx -e HOME -e cleanup-help.sh + echo "Removing $cache from $homeDir/caches" + rm -rf $homeDir/caches/*/$cache + rm -rf $homeDir/caches/$cache-* # Also remove the transforms for Gradle 8.7 + + # Always remove the local build cache, since we are testing connection with remote build cache + rm -rf $homeDir/caches/build-cache-1 + + ./gradlew $task -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl $args + + set +x + echo "" + done +done \ No newline at end of file From 1a95523b641a77cedf0a52d3610918200723d516 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Thu, 12 Sep 2024 16:50:50 +0200 Subject: [PATCH 02/10] Fixed shell script check --- .../remote-cache-experiment-transforms.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index 154695e39..2a02fe0da 100644 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -40,7 +40,7 @@ echo "------------------------------------------------------------" echo "Priming build with task '$task' and HOME=$homeDir" echo "------------------------------------------------------------" set -x -./gradlew $task -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl +./gradlew "$task" -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl set +x cache='transforms' @@ -77,7 +77,7 @@ do # Always remove the local build cache, since we are testing connection with remote build cache rm -rf $homeDir/caches/build-cache-1 - ./gradlew $task -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl $args + ./gradlew "$task" -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl "$args" set +x echo "" From 4fb3f96f05a5cbc190419e9a058eeb4f5c73df78 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Fri, 13 Sep 2024 10:35:07 +0200 Subject: [PATCH 03/10] Updated the script and readme --- transforms-caching-experiment/README.md | 26 +++++---- .../remote-cache-experiment-transforms.sh | 53 +++++++++---------- 2 files changed, 41 insertions(+), 38 deletions(-) mode change 100644 => 100755 transforms-caching-experiment/remote-cache-experiment-transforms.sh diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index e02e96561..53b8f8b6c 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -1,4 +1,4 @@ -# Remote cache experiments for transforms +# Artifact transform remote build cache performance experiment ## Overview @@ -6,19 +6,27 @@ This script is used to test the performance of remote caching for transforms. It will run 3 builds: -1. Init/seed build, that writes to remote build cache. The scan for this buld will have a tag of `remote-cache-experiment-init`. -2. Transform caching enabled - pulls from remote cache. The scan for this buld will have a tag of `baseline-transforms`. -3. Transform caching disabled - executes the transforms. The scan for this buld will have a tag of `disabled-cache-transforms`. +1. Init/seed build, that writes to remote build cache. The scan for this build will have a tag of `remote-cache-experiment-init`. +2. Transform caching enabled - pulls from remote cache. The scan for this build will have a tag of `baseline-transforms`. +3. Transform caching disabled - executes the transforms. The scan for this build will have a tag of `disabled-cache-transforms`. You can then compare the build times to see how transforms caching affects your builds. +## Requirements + +- A Develocity instance to publish scans to +- Access key with remote build cache write permission +- Gradle version 8.9 or higher +- The [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) is expected to be applied to the project. + ## Usage -1. Copy the script into your project directory. -2. Modify the script to specify your Develocity instance URL in the `develocityUrl` variable and set the gradle version used in the `gradleVersion` variable - minimum gradle version supported is 8.9. -3. Having the key set in the environment is expected - note that remote build cache write is requiered. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`. -4. Run the script with `./transforms-caching-experiment.sh`. It will run the gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. -5. Inspect and compare build times +1. Prepare an access key with remote build cache write permission. +2. Copy the script into your project directory. +3. (Optional) If you're using a HTTP cache connector, uncomment line 31 and set the remote cache URL in the script to use a cache shard instead of the default cache. +4. Having the key set in the environment is expected - note that remote build cache write is requiered. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`, either in the script, or in the terminal before running the script. +5. Run the script with `./transforms-caching-experiment.sh`. It will run the gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. +6. Inspect and compare build times ## Advanced usage - disabling specific transforms caching diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh old mode 100644 new mode 100755 index 2a02fe0da..fdb04f265 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -1,29 +1,27 @@ #!/bin/bash -# Note: -# This is a script to run the transforms remote caching experiments. You need to update it to use your server url, gradle version (8.9+) and set up the access key with remote cache write permission (you can also export it in the terminal if you wish to share the script with teammates). When executing, you can also supply a different task to run this with, it defaults to help. It will run 3 builds: -# 1. Init/seed build, that writes to remote build cache -# 2. Transform caching enabled - pulls from remote cache -# 3. Transform caching disabled - executes the transforms -# You can then compare the build times to see how transforms caching affects your builds - -# --------- Required ----------- - -develocityUrl="https://" -gradleVersion="8.9" # at least 8.9 is required - -# Having the key set in the environment is expected - note that remote build cache write is requiered +# REQUIRED: Having the key set in the environment is expected - note that remote build cache write is requiered. It can be set here or exported in the terminal before running the script. #export DEVELOCITY_ACCESS_KEY=$develocityUrl= -# --------- End of required ----------- +gradleVersion=$(./gradlew --version | grep "Gradle" | awk '{print $2}') +major=$(echo $gradleVersion | cut -d. -f1) +minor=$(echo $gradleVersion | cut -d. -f2) + +# Check if the version is lower than 8.9 +if [ $major -lt 8 ] || ([ $major -eq 8 ] && [ $minor -lt 9 ]); then + echo "Gradle version $gradleVersion is lower than 8.9" + exit 1 +else + echo "Gradle version detected: $gradleVersion" +fi homeDir=build/HOME # Set 'task' to the first argument or 'help' if no arguments are provided -task=${1:-help} +tasks=${*:-help} -# Initialize empty Gradle User Home with settings to run build, including Develocity access keys +# Initialize empty Gradle User Home with settings to run build echo "Initializing Gradle User Home directory at $homeDir" rm -rf $homeDir mkdir -p $homeDir @@ -34,16 +32,16 @@ cp -r ~/.gradle/caches/$gradleVersion/generated-gradle-jars $homeDir/caches/$gra # Note: This is expecting that CCUD gradle plugin is applied export GRADLE_CACHE_REMOTE_PUSH=true export GRADLE_CACHE_REMOTE_PATH="cache/$USER-exp-non-task" -export GRADLE_CACHE_REMOTE_URL="$develocityUrl/cache/$USER-exp-non-task" # Needed if the HTTP cache connector is used +#export GRADLE_CACHE_REMOTE_URL="/cache/$USER-exp-non-task" # Needed if the HTTP cache connector is used echo "------------------------------------------------------------" -echo "Priming build with task '$task' and HOME=$homeDir" +echo "Priming build with task '$tasks' and HOME=$homeDir" echo "------------------------------------------------------------" set -x -./gradlew "$task" -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl +# shellcheck disable=SC2086 +./gradlew $tasks -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false set +x -cache='transforms' runs='transforms' # runs='transforms transforms-selected' # Uncomment to test with selected transforms disabled @@ -63,21 +61,18 @@ do for args in "-Dscan.tag.baseline-$run" "-Dscan.tag.disabled-cache-$run $disabledCacheArgs" do echo "------------------------------------------------------------" - echo "Test caches/*/$cache removal with $args" + echo "Test caches/*/transforms removal with $args" echo "------------------------------------------------------------" set -x ./gradlew --stop killall -9 java - # git clean -dfx -e HOME -e cleanup-help.sh - echo "Removing $cache from $homeDir/caches" - rm -rf $homeDir/caches/*/$cache - rm -rf $homeDir/caches/$cache-* # Also remove the transforms for Gradle 8.7 - - # Always remove the local build cache, since we are testing connection with remote build cache - rm -rf $homeDir/caches/build-cache-1 + echo "Removing transforms from $homeDir/caches" + rm -rf $homeDir/caches/*/transforms + rm -rf $homeDir/caches/transforms-* # Also remove the transforms for Gradle 8.7 - ./gradlew "$task" -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Ddevelocity.url=$develocityUrl "$args" + # shellcheck disable=SC2086 + ./gradlew $tasks -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false $args set +x echo "" From 33cb90c4e22a2bac54bb7aa5637552ec04d79171 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Fri, 13 Sep 2024 10:37:59 +0200 Subject: [PATCH 04/10] Shellcheck fixes --- .../remote-cache-experiment-transforms.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index fdb04f265..863b4a357 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -5,11 +5,11 @@ gradleVersion=$(./gradlew --version | grep "Gradle" | awk '{print $2}') -major=$(echo $gradleVersion | cut -d. -f1) -minor=$(echo $gradleVersion | cut -d. -f2) +major=$(echo "$gradleVersion" | cut -d. -f1) +minor=$(echo "$gradleVersion" | cut -d. -f2) # Check if the version is lower than 8.9 -if [ $major -lt 8 ] || ([ $major -eq 8 ] && [ $minor -lt 9 ]); then +if [ "$major" -lt 8 ] || { [ "$major" -eq 8 ] && [ "$minor" -lt 9 ]; }; then echo "Gradle version $gradleVersion is lower than 8.9" exit 1 else @@ -25,9 +25,9 @@ tasks=${*:-help} echo "Initializing Gradle User Home directory at $homeDir" rm -rf $homeDir mkdir -p $homeDir -mkdir -p $homeDir/caches/$gradleVersion/ +mkdir -p $homeDir/caches/"$gradleVersion"/ cp ~/.gradle/gradle.properties $homeDir -cp -r ~/.gradle/caches/$gradleVersion/generated-gradle-jars $homeDir/caches/$gradleVersion/ +cp -r ~/.gradle/caches/"$gradleVersion"/generated-gradle-jars $homeDir/caches/"$gradleVersion"/ # Note: This is expecting that CCUD gradle plugin is applied export GRADLE_CACHE_REMOTE_PUSH=true From 0f5f2a589710064bc9e8d27c0872f9baec5a31bf Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Fri, 13 Sep 2024 10:44:08 +0200 Subject: [PATCH 05/10] Added a link to Inakis ArtifactTransformReport repo in the README --- transforms-caching-experiment/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index 53b8f8b6c..218e3052c 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -30,5 +30,5 @@ You can then compare the build times to see how transforms caching affects your ## Advanced usage - disabling specific transforms caching -If you are sure you are only suffering negative avoidance savings because of a select list of transforms retreiving outputs from cache you can disable only caching for those. To disable specific transforms caching, you can uncomment the line 48 in the script to enable running also experiments with specific transforms caching disabled. You will also need to modify the `disabledTransforms` variable in the script to specify the transforms you want to disable - there is an example supplied in the script. This will run the last two builds again, but with the specified transforms caching disabled - the tags added in scans for those build will be `baseline-transforms-selected` and `disabled-cache-transforms-selected`. +If you are sure you are only suffering negative avoidance savings because of a select list of transforms retreiving outputs from cache you can disable only caching for those. To disable specific transforms caching, you can uncomment the line 48 in the script to enable running also experiments with specific transforms caching disabled. You will also need to modify the `disabledTransforms` variable in the script to specify the transforms you want to disable - there is an example supplied in the script. This will run the last two builds again, but with the specified transforms caching disabled - the tags added in scans for those build will be `baseline-transforms-selected` and `disabled-cache-transforms-selected`. You can use https://github.com/cdsap/ArtifactTransformReport to get statistics on Artifact transforms for a single build or aggregating multiple builds. From 777dd7dfec32866d2f69a3521a403bc4f2de9723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C5=A1per=20Kojek?= Date: Mon, 16 Sep 2024 13:21:49 +0200 Subject: [PATCH 06/10] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Eric Haag Signed-off-by: Gašper Kojek --- transforms-caching-experiment/README.md | 8 ++++---- .../remote-cache-experiment-transforms.sh | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index 218e3052c..10c1dc3d5 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -10,22 +10,22 @@ It will run 3 builds: 2. Transform caching enabled - pulls from remote cache. The scan for this build will have a tag of `baseline-transforms`. 3. Transform caching disabled - executes the transforms. The scan for this build will have a tag of `disabled-cache-transforms`. -You can then compare the build times to see how transforms caching affects your builds. +You can then use the published build scans to evaluate how caching artifact transforms affects your overall build time. ## Requirements - A Develocity instance to publish scans to - Access key with remote build cache write permission - Gradle version 8.9 or higher -- The [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) is expected to be applied to the project. +- The [Common Custom User Data Gradle plugin](https://github.com/gradle/common-custom-user-data-gradle-plugin) is expected to be applied to the project ## Usage 1. Prepare an access key with remote build cache write permission. 2. Copy the script into your project directory. 3. (Optional) If you're using a HTTP cache connector, uncomment line 31 and set the remote cache URL in the script to use a cache shard instead of the default cache. -4. Having the key set in the environment is expected - note that remote build cache write is requiered. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`, either in the script, or in the terminal before running the script. -5. Run the script with `./transforms-caching-experiment.sh`. It will run the gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. +4. Having the key set in the environment is expected - note that remote build cache write is required. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`, either in the script, or in the terminal before running the script. +5. Run the script with `./transforms-caching-experiment.sh`. It will run the Gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. 6. Inspect and compare build times ## Advanced usage - disabling specific transforms caching diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index 863b4a357..947fc8225 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -29,7 +29,7 @@ mkdir -p $homeDir/caches/"$gradleVersion"/ cp ~/.gradle/gradle.properties $homeDir cp -r ~/.gradle/caches/"$gradleVersion"/generated-gradle-jars $homeDir/caches/"$gradleVersion"/ -# Note: This is expecting that CCUD gradle plugin is applied +# Note: This is expecting that CCUD Gradle plugin is applied export GRADLE_CACHE_REMOTE_PUSH=true export GRADLE_CACHE_REMOTE_PATH="cache/$USER-exp-non-task" #export GRADLE_CACHE_REMOTE_URL="/cache/$USER-exp-non-task" # Needed if the HTTP cache connector is used From 0df60d04f91e9ae1b090496bf55149ad7e2e85f6 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Mon, 16 Sep 2024 13:32:40 +0200 Subject: [PATCH 07/10] Added the invocation section to the README, and copied the access keys in the script --- transforms-caching-experiment/README.md | 20 ++++++++++++++++--- .../remote-cache-experiment-transforms.sh | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index 10c1dc3d5..29a4ed865 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -10,7 +10,9 @@ It will run 3 builds: 2. Transform caching enabled - pulls from remote cache. The scan for this build will have a tag of `baseline-transforms`. 3. Transform caching disabled - executes the transforms. The scan for this build will have a tag of `disabled-cache-transforms`. -You can then use the published build scans to evaluate how caching artifact transforms affects your overall build time. +You can then use the published build scans to evaluate how caching artifact transforms affects your overall build time. + +If results show that (remote) caching of transforms is not beneficial for your project, you can disable caching for (specific) transforms using the flags in this script. ## Requirements @@ -21,13 +23,25 @@ You can then use the published build scans to evaluate how caching artifact tran ## Usage -1. Prepare an access key with remote build cache write permission. +1. Ensure you have an access key with remote build cache write permission. 2. Copy the script into your project directory. 3. (Optional) If you're using a HTTP cache connector, uncomment line 31 and set the remote cache URL in the script to use a cache shard instead of the default cache. -4. Having the key set in the environment is expected - note that remote build cache write is required. You can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`, either in the script, or in the terminal before running the script. +4. Having the key set in the environment is expected - note that **remote build cache write is required**. If the key stored in your Gradle user home is missing the remote build cache write permission you can set the key in the environment by running `export DEVELOCITY_ACCESS_KEY==`, either in the script, or in the terminal before running the script. 5. Run the script with `./transforms-caching-experiment.sh`. It will run the Gradle `help` task by default, but you can specify a different task by passing it as an argument to the script. 6. Inspect and compare build times +### Invocation + +To run the script with the `help` task (default), use the following command: +```bash +./transforms-caching-experiment.sh +``` + +To run the script with a specific Gradle task(s), use the following command: +```bash +./transforms-caching-experiment.sh +``` + ## Advanced usage - disabling specific transforms caching If you are sure you are only suffering negative avoidance savings because of a select list of transforms retreiving outputs from cache you can disable only caching for those. To disable specific transforms caching, you can uncomment the line 48 in the script to enable running also experiments with specific transforms caching disabled. You will also need to modify the `disabledTransforms` variable in the script to specify the transforms you want to disable - there is an example supplied in the script. This will run the last two builds again, but with the specified transforms caching disabled - the tags added in scans for those build will be `baseline-transforms-selected` and `disabled-cache-transforms-selected`. You can use https://github.com/cdsap/ArtifactTransformReport to get statistics on Artifact transforms for a single build or aggregating multiple builds. diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index 947fc8225..11f1b149b 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -28,6 +28,8 @@ mkdir -p $homeDir mkdir -p $homeDir/caches/"$gradleVersion"/ cp ~/.gradle/gradle.properties $homeDir cp -r ~/.gradle/caches/"$gradleVersion"/generated-gradle-jars $homeDir/caches/"$gradleVersion"/ +cp -r ~/.gradle/develocity/ $homeDir/develocity/ +cp -r ~/.gradle/enterprise/ $homeDir/enterprise/ # Note: This is expecting that CCUD Gradle plugin is applied export GRADLE_CACHE_REMOTE_PUSH=true From 1755c50d0c14ba2514d654a87614e2a6cb097a6d Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Tue, 17 Sep 2024 10:50:18 +0200 Subject: [PATCH 08/10] Updated readme and changed the killall to pkill daemons to lessen the impact --- transforms-caching-experiment/README.md | 4 +++- .../remote-cache-experiment-transforms.sh | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index 29a4ed865..1a86f314b 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -14,6 +14,8 @@ You can then use the published build scans to evaluate how caching artifact tran If results show that (remote) caching of transforms is not beneficial for your project, you can disable caching for (specific) transforms using the flags in this script. +Note: Killing all gradle daemons is necessary for the experiments to give conclusive results. This may impact your ongoing work, so it is recommended to pause other work while the script is running. + ## Requirements - A Develocity instance to publish scans to @@ -39,7 +41,7 @@ To run the script with the `help` task (default), use the following command: To run the script with a specific Gradle task(s), use the following command: ```bash -./transforms-caching-experiment.sh +./transforms-caching-experiment.sh ``` ## Advanced usage - disabling specific transforms caching diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index 11f1b149b..9e2d9e90e 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -67,7 +67,7 @@ do echo "------------------------------------------------------------" set -x ./gradlew --stop - killall -9 java + pkill -f 'org.gradle.launcher.daemon.bootstrap.GradleDaemon' echo "Removing transforms from $homeDir/caches" rm -rf $homeDir/caches/*/transforms From 64e1be036fa5e6d1c73d42e29d433f87ee23a6a2 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Tue, 17 Sep 2024 16:48:27 +0200 Subject: [PATCH 09/10] Changed to script to use --no-deamon instead of killing the dangling daemon java processes. This should be safer, while still working the same way in my tests --- .../remote-cache-experiment-transforms.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index 9e2d9e90e..d693384a8 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -41,7 +41,7 @@ echo "Priming build with task '$tasks' and HOME=$homeDir" echo "------------------------------------------------------------" set -x # shellcheck disable=SC2086 -./gradlew $tasks -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false +./gradlew $tasks -g $homeDir -Dscan.tag.remote-cache-experiment-init --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false --no-daemon set +x runs='transforms' @@ -67,14 +67,13 @@ do echo "------------------------------------------------------------" set -x ./gradlew --stop - pkill -f 'org.gradle.launcher.daemon.bootstrap.GradleDaemon' echo "Removing transforms from $homeDir/caches" rm -rf $homeDir/caches/*/transforms rm -rf $homeDir/caches/transforms-* # Also remove the transforms for Gradle 8.7 # shellcheck disable=SC2086 - ./gradlew $tasks -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false $args + ./gradlew $tasks -g $homeDir --no-configuration-cache -Ddevelocity.deprecation.muteWarnings=true -Dscan.uploadInBackground=false -Dgradle.cache.local.enabled=false --no-daemon $args set +x echo "" From 362bbd3b08c500a1e561ecb7ac12a069df45e6e4 Mon Sep 17 00:00:00 2001 From: Gasper Kojek Date: Tue, 17 Sep 2024 16:58:37 +0200 Subject: [PATCH 10/10] Removed the gradlew --stop from the transforms caching experiment script, as that's not needed anymore since we're running with --no-daemon --- transforms-caching-experiment/README.md | 2 -- .../remote-cache-experiment-transforms.sh | 1 - 2 files changed, 3 deletions(-) diff --git a/transforms-caching-experiment/README.md b/transforms-caching-experiment/README.md index 1a86f314b..d8208cc01 100644 --- a/transforms-caching-experiment/README.md +++ b/transforms-caching-experiment/README.md @@ -14,8 +14,6 @@ You can then use the published build scans to evaluate how caching artifact tran If results show that (remote) caching of transforms is not beneficial for your project, you can disable caching for (specific) transforms using the flags in this script. -Note: Killing all gradle daemons is necessary for the experiments to give conclusive results. This may impact your ongoing work, so it is recommended to pause other work while the script is running. - ## Requirements - A Develocity instance to publish scans to diff --git a/transforms-caching-experiment/remote-cache-experiment-transforms.sh b/transforms-caching-experiment/remote-cache-experiment-transforms.sh index d693384a8..853b3e9a4 100755 --- a/transforms-caching-experiment/remote-cache-experiment-transforms.sh +++ b/transforms-caching-experiment/remote-cache-experiment-transforms.sh @@ -66,7 +66,6 @@ do echo "Test caches/*/transforms removal with $args" echo "------------------------------------------------------------" set -x - ./gradlew --stop echo "Removing transforms from $homeDir/caches" rm -rf $homeDir/caches/*/transforms