-
Notifications
You must be signed in to change notification settings - Fork 179
New feature: mbed cache #627
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Enable repo caching as default behavior
…stency Also improve help (a lot)
Comparison between first import and subsequent imports with caching enabled. The first import is heavily dependent on internet speed, and in the case below mbed-os was downloaded with 1.7 Megabytes per second. Prep
First import
Downloaded ~221MB with average speed 1.7MB/s Second import
Downloaded ~1.2MB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't comment on the code, but I applaud the idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Haven't had time to review the code, but the idea is superb. |
mbed/mbed.py
Outdated
@subcommand('cache', | ||
dict(name='on', nargs='?', help='Turn repository caching on. Will use either the default or the user specified cache directory.'), | ||
dict(name='off', nargs='?', help='Turn repository caching off. Note that this doesn\'t purge cached repositories. See "purge".'), | ||
dict(name='dir', nargs='?', help='Set cache directory. Set to "default" to let mbed CLI determine the cache directory location. Typically this is "~/.mbed/mbed-cache/" on UNIX, or "%%userprofile%%/.mbed/mbed-cache/" on Windows.'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to actually print out the folder it WOULD really use rather than guess? Do we know at this point or can we use just %s and substitute it in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this what you mean?
$ mbed cache
[mbed] Repository cache is ENABLED.
[mbed] Cache location "/Users/mihsto01/.mbed"
Note that the actual folder is /Users/mihsto01/.mbed/mbed-cache
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think Janne is asking about the help. so mbed cache -h
prints something OS + user specific.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed minor patch to support this.
Looks good 👍 |
README.md
Outdated
@@ -851,6 +851,30 @@ You can combine the options of the Mbed update command for the following scenari | |||
|
|||
Use these with caution because your uncommitted changes and unpublished libraries cannot be restored. | |||
|
|||
## Repository caching | |||
|
|||
To minimize traffic and reduce import times, by default Mbed CLI would cache repositories by storing their indexes under the Mbed CLI user config folder - typically `~/.mbed/mbed-cache/` on UNIX systems, or `%userprofile%/.mbed/mbed-cache/` on Windows systems. Compared to a fully checked out repository, indexes are significantly smaller in size and number of files, and contain the whole revision history of that repository. This allows Mbed CLI to quickly create copies of previously downloaded repository indexes and pull/fetch only the latest changes from the remote repositories, therefore dramatically reducing network traffic and download times, especially for big repositories like `mbed-os`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tense is weird here. Could you make it all active?
would cache -> caches
README.md
Outdated
mbed cache [on|off|dir <path>|ls|purge|-h|--help] | ||
``` | ||
|
||
* `on` - Turn repository caching on. Will use either the default or the user specified cache directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second sentence needs a subject.
"The cache will either be in the user specified location or the default location if the user has not specified a location"
README.md
Outdated
* `purge` - Purge cached repositories. Note that this doesn't turn caching off. | ||
* `-h` or `--help` - Print cache command options. | ||
|
||
If no sub-command is specified to `mbed cache`, then mbed CLI would print the current cache setting (ENABLED or DISABLED) and the path to the local cache directory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tense: would print -> prints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is that different compared to https://github.com/ARMmbed/mbed-cli/blob/master/README.md#compiler-detection-through-the-path. E.g. "If none
of the above are configured, the mbed compile command will fall
back to checking your PATH for an...". Are you suggesting that the tense should be corrected in the that part of the documentation as well? Note that you can find other occurrences of this all over the mbed CLI docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should probably correct the tense throughout the document. That should come as another PR then.
README.md
Outdated
|
||
If no sub-command is specified to `mbed cache`, then mbed CLI would print the current cache setting (ENABLED or DISABLED) and the path to the local cache directory. | ||
|
||
For safety reasons, Mbed CLI will always use `mbed-cache` subfolder to a user specified location. This ensure that no user files will deleted during `purge` even if the user has specified root/system folder as a cache location (e.g. `mbed cache dir /` or `mbed cache dir C:\`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the first sentence is hard to understand.
Proposal:
"For safty reasons, Mbed CLI always uses a sub-directory, mbed-cache
, within the user specified cache location.
README.md
Outdated
|
||
For safety reasons, Mbed CLI will always use `mbed-cache` subfolder to a user specified location. This ensure that no user files will deleted during `purge` even if the user has specified root/system folder as a cache location (e.g. `mbed cache dir /` or `mbed cache dir C:\`). | ||
|
||
**Security notice**: It's generally recommended to use cache location inside your profile home directory. If you use cache location outside your user home/profile, then other system users might be able to access the repository cache and therefore the data of the cached repositories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no subject on the first sentence. Who is recommending the cache location? Probably the Mbed CLI developers or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. The cache command function could be broken up into sub commands as functions, and I would find that more readable.
The reported cache location will now contain "mbed-cache" additional sub-folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Copy edit for minor grammar nits.
All stakeholders approved this PR. Will be merged soon (just fixing CI issues). |
@JanneKiiskila @studavekar Notice that this feature will turn caching on by default. On a CI system you might want to turn caching off as it will cache every PR repository. It's done by simply running |
This feature aims to minimize traffic and reduce import times, by making Mbed CLI cache repositories as a default behavior. Caching is done via storing repository indexes under the Mbed CLI user config folder - typically
~/.mbed/mbed-cache/
on UNIX systems, or%userprofile%/.mbed/mbed-cache/
on Windows systems.Compared to a fully checked out repository, indexes are significantly smaller in size and number of files, and contain the whole revision history of that repository. This allows Mbed CLI to quickly create copies of previously downloaded repository indexes and pull/fetch only the latest changes from the remote repositories, therefore dramatically reducing network traffic and download times, especially for big repositories like
mbed-os
.Workflow
No impact to existing workflows.
This PR introduces caching as default behavior and also a new
mbed cache
sub-command for cache management:on
- Turn repository caching on. Will use either the default or the user specified cache directory.off
- Turn repository caching off. Note that this doesn't purge cached repositories. See "purge".dir
- Set cache directory. Set to "default" to let mbed CLI determine the cache directory location. Typically this is~/.mbed/mbed-cache/
on UNIX systems, or%%userprofile%%/.mbed/mbed-cache/
on Windows systems.ls
- List cached repositories and their size.purge
- Purge cached repositories. Note that this doesn't turn caching off.-h
or--help
- Print cache command options.If no sub-command is specified to
mbed cache
, then mbed CLI would print the current cache setting (ENABLED or DISABLED) and the path to the local cache directory.For safety reasons, Mbed CLI will always use
mbed-cache
subfolder to a user specified location. This ensure that no user files will deleted duringpurge
even if the user has specified root/system folder as a cache location (e.g.mbed cache dir /
ormbed cache dir C:\
).Security notice: It's generally recommended to user cache location inside your own home directory. If you use cache location outside your user home/profile, then other system users might be able to access the repository cache and therefore the data of the cached repositories
How this works
Behind the scenes during
mbed import
ormbed add
, Mbed CLI will check whether repository caching is enabled and whether a cache folder exists for that repository in the correct location. Location is determined based on URL, e.g.https://github.com/ARMmbed/mbed-os-example-client
will be cached in `~/.mbed/mbed-cache/github.com/ARMmbed/mbed-os-example-client' (the actual files of the repositories will not be checked out, just the index).If repo index exists, Mbed CLI would make a carbon copy to the destination folder and try
fetch
for Git, orpull
for Mercurial.fetch
/pull
succeeds, then Mbed CLI checks-outs the repository normally.fetch
/pull
fails, then it's highly likely that the remote repository has been rewritten (bad bad repo admin!). In that case Mbed CLI ignores the cached repo, wipes the copy and does a normal clone of the repository, and lastly "feeds" the new/fresh index to the cache.Listing of cached repositories is done via
mbed cache ls
, e.g.Documentation
Documentation is included with this PR. There's a new section called "Repository caching".
@AnotherButler please review
Tests
Not yet
CC @sg- @theotherjimmy @janjongboom
Note that due to the additionally stored files, there might be impact to CI systems @JanneKiiskila @studavekar @0xc0170 @adbridge.