Commit 4253490
authored
Speed up cache saving (#1902)
At the end of the build, the Python installation including the
site-packages directory (which contains the app's dependencies) has to
be copied from the build directory to the cache directory, so that it's
cached for the next build.
For apps with very large dependencies this can take a considerable
amount of time (Honeycomb reports `python.cache_save_duration` as having
a P99.9 of 28 seconds).
I'd previously benchmarked using `cp --reflink=auto` in the hopes of
improving this in a way that would be compatible with all configurations
(including Heroku CI and `build-in-app-dir`), but found it made performance
worse for standard builds with the current production build system's
filesystems and mount configurations.
This leaves `cp --link` (which uses hardlinks) as the last way we can
improve performance - but using this means:
1. We need to check whether the cache and build directory are on the
same filesystem mounts (since otherwise the copy will fail with a
`Invalid cross-device link` error).
2. Any modifications made to the files in one location affects the
other. (eg by later buildpacks)
However, given the Honeycomb data shows the time spent saving the cache
really is significant for some apps, it's clear that using `--link` is
worth the complexity/mutability trade-offs. In addition, Python package
managers typically fully uninstall a package before reinstalling it at
a different version - so if any apps perform `pip install` type
operations in later buildpacks (which isn't something we officially
support anyway), the cache should still be left in a valid state.
Note: We use `df` to determine whether both locations are on the same
filesystem mount since `stat`'s device number reports the same value
for separate filesystems that happen to be mounted on the same backing
device.
See:
- https://manpages.ubuntu.com/manpages/noble/en/man1/cp.1.html
- https://manpages.ubuntu.com/manpages/noble/en/man1/df.1.html
GUS-W-19603153.1 parent 04d8c0d commit 4253490
2 files changed
Lines changed: 19 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
174 | | - | |
175 | 174 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
182 | 193 | | |
183 | 194 | | |
184 | 195 | | |
| |||
0 commit comments