Skip to content

Design and implement a backend API and plugin framework #414

Closed

Description

@jrosdahl

Background

We want to refactor the code in preparation for introducing support for alternative/additional backends. See also #58.

What to do

  1. The API primitives should work for both the file system backend and other alternative backends.
  2. The API should preferably include a way for the backend to read configuration. Should we have namespaces in the configuration to separate different backends?
  3. Decide if the API should be open (usable by plugins not bundled with ccache, thus aptly documented and versioned) or closed (plugins are only used as an internal mechanism for improved code structure).
  4. Design the plugin framework.
  5. Make a plan on how to configure the interaction of backends in a generic way.
    • For instance, one might want to configure in which order backends should be queried and which backends should be read-only.
    • Or if we want to simplify things, we could decide that we only support one optional backend in addition to the standard one.

Activity

  1. pavsa commented on Jul 6, 2019

    @pavsa
    Contributor

    I think this issue should receive the highest priority now that various backend patches are starting to appear so that people can begin to implement various backends cleanly that would be easily merged to the master, instead of patches that work for one backend only.

    Also, if we are on the edge of switching to C++, this might be a very sensible time to do it. If we are to support querying multiple backends, the current code state is very inflexible for such scenario.

    We should definitely support querying multiple backends, even of the same type.
    For example, I would want to query two filesystem backends in two different directories, but one is read only, other one is read/write.

    There should be also an operation to verify the integrity of the cache contents.

  2. jrosdahl commented on Jul 14, 2019

    @jrosdahl
    MemberAuthor

    @pavsa wrote:

    I think this issue should receive the highest priority

    Right, it has quite high priority in the sense that I'm keeping it mind when doing various refactoring. (As mentioned in another issue, I've begun sketching an API.) It's not the highest priority for me at the moment, though – I think that polishing things related to #411 and #413 is more important right now.

    That said, if you or anybody else also is interested in designing an API, please go ahead and post ideas and opinions. One thing in particular to think about is bullet 3 in "What to do" in the issue description. I would personally like it if we could manage to make an open API so that backend implementations can have their own repos, ownership and life cycles.

    now that various backend patches are starting to appear

    Which patches do you refer to? I'm not aware of any lately appearing backend-related patches.

    Also, if we are on the edge of switching to C++, this might be a very sensible time to do it.

    Related to this: If we go for an open API, it will be in C (since there's no stable C++ ABI)... But yes, internal interfaces would be less clunky in C++ form.

    For example, I would want to query two filesystem backends in two different directories, but one is read only, other one is read/write.

    Agreed, that's one of the scenarios I had in mind for bullet 5.

    There should be also an operation to verify the integrity of the cache contents.

    You mean as part of the API? What do you think the semantics should be? What kind of integrity issues should be detected, etc?

  3. pavsa commented on Jul 27, 2019

    @pavsa
    Contributor

    I think this issue should receive the highest priority

    Right, it has quite high priority in the sense that I'm keeping it mind when doing various refactoring. (As mentioned in another issue, I've begun sketching an API.) It's not the highest priority for me at the moment, though – I think that polishing things related to #411 and #413 is more important right now.

    That said, if you or anybody else also is interested in designing an API, please go ahead and post ideas and opinions. One thing in particular to think about is bullet 3 in "What to do" in the issue description. I would personally like it if we could manage to make an open API so that backend implementations can have their own repos, ownership and life cycles.

    now that various backend patches are starting to appear

    Which patches do you refer to? I'm not aware of any lately appearing backend-related patches.

    I saw this one:
    #438

    Also, if we are on the edge of switching to C++, this might be a very sensible time to do it.

    Related to this: If go for an open API, it will be in C (since there's no stable C++ ABI)... But yes, internal interfaces would be less clunky in C++ form.

    What would be the advantage of open API?

    For example, I would want to query two filesystem backends in two different directories, but one is read only, other one is read/write.

    Agreed, that's one of the scenarios I had in mind for bullet 5.

    There should be also an operation to verify the integrity of the cache contents.

    You mean as part of the API? What do you think the semantics should be? What kind of integrity issues should be detected, etc?

    Yes, API call. We have no such functionality at present.
    It should simply iterate through all the stored objects and use the crc from the compression (or use the hash function for integrity) to verify the integrity of the stored data.

  4. jrosdahl commented on Jul 27, 2019

    @jrosdahl
    MemberAuthor

    What would be the advantage of open API?

    If somebody wants to implement support for backend X and the ccache project does not want to include support for X in the main code tree, then they can do it as a separate project if the API is open and stable. And why might the ccache project not want to include support for X? Because it would increase the test matrix and the maintenance burden.

    Yes, API call. We have no such functionality at present. It should simply iterate through all the stored objects and use the crc from the compression (or use the hash function for integrity) to verify the integrity of the stored data.

    OK. As of 42faf47, ccache verifies the integrity of all data at the time of retrieval. If corrupt data is found, it will simply decay and be removed as part of the normal cache eviction. Does that sound good enough or would you like to see more explicit "verify integrity" functionality? If so, why?

  5. afbjorklund commented on Jul 28, 2019

    @afbjorklund
    Contributor

    It was possible to do a "fsck" type of verification earlier, by running gzip --test on all the files.

    Maybe that functionality should be ported to the new storage too, similar to the compression * ?

    That code runs over all files in the cache and check their compression stats, not their checksum.

  6. afbjorklund commented on Aug 17, 2019

    @afbjorklund
    Contributor

    This new API needs to have support for multiple storage backends (at the same time),
    for features such as #58 and #380 - copying from a a central cache to a local cache...

    This is useful when having a build farm, then the cache can be distributed to new servers.
    Compilations would first check the local cache, and then try to copy from the remote cache.

  7. jrosdahl commented on Aug 17, 2019

    @jrosdahl
    MemberAuthor

    Maybe that functionality should be ported to the new storage too, similar to the compression * ?

    I don't quite see what would be gained with an explicit way of checking integrity since any problems will self-heal. And it's not like we're storing precious data.

    This new API needs to have support for multiple storage backends (at the same time),
    for features such as #58 and #380 - copying from a a central cache to a local cache...

    Hm... What I have in mind with a backend API is that it should define the interaction between ccache and a single storage backend, not multiple backends. ccache can then use it to talk to multiple implementations of the API in some configuable order.

    This is useful when having a build farm, then the cache can be distributed to new servers.
    Compilations would first check the local cache, and then try to copy from the remote cache.

    Right, this is partly what bullet 5 in the issue description is about.

  8. rmatev commented on Aug 17, 2019

    @rmatev

    ccache can then use it to talk to multiple implementations of the API in some configuable order.

    another possibility is that ccache talks to exactly one backend and going over multiple backends is done in a "dispatching" backend.

  9. afbjorklund commented on Aug 17, 2019

    @afbjorklund
    Contributor

    What I have in mind with a backend API is that it should define the interaction between ccache and a single storage backend, not multiple backends. ccache can then use it to talk to multiple implementations of the API in some configuable order.

    As long as ccache can use multiple backends at the same time, sharing the API makes sense.

  10. vaneyli commented on Sep 3, 2019

    @vaneyli

    This new API needs to have support for multiple storage backends (at the same time),
    for features such as #58 and #380 - copying from a a central cache to a local cache...

    This is useful when having a build farm, then the cache can be distributed to new servers.
    Compilations would first check the local cache, and then try to copy from the remote cache.

    Yes, ccache is a great tool to improve the building speed.

    With the help of a distributed backend, it can become a real cloud computing DevOps tool which is especially important in big company.

    The main key of the backend is the high efficiency. the only choice I think is the memory database.

    The #438 has been used in the product environment in alibaba for about a year and no error appeared.

    About 3W .o (total about 10G) cost only 5-6 mins.

    If anyone would like to try, just use it, Please see code at https://github.com/alibaba/xcache

  11. afbjorklund commented on Sep 3, 2019

    @afbjorklund
    Contributor

    The main key of the backend is the high efficiency. the only choice I think is the memory database.

    A memory-mapped database would probably work OK for ccache too... Especially if using a cache proxy ? (such as moxi, buffering the I/O)

    The memcached option is actually -network-based (as seen from the client), it’s only the server that is (as in: it usually is) memory-based.

  12. vaneyli commented on Sep 4, 2019

    @vaneyli

    The memcached option is actually -network-based (as seen from the client), it’s only the server that is (as in: it usually is) memory-based.

    Yes, I mean using the memory-based database in server which is the only choice for building. Any other databases which store items on disk are bad choices. Of course, they works but the building time would be longer which plus time of the network transmit. To achieve the highest speed is the goal of the build system.

  13. vaneyli commented on Sep 5, 2019

    @vaneyli

    "Design and implement a backend API and plugin framework"
    Although I have written a remote backend for ccache, I don't thinks it's the best choice. I don't mean the idea the backend API is bad :)

    The best soultion is: a new high efficency distributed filesystem based on fuse.
    Just put the cache dirs on the filesystem. No change needed to the code of ccache. the ccache become the a distributed!

    The evolution could be:

    local ccache -> ccache with remote backend -> ccache on NFS( a temporary stage for it would be hung when too many connections ) -> ccache on a new hight efficency distriubted filesystem based on fuse.

  14. jrosdahl commented on Sep 5, 2019

    @jrosdahl
    MemberAuthor

    @vaneyli: Please understand that "backend API" in this case refers to making it possible to optionally use another storage backend than the default "built-in classic filesystem-based" one. You would then be free to write and use as many real cloud computing DevOps new high-efficient distributed filesystem based on FUSE backends you like. 🙂

    Changing the default backend model to something much different from the current won't happen, at least not in this project.

    Yes, I mean using the memory-based database in server which is the only choice for building. Any other databases which store items on disk are bad choices.

    That is trivially not true. There are users who a) don't want or need the complexity of running a separate database server or b) don't have enough memory or servers to fit a large memory-based cache or c) want to keep the cache after rebooting servers. Just because your use case leads you to think in one direction doesn't mean that there aren't other perfectly valid use cases.

  15. 12 remaining items

  16. afbjorklund commented on Oct 19, 2020

    @afbjorklund
    Contributor

    I have some basic SQL implementation kicking around somewhere. Probably trivial to rewrite, though...
    I think the main goal of that ccache branch was actually to show how bad it was compared to NoSQL :-)

    But those were the suggested backends:

    • memcached
    • HTTP
    • NFS (i.e. path)
    • SQL

    Once the storage API is in place, that is.

  17. astnbomb commented on Nov 20, 2020

    @astnbomb

    Updated the memcached branch from 3.7.5 to 3.7.11, seems to be passing the tests at least:

    3.7-maint...afbjorklund:memcached-3.7

    @afbjorklund Really appreciate you bringing this up to date. My company has been using the original memcached-ccache branch (which lacks depend mode) and this will be a huge help.

  18. ftrofin commented on Dec 16, 2020

    @ftrofin
    Contributor

    Glad to discover this issue already exists, I was musing about this idea for a few months now... :-) I'm very interested in this topic, what are the plans for this feature? Is there a ccache developer channel (Discord, Slack, whatever) where these things are discussed?

  19. pavsa commented on Dec 16, 2020

    @pavsa
    Contributor

    How is the API state? Is there anything written yet? If not, I would be for closed C++ API only. As it's a cache, should be fast and single executable and therefore highly optimized when compiled.

  20. afbjorklund commented on Dec 16, 2020

    @afbjorklund
    Contributor

    Is there a ccache developer channel (Discord, Slack, whatever) where these things are discussed?

    There is https://gitter.im/ccache/ccache

  21. afbjorklund commented on Dec 16, 2020

    @afbjorklund
    Contributor

    As it's a cache, should be fast and single executable and therefore highly optimized when compiled.

    The main issue was that the "ccache" binary itself is started lots of time, once for each compilation...

    Normally a cache, especially a distributed one, has some startup and shutdown time for each invocation.
    This was why there was a persistent backend (called moxi*) for memcached, to handle the connections.
    So ccache could just talk to the daemon, and then shut down again. And it would carry the data further.
    You could also use for instance binary protocol and unix sockets locally, and then use ascii and tcp/ssl.

    * https://docs.couchbase.com/server/current/install/install-client-server.html#client-side-memcached-to-couchbase-proxy

  22. jrosdahl commented on Jan 2, 2021

    @jrosdahl
    MemberAuthor

    @ftrofin wrote:

    I'm very interested in this topic, what are the plans for this feature?

    There is no specific plan from my side at least. I may look into it some time when bugs introduced in the 4.0 release have been fixed. Fixing bugs has higher priority for me than adding new features. As I've written earlier, if somebody wants to start working on an API, please go ahead and contribute ideas.

    Is there a ccache developer channel (Discord, Slack, whatever) where these things are discussed?

    The Gitter channel mentioned by @afbjorklund exists, but note that it's a generic channel not only for ccache developers. There is now also Discussions which I think is the best place for some types of discussion.

    @pavsa wrote:

    How is the API state? Is there anything written yet?

    Nope. Have you written anything?

    If not, I would be for closed C++ API only.

    I'm still a bit sceptical of an in-tree closed API for the reasons mentioned in #414 (comment). We could make it an open C++ API if we feel that it would be OK if plugins potentially have to be recompiled after recompiling the main binary.

    As it's a cache, should be fast and single executable and therefore highly optimized when compiled.

    If you worry about dynamic loading of code then I don't think you should be very worried. As @afbjorklund wisely mentions, the process architecture will matter much more for network-based backends.

  23. afbjorklund commented on May 25, 2021

    @afbjorklund
    Contributor

    There is a very simplistic API in the PR #676, with implementations for HTTP and Redis:

    class StorageBackend
    {
    public:
      virtual ~StorageBackend() = default;
    
      virtual bool storeInBackendOnly() const = 0;
    
      virtual bool getResult(const Digest& digest, const std::string& path) = 0;
      virtual bool getManifest(const Digest& digest, const std::string& path) = 0;
    
      virtual bool putResult(const Digest& digest, const std::string& path) = 0;
      virtual bool putManifest(const Digest& digest, const std::string& path) = 0;
    };

    Another implementation like for instance MySQL or File should be easy to add, as well ?

    classStorageBackend__inherit__graph

    I moved the previous memcached implementation to a separate maintenance project.
    There is probably no code that can be reused, and using redis instead is much easier.

    The combined "result" files are already included, and there is no 1M value limit there.
    Previously we used couchbase, but it has focused more on being a JSON database...

  24. afbjorklund commented on Jun 5, 2021

    @afbjorklund
    Contributor

    For the modern backends, there is a replacement for the old moxi and couchbase setup.
    It still uses memory where available, and it still uses a NoSQL database for storing data...

    Old (ccache 3): ccache/distcc + memcached/distccd

    New (ccache 4): ccache/distcc + nginx|redis/distccd

    • HttpBackend (served by nginx+webdav)
    • RedisBackend (backed by redis-server)

    It will be interesting to compare the ccache performance of the nginx and the redis setup...
    Comparing the old setup with the new setup will also have some historical interest perhaps.

    Other topics:

    • HttpBackend vs. FileBackend (HTTP vs NFS)
    • RedisBackend vs. MysqlBackend (NoSQL vs SQL)

    Locally one configures "nutcracker" to work as a proxy, towards the real Redis server(s):

    https://blog.twitter.com/developer/en_us/a/2012/twemproxy.html (as used by Twitter)

    Then on the remote side, one can use "ardb" to persist the data into a NoSQL database:

    http://rocksdb.blogspot.com/2013/11/the-history-of-rocksdb.html (as used by Facebook)

    The main difference for ccache is that one uses "localhost" instead of the remote servers.
    To the application (i.e. ccache or redis-cli), it will just look like a local Redis server.

    The local server also takes care of authentication/encryption and the connection pooling.
    It's also possible to do multiple servers and replication, even if a more advanced topic.

  25. jrosdahl commented on Jun 6, 2021

    @jrosdahl
    MemberAuthor

    @afbjorklund wrote:

    There is a very simplistic API in the PR #676 [...]

    Right, that's an internal API for secondary storage, which basically only requires get and put operations. Just to clarify, what I had in mind with this issue was to investigate and discuss (and potentially reject) plugins, i.e. dynamically loaded code, and an open API that could be used for primary storage as well (i.e. an API that the current standard file cache could implement and that would make it possible to replace it with something else). Such an API would also need to include parts related to storage of statistics counters, support for hard links, etc. I did hope to have time to do this.

    That said, I have now decided how I want to go forward with storage backends: I'm ready to scrap the idea of introducing real plugins, at least for now, since apparently neither I nor anybody else has had time and motivation to pursue it. This makes the answer to bullet 3 "the API should be closed" and the answer to bullet 2 "not applicable". I'm also OK with reducing the scope of bullet 1 to just secondary storage since it makes it much easier, and it's of course secondary storage solutions that people mostly have been asking about. Left to do is to think more about the configuration (bullet 5).

    More concretely, my thoughts right now look something like this:

    1. Determine how to leave the configuration open for enabling multiple backends at the same time. No need to support more than one at a time initially, but it would be good if the configuration format is prepared for such a use case and also for the use case of Add support for two level cache #380 where an alternative backend comes before the standard one. Also, I think that it would be good to be able to specify backend-specific attributes (like read-only) without inventing new ccache variables for this. For example, if we want to implement an AWS S3 storage backend then one needs to specify access key and secret key – I would prefer to not add CCACHE_S3_... variables for that. Put differently, I would like to have no backend-specific variables since that allows for future plugins to have specific configuration without having to hook into the main configuration parser.
    2. Figure out which statistics counters should be added for secondary storage. Probably OK to just have "secondary cache hit/miss/rate", not counters per backend type.
    3. Add an internal API for secondary storage, quite similar to the proposed one in Add secondary HTTP storage #676.
    4. Add a simple file backend implementation (for secondary cache on NFS, say).
    5. "Simple" backends can be bundled with ccache, where "simple" here means something like "with minimal external dependencies". For instance, I would like to avoid depending on more external libraries unless they are ubiquitous and small enough.
    6. Backends I see would fit this definition are an HTTP GET/PUT backend like in Add secondary HTTP storage #676 and various HTTP-based cloud storage ones. Redis would also be a good fit.
    7. Is memcached still of interest?
  26. afbjorklund commented on Jun 6, 2021

    @afbjorklund
    Contributor

    Most plugin system have the opportunity to do both kind of plugins, you would have main plugins that are compiled in and included by default. And then you can have some kind of dlopen (or gRPC) way to add third-party plugins, that can be added afterwards ? You could also have plugins that are included in the source code, but only enabled by special configuration. Like this MySQL sample backend that is of limited interest as default - but could be valid as sample code or as a basis for some other new plugin ?

    As an example, I would do the FileBackend always included (no dependencies). The HttpBackend and RedisBackend configured ON by default (just one system library each, libcurl and libhiredis) and for instance MysqlBackend configured OFF by default (requires libmysqlclient, might not be useful). The CMake configuration makes it easy to turn off and on, so it would be possible to build a local-only ccache by disabling them. But we have seen that we want to include most of them by default, i.e. "where available".

    Having a simple way of doing configuration sounds good. Some of them have lots and lots of little knobs and dials, but when putting all of them in one string or one config file it becomes manageable. That's how it is configured now (for the user at least), but having all the variables in the config source code and documentation is not great - so if there was a better and common way to do that, it would be preferred. Maybe a second configuration file, for the storage backend ? Currently it's been one-liners, for params:

    export CCACHE_MEMCACHED_CONF=--SERVER=localhost
    export CCACHE_MEMCACHED_CONF=--SOCKET=/tmp/memcached.sock
    export CCACHE_MEMCACHED_CONF=--SERVER=localhost:11311

    The string/file is passed to the backend library, which handles parsing.

    I would like to avoid depending on more external libraries unless they are ubiquitous and small enough.

    Another criteria would be "readily available in most distributions", makes building and installing so much easier...

    I think the selected libraries (cURL, hiredis) are available everywhere. Or at least widely known, where to get them.

    Is memcached still of interest?

    The memcached had some unique features, but also some severe limitations (1 MB maximum value size, in default configuration!). I think the "memcached_only" feature can be emulated by just storing a local copy on temporary disk (instead of having to fork the entire code, just to avoid local files) and the ketama consistent hashing can be handled by an external program like this "nutcracker". So it seems like using redis will now be a good replacement for it, it might be (a little) slower but much easier code.

    So I forked off the old memcached C code to a separate repository, I don't think there is any need for a new backend for it ?

    If there is, it could be one of those "extra" plugins that are available in the source code - but disabled by default configuration.

    I have some small python programs that will upload the entire cache directory to the remote backend storage, so the plan was to use them for some testing. Eventually one want to compare also the end-to-end process including the internal upload, but it makes for doing some comparisons. For the tests that I had in mind, the max cache size is usually 50.0 GB (without compression). Typically getting around 75% space savings from Zstd compression, so it's around 10G of ccache data for some 100,000 C/C++ files.

  27. jrosdahl commented on Jun 6, 2021

    @jrosdahl
    MemberAuthor

    Most plugin system have the opportunity to do both kind of plugins

    Right, I know how plugins and plugin framework tend to work. I would like to not discuss plugins right now.

    [...] and for instance MysqlBackend configured OFF by default (requires libmysqlclient, might not be useful)

    A problem I see with backends not enabled by default is that they make the documentation messy. I would prefer if all bundled backends are expected to be enabled by default so that the documentation doesn't have to say "if enabled", etc.

    Having a simple way of doing configuration sounds good.

    I have actually been thinking about this during the past days and will write down my current ideas soon.

    Another criteria would be "readily available in most distributions", makes building and installing so much easier...

    Yes, that's what I meant with ubiquitous.

    I think the selected libraries (cURL, hiredis) are available everywhere. Or at least widely known, where to get them.

    Right, but curl fails the "small enough" criterion.

  28. jrosdahl commented on Jun 6, 2021

    @jrosdahl
    MemberAuthor

    I have now created a Storage backends project which collects tasks and ideas related to this.

    Let's close this issue about the plugin framework since we're not doing that within the foreseeable future.

  29. added
    status: won't fix
    on Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue: featurestatus: won't fix

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions