IPFS Daily Optimization Guide

Original link: https://zu1k.com/posts/tutorials/p2p/ipfs-easy-use/

ipfs-logo.png

In the past two days, Livid, the webmaster of V2EX, released a content publishing and subscription application [Planet] based on IPFS and ENS. The idea was mentioned in the previous [Podcast Interview] , and I thought it was very interesting at first. As I expected, Planet attracted a lot of attention once it was released. Planet uses a graphical method to allow more ordinary people to try distributed content publishing such as IPFS. It is said that a comment function will be added later. This is in the IPFS network. It is also a big challenge. I don’t know what level of ease of use Planet can achieve. I will continue to pay attention.

I also understood and started to use IPFS technology a long time ago, and I have accumulated some experience in the process of tossing. Below I will share some tips with you to make your IPFS easier to use.

Complete novice friends, please read the article “IPFS Novice Guide” written by me in 20 years

Build a gateway

Compared with using a public IPFS gateway, I recommend building it at home, which not only provides a better experience, but also avoids the trouble of installing IPFS on each computer.

After installing IPFS on the server according to the normal tutorial, you need to modify the configuration file to open Api and Gateway to the outside world.

Because it is in a home network, I will not introduce additional access control configuration. If you are building on a public network server, you need to pay attention to configuring access control to avoid abuse.

Modify the IP binding between the API and the Gateway to 0.0.0.0 to open to the local area network, and then modify the http header of the API to configure cross-domain:

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
 "API" : { "HTTPHeaders" : { "Access-Control-Allow-Headers" : [ "X-Requested-With" , "Range" , "User-Agent" ], "Access-Control-Allow-Methods" : [ "GET" , "POST" , "OPTIONS" ], "Access-Control-Allow-Origin" : [ "*" ] } }

Configure the subdomain gateway to achieve the effect of dweb.link . For example, to use *.ipfs.zu1k.com as the subdomain gateway, you must first resolve the generic domain name to the IP of the IPFS gateway, and then add the following to the Gateway configuration:

 1 2 3 4 5 6 7 8 9 10 11 12 13
 "Gateway" : { "PublicGateways" : { "ipfs.zu1k.com" : { "NoDNSLink" : false , "Paths" : [ "/ipfs" , "/ipns" , "/api" ], "UseSubdomains" : true } }, }

In order to get a better IPFS experience, it is recommended to install[IPFS browser plug-in] , or use the Brave browser, which can make the IPFS experience more native.

Pin optimization

Immediately after the content is published, access through the public IPFS gateway is usually very slow, and even cannot be accessed until the timeout is reached, which is caused by the addressing process of IPFS. As more and more users access the content, their IPFS nodes will cache the data of your content. At this time, when new nodes access the same content, it will usually be very fast. This is the characteristic of IPFS, which is similar to the principle of BT download. The more copies of data exist in the network, the better the performance of the P2P network can be utilized.

However, an IPFS node will not cache your data indefinitely. By default, the GC frequency is once an hour, which means that if your data is not accessed by users, it will be cleaned up from their nodes after an hour. Lose. In order to keep our data in the IPFS network for a long time, users need to pin your data to prevent it from being GCed. My approach is to use idle servers to build IPFS nodes to pin their own data, and then friends to pin each other, which is a win-win cooperation.

So you may as well Pin my blog: ipfs pin add /ipns/zu1k.com

If you use IPNS or domain name to expose frequently modified content to the outside world, you need to set up timed tasks to keep pinning new data, because IPFS will only Pin the CID corresponding to the current state when Pinning an IPNS, and will not use it later. to update.

Remote Pinning Service

If you don’t want to run the local IPFS node all the time, but want others to access the content you publish, you can consider using the Remote Pinning service, which is a content Pinning service provided by some centralized service providers, and its effect is similar to yours The native pin is equivalent. Even because of their better network quality and more connected nodes, Pin content on their nodes can be distributed and accessed faster.

I mainly recommend two, [Pinata] and [web3.storage] . For specific tutorials, see the official documentation

 1 2 3
 # ipfs pin remote service ls Pinata https://api.pinata.cloud/psa web3_storage https://api.web3.storage

