This is an old revision of the document!
Kraken2: Efficient Multi-Sample Classification
Problem and solution
By default, kraken2 loads its database into process-local RAM for every invocation, which requires substantial amount of time. Repeating this for many samples (*mhm* especially with the better db - Pracken (>400 GB)) the time to classify samples explodes, just because of repeated db-loading from scratch.
Use –memory-mapping to access the database through file-backed memory mapping instead of copying the entire index into each process's RAM. The operating system can reuse cached database pages between samples1), reducing repeated loading overhead.
e.g.
kraken2 \ --db /mnt/nas1/db/kraken/pracken_20260708/ \ --paired \ --gzip-compressed \ --threads 8 \ --confidence 0.1 \ --use-names \ --memory-mapping \ --report sample_report.txt \ --output sample_output.txt \ sample_R1.fastq.gz sample_R2.fastq.gz
Example Kraken2 Script:
References:
- Official Kraken2 manual — explains what
–memory-mappingdoes. - GitHub issue #719 — discusses the ability to load db only once for multiple samples.
- GitHub issue #451 — discusses memory mapping and I/O performance.
1)
This does not keep a Kraken2 process or mapping alive between runs. Benefits depend on cache availability and disk speed. On slow or network storage, random disk I/O may make classification slower.
