2022-06-09 16:00:14 +00:00
+++
title="We tried IPFS over Garage"
date=2022-06-09
+++
2022-06-15 17:47:23 +00:00
*Once you have spawned your Garage cluster, you might be interested in finding ways to share efficiently your content with the rest of the world,
such as by joining federated platforms.
In this blog post, we experiment with interconnecting the InterPlanetary File System (IPFS) daemon with Garage.
We discuss the different bottlenecks and limitations of the software stack as it is currently available.*
2022-06-09 16:00:14 +00:00
<!-- more -->
<!-- Garage has been designed to be operated inside the same "administrative area", ie. operated by a single organization made of members that fully trust each other.
It is an intended design decision: trusting each other enables Garage to spread data over the machines instead of duplicating it.
Still, you might want to share and collaborate with the rest of the world, and it can be done in 2 ways with Garage: through the integrated HTTP server that can serve your bucket as a static website,
or by connecting it to an application that will act as a "proxy" between Garage and the rest of the world.
2022-06-15 17:47:23 +00:00
We refer as proxy software that know how to speak federated protocols (eg. Activity Pub, Solid, RemoteStorage, etc.) or distributed/p2p protocols (eg. BitTorrent, IPFS, etc.).-->
2022-06-09 16:00:14 +00:00
2022-06-10 15:25:53 +00:00
## Some context
2022-06-09 16:00:14 +00:00
People often struggle to see the difference between IPFS and Garage, so let's start by making clear that these projects are complementary and not interchangeable.
2022-06-10 15:25:53 +00:00
2022-06-15 17:47:23 +00:00
Personally, I see IPFS as the intersection between BitTorrent and a file system. BitTorrent remains to this day one of the most efficient ways to deliver
a copy of a file or a folder to a very large number of destinations. It however lacks some form of interactivity: once a torrent file has been generated, you can't simply
add or remove files from it. By presenting itself more like a file system, IPFS is able to handle this use case out-of-the-box.
2022-06-10 15:25:53 +00:00
2022-06-15 17:47:23 +00:00
<!-- IPFS is a content - addressable network built in a peer - to - peer fashion.
2022-06-09 16:00:14 +00:00
With simple words, it means that you query the content you want with its identifier without having to know *where* it is hosted on the network, and especially on which machine.
2022-06-10 15:25:53 +00:00
As a side effect, you can share content over the Internet without any configuration (no firewall, NAT, fixed IP, DNS, etc.).-->
2022-06-09 16:00:14 +00:00
2022-06-10 15:25:53 +00:00
<!-- However, IPFS does not enforce any property on the durability and availablity of your data: the collaboration mentioned earlier is
2022-06-09 16:00:14 +00:00
done only on a spontaneous approach. So at first, if you want to be sure that your content remains alive, you must keep it on your node.
And if nobody makes a copy of your content, you will loose it as soon as your node goes offline and/or crashes.
Furthermore, if you need multiple nodes to store your content, IPFS is not able to automatically place content on your nodes,
2022-06-10 15:25:53 +00:00
enforce a given replication amount, check the integrity of your content, and so on.-->
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
However, you would probably not rely on BitTorrent to durably store your encrypted holiday pictures you shared with your friends,
as content on the BitTorrent tends to vanish when no one in the network has a copy of it anymore. The same applies to IPFS.
If at some time, everyone has a copy of the pictures on their hard disk, people might delete these copies after a while without you knowing it.
You also can't easily collaborate to share this common treasure. For example, there is no automatic way to say that Alice and Bob
2022-06-10 15:25:53 +00:00
are in charge of storing the first half of the archive while Charlie and Eve are in charge of the second half.
2022-06-09 16:00:14 +00:00
➡️ **IPFS is designed to deliver content.**
2022-06-10 15:25:53 +00:00
*Note: the IPFS project has another project named [IPFS Cluster ](https://cluster.ipfs.io/ ) that allow servers to collaborate on hosting IPFS content.
2022-06-15 17:47:23 +00:00
[Resilio ](https://www.resilio.com/individuals/ ) and [Syncthing ](https://syncthing.net/ ) both feature protocols inspired by BitTorrent to synchronize a tree of your file system between multiple computers.
2022-06-10 15:25:53 +00:00
Reviewing these solutions is out of the scope of this article, feel free to try them by yourself!*
2022-06-15 17:47:23 +00:00
Garage, on the contrary, is designed to spread automatically your content over all your available nodes, in a manner that makes the best use possible of your storage space.
At the same time, it ensures that your content is always replicated exactly 3 times across the cluster (or less if you change a configuration parameter),
on different geographical zones when possible.
2022-06-10 15:25:53 +00:00
<!-- To access this content, you must have an API key, and have a correctly configured machine available over the network (including DNS/IP address/etc.). If the amount of traffic you receive is way larger than what your cluster can handle, your cluster will become simply unresponsive. Sharing content across people that do not trust each other, ie. who operate independant clusters, is not a feature of Garage: you have to rely on external software. -->
2022-06-15 17:47:23 +00:00
However, this means that when content is requested from a Garage cluster, there are only 3 nodes that are capable of returning it to the user.
As a consequence, when content becomes popular, these nodes might become a bottleneck.
Moreover, all resources created (keys, files, buckets) are tightly coupled to the Garage cluster on which they exist;
servers from different clusters can't collaborate to serve together the same data (without additional software).
2022-06-09 16:00:14 +00:00
➡️ **Garage is designed to durably store content.**
2022-06-15 17:47:23 +00:00
In this blog post, we will explore whether we can combine both properties by connecting an IPFS node to a Garage cluster.
2022-06-09 16:00:14 +00:00
## Try #1: Vanilla IPFS over Garage
<!--If you are not familiar with IPFS, is available both as a desktop app and a [CLI app ](https://docs.ipfs.io/install/command-line/ ), in this post we will cover the CLI app as it is often easier to understand how things are working internally.
You can quickly follow the official [quick start guide ](https://docs.ipfs.io/how-to/command-line-quick-start/#initialize-the-repository ) to have an up and running node.-->
2022-06-15 17:47:23 +00:00
IPFS is available as a pre-compiled binary, but to connect it with Garage, we need a plugin named [ipfs/go-ds-s3 ](https://github.com/ipfs/go-ds-s3 ).
The Peergos project has a fork because it seems that the plugin is known for hitting Amazon's rate limits
([#105](https://github.com/ipfs/go-ds-s3/issues/105), [#205 ](https://github.com/ipfs/go-ds-s3/pull/205 )).
2022-06-09 16:00:14 +00:00
This is the one we will try in the following.
The easiest solution to use this plugin in IPFS is to bundle it in the main IPFS daemon, and thus recompile IPFS from source.
2022-06-15 17:47:23 +00:00
Following the instructions on the README file allowed me to spawn an IPFS daemon configured with S3 as the block store.
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
I had a small issue when adding the plugin to the `plugin/loader/preload_list` file: the given command lacks a newline.
I had to edit the file manually after running it, the issue was directly visible and easy to fix.
2022-06-09 16:00:14 +00:00
After that, I just ran the daemon and accessed the web interface to upload a photo of my dog:
2022-06-15 17:47:23 +00:00
< center >
2022-06-09 16:00:14 +00:00
![A dog ](./dog.jpg )
2022-06-15 17:47:23 +00:00
< / center >
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
A content identifier (CID) was assigned to this picture:
2022-06-09 16:00:14 +00:00
```
QmNt7NSzyGkJ5K9QzyceDXd18PbLKrMAE93XuSC2487EFn
```
2022-06-15 17:47:23 +00:00
The photo it now accessible on the whole network.
2022-06-09 16:00:14 +00:00
You can inspect it [from the official gateway ](https://explore.ipld.io/#/explore/QmNt7NSzyGkJ5K9QzyceDXd18PbLKrMAE93XuSC2487EFn ) for example:
![A screenshot of the IPFS explorer ](./explorer.png )
At the same time, I was monitoring Garage (through [the OpenTelemetry stack we have implemented earlier this year ](/blog/2022-v0-7-released/ )).
2022-06-15 17:47:23 +00:00
Just after launching the daemon and before doing anything, we had this surprisingly active Grafana plot:
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
< center >
2022-06-09 16:00:14 +00:00
![Grafana API request rate when IPFS is idle ](./idle.png )
2022-06-15 17:47:23 +00:00
< p > *Legend: y axis = requests per 10 seconds, x axis = time*< / p >
< / center >
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
It means that on average, we have around 250 requests per second. Most of these requests are checks that an IPFS block does not exist locally.
These requests are triggered by the DHT service of IPFS: since my node is reachable over the Internet, it acts as a public DHT server and start answering global
block requests over the whole network. Each time it receives a request for a block, it sends a request to its storage back-end to see if it exists
(in our case, to Garage).
2022-06-10 15:25:53 +00:00
*We will try to tweak the IPFS configuration later - we know that we can deactivate the DHT server. For now, we will continue with the default parameters.*
2022-06-15 17:47:23 +00:00
When I start interacting with IPFS by sending a file or browsing the default proposed catalogs (ie. the full XKCD archive),
we hit limits with our monitoring stack which, in its default configuration, is not able to ingest the traces of
so many requests being processed by Garage.
2022-06-09 16:00:14 +00:00
We have the following error in Garage's logs:
```
OpenTelemetry trace error occurred. cannot send span to the batch span processor because the channel is full
```
2022-06-15 17:47:23 +00:00
At this point, I didn't feel that it would be very interesting to fix this issue to see what is exactly the number of requests done on the cluster.
In my opinion, such a simple task of sharing a picture should not require so many requests to the storage server.
As a comparison, this whole webpage, with its pictures, triggers around 10 requests on Garage when loaded, not thousands.
2022-06-09 16:00:14 +00:00
I think we can conclude that this first try was a failure.
2022-06-15 17:47:23 +00:00
The S3 storage plugin for IPFS does too many request and would need some important work to optimize it.
But we should not give up too fast, because the Peergos folks are known to run their software based on IPFS, in production, with an S3 backend.
2022-06-09 16:00:14 +00:00
## Try #2: Peergos over Garage
2022-06-10 15:25:53 +00:00
[Peergos ](https://peergos.org/ ) is designed as an end-to-end encrypted and federated alternative to Nextcloud.
2022-06-15 17:47:23 +00:00
Internally, it is built upon IPFS and is known to have a [deep integration with the S3 API ](https://peergos.org/posts/direct-s3 ).
2022-06-10 15:25:53 +00:00
One important point of this integration is that your browser is able to bypass both the Peergos daemon and the IPFS daemon
2022-06-15 17:47:23 +00:00
to write and read IPFS blocks directly from the S3 API server.
2022-06-10 15:25:53 +00:00
2022-06-15 17:47:23 +00:00
*I don't know exactly if Peergos is still considered as alpha quality, or if a beta version was released,
but keep in mind that it might be more experimental that you would like!*
2022-06-10 15:25:53 +00:00
<!-- To give ourselves some courage in this adventure, let's start with a nice screenshot of their web UI:
![Peergos Web UI ](./peergos.jpg )-->
Starting Peergos on top of Garage required some small patches on both sides,
but in the end, we were able to get it working.
I was able to upload my file, see it in the interface, create a link to share it,
rename it, move it in a folder, and so on:
![A screenshot of the Peergos interface ](./upload.png )
At the same time, the fans of my computer started to become a bit loud.
2022-06-15 17:47:23 +00:00
A quick look at Grafana shows that Garage is still very busy:
2022-06-10 15:25:53 +00:00
2022-06-15 17:47:23 +00:00
< center >
2022-06-10 15:25:53 +00:00
![Screenshot of a grafana plot showing requests per second over time ](./grafa.png )
2022-06-15 17:47:23 +00:00
< p > *Legend: y axis = requests per 10 seconds on log(10) scale, x axis = time*< / p >
< / center >
2022-06-10 15:25:53 +00:00
Again, the workload is dominated by the `HeadObject` requests.
2022-06-15 17:47:23 +00:00
After getting a look at `~/.peergos/.ipfs/config` , it seems that the IPFS configuration used by the Peergos project is quite standard,
which means that, same as before, we are acting as a DHT server and having to answer to thousands of block requests every second.
We also have some traffic on the `GetObject` and `OPTIONS` endpoints (with peaks up to ~45 req/sec).
This traffic is all generated by Peergos.
The `OPTIONS` HTTP verb is here because we use the direct access feature of Peergos,
meaning that our browser is talking directly to Garage and has to use CORS to validate requests for security.
Internally, IPFS splits files in blocks of less than 256 kB. My picture is thus split in 2 blocks, requiring 2 requests over Garage to fetch it.
2022-06-10 15:25:53 +00:00
But even by knowing that IPFS split files in small blocks, I can't explain why we have so much `GetObject` requests.
## Try #3: Optimizing IPFS
<!--
Routing = dhtclient
![](./grafa2.png)
-->
2022-06-15 17:47:23 +00:00
We have seen in our 2 previous tries that the main source of load was the federation, and more especially, the DHT server.
In this section, we want to artificially remove this problem from the equation by preventing our IPFS node from federating
2022-06-10 15:25:53 +00:00
and see what pressure is put by Peergos alone on our local cluster.
To isolate IPFS, we have set its routing type to `none` , we have cleared its bootstrap node list,
and we configured the swarm socket to listen only on localhost.
Finally, we restart Peergos and observe this more peaceful graph:
![Screenshot of a grafana plot showing requests per second over time ](./grafa3.png )
*Legend: y axis = requests per 10 seconds on log(10) scale, x axis = time*
Now, for a given endpoint, we have peaks of around 10 req/sec which is way more reasonable.
2022-06-15 17:47:23 +00:00
Furthermore, we are no longer hammering our back-end with requests on objects that are not there.
2022-06-10 15:25:53 +00:00
2022-06-15 17:47:23 +00:00
After discussing with the developers, it is possible to go even further by running Peergos without IPFS:
2022-06-10 15:58:15 +00:00
this is what they do for some of their tests. At the same time, if you increase the size
2022-06-10 15:59:55 +00:00
of a block, you might have a non-federated but efficient end-to-end encrypted "cloud storage" that works well over Garage,
2022-06-10 15:58:15 +00:00
with your clients directly hitting the S3 API!
2022-06-15 17:47:23 +00:00
If federation is a hard requirement for your setup, the next step would be to gradually allow our node to connect to the IPFS network,
while ensuring that the traffic to the S3 cluster remains low.
For example, configuring our IPFS node as a `dhtclient` instead of `dhtserver` would exempt it from answering public DHT requests.
Keeping an in-memory index (as a hash map and/or Bloom filter) of the blocks stored on the current node
2022-06-10 15:25:53 +00:00
could also drastically reduce the number of requests.
It could also be interesting to explore ways to run in one process a full IPFS node with a DHT
2022-06-15 17:47:23 +00:00
server on the regular file system, and reserve a second process configured with the S3 back-end to handle only our Peergos data.
2022-06-10 15:25:53 +00:00
However, with these optimizations, the best we can expect is the traffic we have on the previous plot.
From a theoretical perspective, it is still higher than the optimal number of requests.
On S3, storing a file, downloading a file, listing available files are all actions that can be done in a single request.
2022-06-15 17:47:23 +00:00
Even if all requests don't have the same cost on the cluster, processing a request has a non-negligible fixed cost.
2022-06-10 15:25:53 +00:00
## S3 and IPFS are incompatible?
*Text by Alex*
## Conclusion
2022-06-15 17:47:23 +00:00
Running IPFS over an S3 storage back-end does not quite work out of the box in term of performances in the current state of affairs.
2022-06-10 15:49:02 +00:00
We have identified that the main problem is linked with the DHT service,
2022-06-15 17:47:23 +00:00
and proposed some improvements (disabling the DHT server, keeping an in-memory index of the blocks, using the S3 back-end only for your data).
2022-06-10 15:25:53 +00:00
2022-06-10 15:58:15 +00:00
It is possible to modify Peergos to make it work without IPFS. With some optimization on the block size,
you might have a great proof of concept of an end-to-end encrypted "cloud storage" over Garage.
2022-06-15 17:47:23 +00:00
*If you happen to be working on this, please inform us!*
2022-06-10 15:58:15 +00:00
From an IPFS design perspective, it seems however that the numerous small blocks handled by the protocol
2022-06-10 15:25:53 +00:00
do not map trivially to efficient S3 requests, and thus could be a limiting factor to any optimization work.
2022-06-10 15:49:02 +00:00
As part of our test journey, we also read some posts about performance issues on IPFS (eg. [#6283 ](https://github.com/ipfs/go-ipfs/issues/6283 )) that are not
2022-06-10 15:25:53 +00:00
linked with the S3 connector. We might be negatively influenced by our failure to connect IPFS with S3,
2022-06-15 17:47:23 +00:00
but we are tempted to think that IPFS is intrinsically resource-intensive.
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
On our side, we will continue our investigations towards more *minimalistic* software.
2022-06-10 15:25:53 +00:00
This choice makes sense for us as we want to reduce the ecological impact of our services
2022-06-10 15:49:02 +00:00
by deploying less servers, that use less energy, and that are renewed less frequently.
2022-06-09 16:00:14 +00:00
2022-06-15 17:47:23 +00:00
*We are aware of the existence of many other software projects for file sharing
such as Nextcloud, Owncloud, Owncloud Infinite Scale, Seafile, Filestash, Pydio, SOLID, Remote Storage, etc.
Many of these could be connected to an S3 back-end such as Garage.
We might even try some of them in future blog posts, so stay tuned!*