Pinata is no threshold and provides 1G of Pin capacity for free.

web3.storage provides 1T for free, but Pin Api needs to send an email to apply, and there will be a reply within one day. [Tutorial]

open port

Because IPFS requires P2P communication, if you do not have an IPFS node on the public network to Pin your content, you need to ensure that your local IPFS node can be accessed. Check your router, enable UPnP, create port mapping if necessary, and open your 4001 port (if not modified).

Resource Occupancy Optimization

If you don’t do any configuration optimization, just follow the normal process to download, install and run, you will find that IPFS will take up a lot of CPU resources and memory in the background, your fan will start to spin wildly; maintain a large number of network connections, causing your network Stuck and stopped. This is because the default configuration of IPFS is not optimized for small personal hosts. If you are running on a 2-core Linux server, IPFS can even eat up all your CPU, and the congestion of the network may cause you to log in with ssh. became a problem.

At this time, we need to adjust the parameters in the configuration file to find a way to reduce resource usage, so that IPFS does not affect our daily work. In fact, IPFS has provided several configuration files . You can view the specific introduction through ipfs config profile --help .

I don’t know how to translate the profile properly, and the translation into a file is not very accurate. The application of these profiles in ipfs only modifies some specific options, not a complete change of the configuration file.

I recommend applying lowpower configuration on low-config servers and personal computers, ipfs config profile apply lowpower , this will limit the number of connections IPFS maintains, reduce network usage, and reduce GC frequency, which can significantly reduce cpu usage, my The test can reduce the cpu usage from over 80% to under 20%. Of course, the reduction of resource occupation will also lead to the reduction of communication efficiency, which will increase the content addressing time and affect the user experience. If your usage is similar to RSS feeds and offline viewing, the increased addressing time can be ignored.

If you are running IPFS on a server with a public IP, it is also recommended to apply the server configuration, ipfs config profile apply server , which will turn off node discovery on the local network, because it is meaningless, and it can also reduce network usage.

afterword

At the end of November 2020, I published the article “New Guide to IPFS” , expecting IPFS to develop rapidly and become the next-generation web infrastructure. Unconsciously, it has been a year and a half. From the current situation, although IPFS is still developing, it is still in a state of half-dead, which makes me very disappointed.

But when you think about it, it is unreasonable to expect a technology to become the next mainstream. Any technology should only be able to grow into a widely used mainstream under a wide range of needs, rather than saying that if you have some good features, it must be widely accepted. In terms of demand, we really need P2P-based content publishing and content-based addressing, which have very good advantages, but cannot meet all our needs for the Internet. While we expect the content to be immutable and the content not to be deleted, we also hope to have the right to delete or modify a certain content; we like the decentralized content distribution method of P2P, but we cannot deny that anyone wants lower latency, Faster; we also want more control over the content, including fine-grained access controls, more flexible expressions…

Based on the above ideas, I don’t think IPFS is the next generation of Web, which is Web3. But I don’t deny that IPFS has huge potential to play a very important role in the next generation of Web, but this role is not all. The content distribution method based on P2P is not a new technology for a long time. BitTorrent and BtSync and BTFS based on BT technology are also very competitive. If IPFS wants to compete with it, it needs to work harder to make it easier to use and more popular.

I myself have been using IPFS for nearly two years. In the past two years, my own feeling is that IPFS itself has not had much breakthrough development, and various marketing and bluffing activities have emerged around it, such as file mining, NFT, etc. Wait, but these have indeed made more people pay attention to IPFS, and contributed a lot of nodes and storage space to the IPFS network, but I always feel strange, this is not the long-term way of development.

However, in recent years, the Internet has become more and more closed, and content censorship has become more and more strict. Presumably, distributed content publishing methods such as IPFS will attract more attention from non-technical people. It is expected that at this juncture of surge in demand, more excellent applications will emerge. IPFS It is rolled out so that more ordinary people can use these new technologies more conveniently and enjoy the rights brought by new technologies, those rights that we should have but have been deprived of.

This article is reprinted from: https://zu1k.com/posts/tutorials/p2p/ipfs-easy-use/
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment