Repository navigation
MAINT Increase ccache hit rate on Azure Pipelines - #22213
Conversation
Azure does not seem to update existing cache with the same name. Therefore it seems that the ccache folder contents can get stalled and the hit rate seems to diminish over time. Base on my understanding of https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops it seems that if a segment of the key is a filename (and hopefully a directory?), the contents of the file (assumed to be relative to $(Pipeline.Workspace)) will be used to check if an updated version of the cache blob needs to be re-uploaded. By putting the ccache foldername as a cache key segment, I hope that the cache will be updated whenever a compiled binary artifact has been updated.
|
Let us wait for this first CI run to complete before pushing a new commit to trigger a second consecutive run and see the impact in terms of build speed and check the logs to see if the update actually happens in the post-job ccache step and also check the hit rate in the call to |
|
Note that I wrote |
|
Ok so in the first build we had in the post-job ccache step: Not sure what it means... |
thomasjpfan
left a comment
There was a problem hiding this comment.
This change is consistent with the Azure Docs on ccache.
It looks like it works well for some of the runs such as py37_conda_forge_openblas_ubuntu_1804 with 48% hits in the cache.
Installs that use pip install -e . such as pylatest_pip_openblas_pandas has 11% hits. I think this is due to pip install -e . always creating a new env where NumPy headers are installed in a new tmp directory every time.
Also osx build does not use the cache. We can work on that in another PR.
Interesting analysis. But before investigating that let me push a Cython code change to check that the cache gets invalidated in the post job step. |
|
The docker-based build will also need special attention to mount the |
|
Hum, after the Cython code change, it seems that the post-job does not want to use the changed ccache folder contents to invalidate the existing cache: Let me try to add the build number to the cache key. |
|
I will also disable the tests to iterate faster. But probably another day as it's late here in Europe. Fill free to push to this PR if you want to experiment in the mean time. |
|
Ok the cache hit rate has improved significantly for all the linux and macos builds. This can cut ~5 min of redundant compilation for most jobs.
The hit rate for For Windows, it might be either possible to configure ccache or clcache but that seems quite a lot more work to do and I don't have a windows VM handy to try to setup locally. |
| displayName: ccache | ||
| continueOnError: true | ||
| - script: > | ||
| mkdir -p $CCACHE_DIR |
There was a problem hiding this comment.
This is necessary to bootstrap after an invalidation otherwise one would get a file not found error in the post-job ccache step.
Maybe it would be possible to write a CI-specific ccache config file to disable the hashing of the CWD (current working directory) to increased the cache hit rate when building from the pip-generated isolated temp build folder. However I fear this will be a lengthy trial and error process. I think this PR is useful enough to be merged as is without optimizing that last point. |
I have used CCACHE_BASEDIR in another project to change the "base directory" so paths can be relative. I have not tried it in the context of I agree that we have now is already improvement, so let's merge first and we can make more improvements later. |
|
Note that the |
Azure does not seem to update existing cache entries with the same key.
Therefore it seems that the ccache folder contents can get stalled and the hit rate seems to diminish over time.
Base on my understanding of https://docs.microsoft.com/en-us/azure/devops/pipelines/release/caching?view=azure-devops it seems that if a segment of the key is a filename (and hopefully a directory?), the contents of the file (assumed to be relative to $(Pipeline.Workspace)) will be used to check if an updated version of the cache blob needs to be re-uploaded.
By putting the ccache foldername as a cache key segment, I hope that the cache will be updated whenever a compiled binary artifact has been updated.EDIT: Azure's "Cache" step cannot automatically hash the contents of the
ccachefolder to be build an automatically invalidated key segment. Therefore I decided to use the ever incremented build nbumber at the last segment of the key and it seems to work as expected at the small expense of potential unnecessary uploads to the cache blob store.Unused cached entries are automatically collected after a week so we should not waste too much resources.