Bug 15590 - libldb: peformance issue with indexes
Summary: libldb: peformance issue with indexes
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: AD: LDB/DSDB/SAMDB (show other bugs)
Version: 4.19.5
Hardware: All All
: P5 normal with 15 votes (vote)
Target Milestone: ---
Assignee: Andrew Bartlett
QA Contact: Samba QA Contact
Depends on:
Reported: 2024-02-22 14:16 UTC by Andreas Schneider
Modified: 2024-03-07 09:58 UTC (History)
3 users (show)

See Also:

repro.sh (1.59 KB, text/plain)
2024-02-22 14:17 UTC, Andreas Schneider
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Schneider 2024-02-22 14:16:06 UTC

my colleagues found a performance issue with current libldb.

Fedora 39:
$ rpm -q ldb-tools

$ bash repro.sh 30000
Added 30000 records successfully

real    0m0.534s
user    0m0.931s
sys     0m0.062s

$ bash repro.sh 10000 indexes
Added 2 records successfully
Added 10000 records successfully

real    0m16.232s
user    0m16.122s
sys     0m0.238s

$ bash repro.sh 20000 indexes
Added 2 records successfully
Added 20000 records successfully

real    1m32.052s
user    1m30.924s
sys     0m1.235s

CentOS7 (container from out CI):
[samba@57da0cb767c4 ~]$ rpm -qf /usr/bin/ldbadd

[samba@57da0cb767c4 ~]$ bash repro.sh 20000 indexes
Added 2 records successfully
Added 20000 records successfully

real    0m0.871s
user    0m1.231s
sys     0m0.140s
Comment 1 Andreas Schneider 2024-02-22 14:17:00 UTC
Created attachment 18258 [details]
Comment 2 Andrew Bartlett 2024-02-29 21:42:30 UTC
Can you bisect down to find the exact revision this fails on?

Also can you confirm both in as close to similar environments, eg both in docker, so we can rule out a change around fsync() etc?

Also note that the transaction behaviour for ldbadd is about the worst possible, it will open and close a transaction for each LDIF chuck individually.
Comment 3 Andreas Schneider 2024-03-01 10:11:00 UTC
I've bisected it on registry.gitlab.com/samba-team/devel/samba/samba-ci-centos8s:9a406973474a7903fe7fd6215226660911ed73c0

b6b5b5fe355fee2a4096e9214831cb88c7a2a4c6 is the first bad commit
commit b6b5b5fe355fee2a4096e9214831cb88c7a2a4c6
Author: Gary Lockyer <gary@catalyst.net.nz>
Date:   Wed Mar 6 15:28:45 2019 +1300

    lib ldb key value: fix index buffering

    As a performance enhancement the key value layer maintains a cache of
    the index records, which is written to disk as part of a prepare commit.
    This patch adds an extra cache at the operation layer to ensure that the
    cached indexes remain consistent in the event of an operation failing.

    Add test to test for index corruption in a failed modify.

    Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet@samba.org>
    Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
    Signed-off-by: Andrew Bartlett <abartlet@samba.org>

 lib/ldb/ldb_key_value/ldb_kv.c       |  22 ---
 lib/ldb/ldb_key_value/ldb_kv.h       |  12 ++
 lib/ldb/ldb_key_value/ldb_kv_index.c | 347 ++++++++++++++++++++++++++++++++---
 lib/ldb/tests/python/api.py          |  82 ++++++++-
 4 files changed, 415 insertions(+), 48 deletions(-)