Open polkovnikov opened 3 years ago
Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:
Finally, remember to use https://discuss.ipfs.io if you just need general support.
Checklist
Installation method
ipfs-update or dist.ipfs.io
Version
Config
Description
I tried to do one exotic thing - to open IPFS hosted English wikipedia (as
.zim
file) in Kiwix application on Linux (Kiwix was installed throughsudo apt install kiwix
).And it appeared a really-really slow CPU-bound process.
I mounted file system
/ipfs
and/ipns
using commandipfs daemon --mount
.ZIM (Kiwix) file is located here
/ipns/en.wikipedia-on-ipfs.org/wikipedia_en_all_maxi_2021-02.zim
and is83 GB
in size.It is known that Kiwix reads into memory only small part of file, search index and meta data. And probably Kiwix does a lot of small random file reads when parsing metadata.
I guess probably this is the cause of very high CPU usage - I think IPFS mounted file system (
/ipns
) is not optimized for small random reads and causes high CPU usage for such things.I see following behavior when I open webui on my localhost - first IPFS tries to download requested blocks and download speed is quite alright, around
1 MByte/sec
, this lasts for 1 minute or so. Then follows a quite long (about 5-10 minutes) period of no download (around 0 speed) but with very high CPU usage for ipfs daemon which can be seen inhtop
. All 4 CPU cores (8 hardware threads) of ipfs daemon use 95-100% of core. Then again 1 minute of download and again 5-10 minutes of high CPU usage.This switching between 1 minute of download and 5-10 minutes of high CPU usage repeats for around 6-8 times. Finally after 1 hour Kiwix opens Wikipedia successfully. At this point webui shows around
1 GByte
of blocks occupied by Wikipedia cached parts.Just to note, I didn't do
ipfs pin add ...
for this file, and I didn't planned to, I wanted to browse distributed remote copy in Kiwix without occupying too much space, 1 GB cache in local IPFS is alright, but not whole 83 GB file.If I open any article like
Book
then again a minute of download and few minutes of high CPU usage and article is opened correctly after that with all pictures shown.To solve similar issues I'll suggest that following can be implemented - if any program tries to read few bytes of data from file at random point then file system code should read from IPFS node
1 MByte
instead (aligned) and cache this 1MB in RAM. If again program reads another few bytes within this 1MB block then RAM cache should return those few bytes immediately from cached 1MB, without even contacting any IPFS node infrastructure. If limited RAM cache is full then oldest (or least accessed) 1MB blocks should be removed from RAM.This suggested 1MB caching tecnique of cause should be tweakable by IPFS config, one can tweak cache size limit and also block size (this 1MB in my example).
I can guess that right now when any small few bytes read is issued to mounted file system then this read request goes through heavy architecture of IPFS node, finds corresponding block, reads small part of it and returns to user, without any in-RAM fast caching. Am I right? Or something else can be causing high CPU usage?