Skip to content

Add secondary HTTP storage - #676

Merged
jrosdahl merged 3 commits into
ccache:masterfrom
gjasny:httpcache-backend
Jul 8, 2021
Merged

jrosdahl merged 3 commits into
ccache:masterfrom
gjasny:httpcache-backend

Conversation

@gjasny

@gjasny gjasny commented Oct 2, 2020

Copy link
Copy Markdown
Contributor

Hello,

this is my attempt to add an HTTP backend-storage to ccache. Despite trying we did not had success enlarging memcached with extstore. While working with Bazel we had good experience with it's HTTP-based remote caching. So I thought it might be easiest to go with a simple HTTP storage backend first. There we also won't have to care about splitting the cache content into 1 MByte chunks.

The good news is also that my employer LogMeIn allowed me to contribute code as part of my regular work. Legal also signed off.

Could you please take a look at the changes and tell me where things could be improved or completely reworked?

Thanks,
Gregor

PS: I really like the new CMake and C++11 code base!

@gjasny gjasny changed the title feat: started httpcache storage backend WIP: add httpcache storage backend Oct 2, 2020
@AlexanderLanin

Copy link
Copy Markdown
Contributor

Besides the actual change which I cannot comment on, I wonder why HTTPCACHE_BACKEND is a compile time flag. Is there any significant downside to include it always?

@jrosdahl jrosdahl added the issue: feature New feature label Oct 5, 2020
@jrosdahl

jrosdahl commented Oct 5, 2020

Copy link
Copy Markdown
Member

Hi @gjasny, I'll have to come back to this some time after the 4.0 release.

@gjasny
gjasny force-pushed the httpcache-backend branch 2 times, most recently from 44dbfc4 to bbcd7c5 Compare October 7, 2020 15:43
@afbjorklund

This comment has been minimized.

@afbjorklund

Copy link
Copy Markdown
Contributor

I wonder why HTTPCACHE_BACKEND is a compile time flag. Is there any significant downside to include it always?

Seems to add a dependency on libcurl

@AlexanderLanin

Copy link
Copy Markdown
Contributor

This sounds great but has been stale for a while. Sounds like that could be a really huge performance boost to caching in company environments (10+ people working on same codebase, but compiling locally like in the 80s).

Potential improvements:

@afbjorklund

afbjorklund commented May 18, 2021 •

Copy link
Copy Markdown
Contributor

Was there any updates on this ? I updated to 4.3, and it seemed to be working still: 80d1726

