Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Badger datastore performance with English snapshot #85

Open
lidel opened this issue Feb 22, 2021 · 9 comments
Open

Badger datastore performance with English snapshot #85

lidel opened this issue Feb 22, 2021 · 9 comments
Labels
dif/expert Extensive knowledge (implications, ramifications) required effort/weeks Estimated to take multiple weeks kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding P1 High: Likely tackled by core team if no one steps up snapshots issues related to snapshot creation and updates

Comments

@lidel
Copy link
Member

lidel commented Feb 22, 2021

badger shows consistent issues in go-ipfs 0.8.0 with 300GB of wikipedia_en_all_maxi_2021-02

Issues

  • oom-killer stopped the process at 30%, then 60%
    • unable to open resulting repo with 32GB of RAM (churns until oom-killer kicks in)
    • unable to open when RAM limited to 20G, errors after ~30s:
      $ firejail --noprofile --rlimit-as=20000000000 ipfs daemon
      Error: Opening table: "/media/1tb/projects/wikipedia/ipfs-repo/en/badgerds/189654.sst": Unable to map file: "189654.sst": cannot allocate memory

How to reproduce

Reproduction of relevant import steps:

  1. go-ipfs 0.8.0 from https://dist.ipfs.io/#go-ipfs
  2. zimdump from https://download.openzim.org/nightly/2021-02-12/zim-tools_linux-x86_64-2021-02-12.tar.gz
  3. download wikipedia_en_all_maxi_2021-02.zim (~80GB)
  4. unpack ZIM (requires ~300GB, ~20 000 000 files)
$ zimdump dump --dir=wikipedia_en_all_maxi_2021-02 wikipedia_en_all_maxi_2021-02.zim
  1. Add unpacked archive to a fresh ipfs repo with badger backend:
$ ipfs init -p badgerds --empty-repo
$ ipfs config --json 'Experimental.ShardingEnabled' true
$ ipfs add -r --cid-version 1 --pin=false --offline -Qp ./wikipedia_en_all_maxi_2021-02/

Would be useful if someone reproduced the memory issue so we know its not specific to my box.

Things to try

@lidel lidel added kind/bug A bug in existing code (including security flaws) dif/expert Extensive knowledge (implications, ramifications) required P1 High: Likely tackled by core team if no one steps up snapshots issues related to snapshot creation and updates need/analysis Needs further analysis before proceeding effort/weeks Estimated to take multiple weeks labels Feb 22, 2021
@BigLep
Copy link

BigLep commented Feb 22, 2021

@lidel : can/should we add a regression test for this so we don't do releases that fail for this usecase?

@lidel
Copy link
Member Author

lidel commented Feb 22, 2021

@BigLep ideally, yes, but I'd say it is not feasible at this stage:

  • badgerv1 datastore is not the default in go-ipfs (flatfs is)
    • there is badgerv2
    • in general, badger in go-ipfs needs some work. in the end, we may end up not switching default to badger2/3 due to issues like this (and other ones in v2, found out by Lotus team)
  • running this type of import test requires expensive CI setup – I'd rather have us testing default than opt-in features first (and we don't have any tests like this running on CI for flatfs datastore)

@lidel
Copy link
Member Author

lidel commented Feb 25, 2021

For the record, I switched to flatfs with sync set to false and ipfs add in offline mode finished under 5h, which is still acceptable given no memory issues, no ridiculous CPU load. I'll be switching README and scripts to use that instead of badger.

lidel added a commit that referenced this issue Feb 26, 2021
@lidel
Copy link
Member Author

lidel commented Mar 17, 2021

Another badger issue: ipfs/go-ds-badger#111 (panic: slice bounds out of range)

@lidel
Copy link
Member Author

lidel commented Mar 28, 2021

The panic turned out to be a broken datastore (went away after re-generating).

New/old issue tho:
I was unable to pin this English snapshot from #92 to a second localhost node running badger.
32GB of RAM was not enough for this, ipfs daemon doing the pinning gets killed (same issue as I originally had during ipfs add). Will try to pin it elsewhere to see if the issue with badger can be reproduced outside my box.

I will also try to retry with MaxTableSize set to 64MB (go-ipfs uses 16MB to allocate less memory up front)

@lidel
Copy link
Member Author

lidel commented Mar 29, 2021

Tried finishing pinning English with go-ds-badger patched with:

--- a/datastore.go
+++ b/datastore.go
@@ -107,13 +107,13 @@ func init() {
        DefaultOptions.Options.ValueLogLoadingMode = options.FileIO
 
        // Explicitly set this to mmap. This doesn't use much memory anyways.
-       DefaultOptions.Options.TableLoadingMode = options.MemoryMap
+       DefaultOptions.Options.TableLoadingMode = options.FileIO
 
        // Reduce this from 64MiB to 16MiB. That means badger will hold on to
        // 20MiB by default instead of 80MiB.
        //
        // This does not appear to have a significant performance hit.
-       DefaultOptions.Options.MaxTableSize = 16 << 20
+       DefaultOptions.Options.MaxTableSize = 64 << 20
 }

Helped a bit, but crashed again after 9h (memory limited to 20GB).
I'll retry with empty repo just to be sure it is not due to left-overs created with old values.

This most likely could be solved by throwing enough RAM at nodes pinning the data, but pinning an existing Wikipedia snapshot should work on a consumer-grade PC.

@lidel
Copy link
Member Author

lidel commented Mar 30, 2021

No luck. Next step is to backport this fix for ipfs/go-ds-badger#86 and build go-ds-badger against patched badger. nevermind.

Ended up using flatfs with sync set tofalse. Takes time, but can finish on desktop hardware without balooning RAM usage.

@alzinging
Copy link

is this project using the Zim dumps rather than Wikimedias internal MWDumper.pl and related XML to MySQL import processes? I successfully got a working database from this process, and prefer not having to have another middle man in the dump and sync process ... ideally we would speed-improve the daily dump sync and automate it ... that's what Wikipedia is asking for.

We should have this thing "live and usable" and always current.

9546678083 if you can or need help.

@kelson42
Copy link

kelson42 commented Dec 15, 2022

@alzinging We were doing like this 15 years ago... wish you good luck with this approach ;) Your comment is anyway pretty out of topic in this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dif/expert Extensive knowledge (implications, ramifications) required effort/weeks Estimated to take multiple weeks kind/bug A bug in existing code (including security flaws) need/analysis Needs further analysis before proceeding P1 High: Likely tackled by core team if no one steps up snapshots issues related to snapshot creation and updates
Projects
None yet
Development

No branches or pull requests

4 participants