I used nginx (http://localhost:8080/cache) and curl for my testing, and it was quite simple to set up.

For testing purposes you can pull and push with curl (GET) and curl --upload-file (PUT) over http.


Sounds like that could be a really huge performance boost to caching in company environments (10+ people working on same codebase, but compiling locally like in the 80s).

It also helps when you have a build farm, like when doing continuous integration...

Is this already compatible to something? It definitely should be compatible to existing (google, aws, azure) solutions, otherwise it's useless. e.g. https://docs.bazel.build/versions/master/remote-caching.html#http-caching-protocol

If you want it more compatible with those, then I think you need to add CAS support.

One approach if you want to share the cache with other systems, is to do it for the files only.
There is already support to store "raw files" (in addition to embedded), so it should be doable.

Instead of storing the files in a path, it calculates the SHA-256 checksum (as hex) and uses that

For ccache we had it in the memcached backend, but only for file fragments and not whole files.
We also used the built-in fast and small checksum to do it, instead of the slow and big sha2 standard.


UPDATE: Moved CAS (deduplication) to a separate topic, so please ignore for this PR.

It is only "needed" for Bazel compatibility, but not a requirement for using cloud storage.

ac/01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b

cas/15e2b0d3c33891ebb0f1ef609ec419420c20e320ce94c65fbc8c3312448eb225

@afbjorklund

This comment has been minimized.

@gjasny

gjasny commented May 18, 2021

Copy link
Copy Markdown
Contributor Author

At work we switched from the memcached backend to the plain http put / get storage backend and were able to replace a 300GB RAM equipped EC2 instance with a much smaller one with 40gb network interface and a 2TB local disk at 1/10th of the price. It's backed by a nginx with sendfile enabled. Performance is great and it's running without issues since December.

Our ccache is still at the 3.something memcache branch with my http patches ontop. I'll try to work on this issue during my non-feature Fridays.

@ftrofin

This comment has been minimized.

@afbjorklund

This comment has been minimized.

@afbjorklund

This comment has been minimized.

@afbjorklund

afbjorklund commented May 25, 2021 •

Copy link
Copy Markdown
Contributor

@gjasny : I fixed the tracing (as per "todo") in 23235c7, but also discovered that it (tracing) was broken on master...

It would be nice if we could have some kind of StorageBackend available on master, with only a "null" implementation ?


Did you have any thoughts about how configuration could scale to having multiple backends ?

Obviously having one variable for each is not great, when talking about 4 or 5 storage backends...

CCACHE_HTTPCACHE_URL=http://localhost:8080/cache

CCACHE_REDISCACHE_URL=localhost:6379

CCACHE_FILECACHE_URL=/mnt/nfs/path/to/shared/cache

CCACHE_MYSQLCACHE_URL=localhost:3306

There was also the discussion about compile-time vs. run-time (plugins), for configuring them.

Sorry for hi-jacking the original HTTP request, we could move the discussion somewhere else.

@afbjorklund

This comment has been minimized.

@Romain-Geissler-1A

This comment has been minimized.

@afbjorklund

This comment has been minimized.

@afbjorklund

This comment has been minimized.

@jrosdahl

jrosdahl commented Jun 6, 2021

Copy link
Copy Markdown
Member

I wrote:

Hi @gjasny, I'll have to come back to this some time after the 4.0 release.

Sorry for taking so long to come back to this. The 4.0 release has now happened and I've made a couple of (mostly) bug fix releases, so now the storage backend stuff has bubbled higher up on my list of things to think about.

Thanks for the PR – it's generous of your company to allow you to contribute code! 👍

Before summarizing my thoughts on this I have some replies to comments made by others.

@jrosdahl

jrosdahl commented Jun 6, 2021

Copy link
Copy Markdown
Member

@AlexanderLanin wrote:

I personally think the discussion in #414 has been going on long enough.

I would say that the problem with #414 is that the real discussion did not even start, not that it has been going on long enough. But see my recent comment to #414.

So we should just go ahead with this one and be done with it.

If you mean "just merge it": No we shouldn't.

Is this already compatible to something?

Yes, plain HTTP GET/PUT is compatible with many servers.

@jrosdahl

This comment has been minimized.

@jrosdahl

This comment has been minimized.

@jrosdahl

jrosdahl commented Jun 6, 2021

Copy link
Copy Markdown
Member

@gjasny: Here is some feedback on the PR:

  • It looks like storeInBackendOnly isn't needed since that information is available via the config and doesn't need to be stored in the backend instance.
  • We should think more about generalizing the configuration settings. For instance, what should happen if another backend is configured as well? There needs to be some defined order in which lookups occur.
  • It would be good to have statistics counters for hits and misses for secondary storage.
  • Documentation needs to be updated.
  • I would like to avoid a dependency on libcurl. The main reason is that it's so competent that it's also very large (when including dependencies) – the increased startup time just by linking (dynamically) with libcurl is around 4-5 ms, which maybe doesn't sound much, but it's is a ≈300% increase (≈1.6 ms vs ≈6.4 ms on my system). Those milliseconds matter since fast cache hits take much less than 6.4 ms. (Linking statically libcurl is not feasible.) I think that it would be very interesting to try out https://github.com/yhirose/cpp-httplib as an alternative.

See also my comment to #414.

@jrosdahl jrosdahl mentioned this pull request Jun 6, 2021
@afbjorklund

This comment has been minimized.

@jrosdahl

This comment has been minimized.

@gjasny
gjasny force-pushed the httpcache-backend branch 3 times, most recently from c25c4e7 to 2ecd72f Compare June 28, 2021 11:47
@gjasny

gjasny commented Jun 28, 2021

Copy link
Copy Markdown
Contributor Author

I'll add an URL class and tests tomorrow.

@gjasny

gjasny commented Jun 29, 2021 •

Copy link
Copy Markdown
Contributor Author

Todo:

  • Test IPv6 capabilities of http client lib
  • Print error string instead of 4: Failed to put /edf0hot67e21geacg88dfjeceoug56vpk to http storage: error code: 4
  • Connection keep-alive
  • URL class
  • replace sleep 1 in start_http_server within secondary_http.bash

@jrosdahl jrosdahl linked an issue Jul 1, 2021 that may be closed by this pull request
@jrosdahl

jrosdahl commented Jul 1, 2021

Copy link
Copy Markdown
Member

Thanks for working on this!

The title says "WIP" and there are items left on the to do list, so perhaps mark the PR as a draft until ready for review?

Regarding authentication: I would like that to be supported (both via URL and via username/password attributes in the secondary_storage string), but that of course can be done as a separate task later.

Another thing that I would like to see (again: can be done later if wanted) is configurable timeouts (see #859 (comment)).

@gjasny
gjasny force-pushed the httpcache-backend branch from adb0c11 to 8c36a06 Compare July 2, 2021 12:08
@gjasny gjasny changed the title WIP: add httpcache storage backend Add secondary HTTP storage Jul 2, 2021
@gjasny

gjasny commented Jul 2, 2021

Copy link
Copy Markdown
Contributor Author

Hello,

I believe this PR is ready for a review. There are some follow-up tasks:

  • Configure and enforce HTTP timeouts
  • Refactor Storage class to use Url class
  • Authentication
  • HTTPS support

I'll start working on those during the next days.

Thanks,
Gregor

@gjasny
gjasny force-pushed the httpcache-backend branch from 8c36a06 to d72397d Compare July 2, 2021 12:19
Comment thread doc/MANUAL.adoc Resolved
Comment thread doc/MANUAL.adoc Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread test/run Resolved
Comment thread test/suites/secondary_http.bash Resolved
Comment thread test/suites/secondary_http.bash Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread test/suites/secondary_http.bash Resolved
@gjasny
gjasny force-pushed the httpcache-backend branch 2 times, most recently from aaa4039 to f6a8d72 Compare July 6, 2021 12:14
@gjasny

gjasny commented Jul 6, 2021

Copy link
Copy Markdown
Contributor Author

Ready for another review.

Comment thread src/system.hpp Resolved
Comment thread doc/MANUAL.adoc Resolved
Comment thread doc/MANUAL.adoc Resolved
Comment thread doc/MANUAL.adoc Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread src/storage/secondary/HttpStorage.cpp Resolved
Comment thread src/storage/secondary/HttpStorage.hpp Resolved
Comment thread test/suites/secondary_http.bash Resolved
@gjasny
gjasny force-pushed the httpcache-backend branch from f6a8d72 to df7afba Compare July 7, 2021 10:32
@gjasny

gjasny commented Jul 7, 2021

Copy link
Copy Markdown
Contributor Author

Window build looks fine. But after removing my conflicting commit I cannot resolve the conversation, anymore.

Comment thread LICENSE.adoc Resolved
Comment thread doc/MANUAL.adoc Resolved
Comment thread test/suites/secondary_http.bash Resolved
@gjasny
gjasny force-pushed the httpcache-backend branch from df7afba to 64f6522 Compare July 7, 2021 22:10
@gjasny
gjasny force-pushed the httpcache-backend branch from 64f6522 to a28ad9d Compare July 7, 2021 22:11
@jrosdahl jrosdahl added this to the 4.4 milestone Jul 8, 2021
@jrosdahl
jrosdahl merged commit 4eabb63 into ccache:master Jul 8, 2021
@jrosdahl

jrosdahl commented Jul 8, 2021

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

issue: feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Storage backends: HTTP

6 participants