summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-10-15 20:53:20 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:21:03 -0500
commit3433468e12e6ecbe849a377a65bd2baaf5415b72 (patch)
treead29c75784ccab730c54a1f5d058a36b799c7ca7
parent518666fde197110cdcc2702168d55e787e0e89d9 (diff)
downloadsamba-3433468e12e6ecbe849a377a65bd2baaf5415b72.tar.gz
samba-3433468e12e6ecbe849a377a65bd2baaf5415b72.tar.bz2
samba-3433468e12e6ecbe849a377a65bd2baaf5415b72.zip
r19294: a little speed tester for ldb/tdb
I wrote this to see if using a ldb for idmap store (the equivalent of winbindd_idmap.tdb) makes sense. It's a long lived database that administrators may wish to edit, so ldb makes sense, but at the moment ldb is too slow. This test will help us speed it up. (This used to be commit 10f8260455a55530f5701a136af8fa8b05ca8532)
-rw-r--r--source4/torture/local/config.mk1
-rw-r--r--source4/torture/local/dbspeed.c250
-rw-r--r--source4/torture/local/local.c1
3 files changed, 252 insertions, 0 deletions
diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk
index fb3eb2c6ad..c9494039e0 100644
--- a/source4/torture/local/config.mk
+++ b/source4/torture/local/config.mk
@@ -28,6 +28,7 @@ OBJ_FILES = \
ndr.o \
event.o \
local.o \
+ dbspeed.o \
torture.o
PUBLIC_DEPENDENCIES = \
RPC_NDR_ECHO \
diff --git a/source4/torture/local/dbspeed.c b/source4/torture/local/dbspeed.c
new file mode 100644
index 0000000000..10620440ce
--- /dev/null
+++ b/source4/torture/local/dbspeed.c
@@ -0,0 +1,250 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local test for tdb/ldb speed
+
+ Copyright (C) Andrew Tridgell 2004
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include "includes.h"
+#include "system/filesys.h"
+#include "lib/tdb/include/tdb.h"
+#include "lib/ldb/include/ldb.h"
+#include "lib/ldb/include/ldb_errors.h"
+#include "lib/db_wrap.h"
+#include "torture/torture.h"
+
+
+static BOOL tdb_add_record(struct tdb_wrap *tdbw, const char *fmt1, const char *fmt2, int i)
+{
+ TDB_DATA key, data;
+ int ret;
+ key.dptr = (uint8_t *)talloc_asprintf(tdbw, fmt1, i);
+ key.dsize = strlen((char *)key.dptr)+1;
+ data.dptr = (uint8_t *)talloc_asprintf(tdbw, fmt2, i+10000);
+ data.dsize = strlen((char *)data.dptr)+1;
+
+ ret = tdb_store(tdbw->tdb, key, data, TDB_INSERT);
+
+ talloc_free(key.dptr);
+ talloc_free(data.dptr);
+ return ret == 0;
+}
+
+/*
+ test tdb speed
+*/
+static BOOL test_tdb_speed(struct torture_context *torture, const void *_data)
+{
+ struct timeval tv;
+ struct tdb_wrap *tdbw;
+ int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
+ int i, count;
+ TALLOC_CTX *tmp_ctx = talloc_new(torture);
+
+ unlink("test.tdb");
+
+ torture_comment(torture, "Testing tdb speed for sidmap");
+
+ tdbw = tdb_wrap_open(tmp_ctx, "test.tdb",
+ 10000, 0, O_RDWR|O_CREAT|O_TRUNC, 0600);
+ if (!tdbw) {
+ torture_fail(torture, "Failed to open test.tdb");
+ goto failed;
+ }
+
+ torture_comment(torture, "Adding %d SID records", torture_entries);
+
+ for (i=0;i<torture_entries;i++) {
+ if (!tdb_add_record(tdbw,
+ "S-1-5-21-53173311-3623041448-2049097239-%u",
+ "UID %u", i)) {
+ torture_fail(torture, "Failed to add SID %d", i);
+ goto failed;
+ }
+ if (!tdb_add_record(tdbw,
+ "UID %u",
+ "S-1-5-21-53173311-3623041448-2049097239-%u", i)) {
+ torture_fail(torture, "Failed to add UID %d", i);
+ goto failed;
+ }
+ }
+
+ torture_comment(torture, "Testing for %d seconds", timelimit);
+
+ tv = timeval_current();
+
+ for (count=0;timeval_elapsed(&tv) < timelimit;count++) {
+ TDB_DATA key, data;
+ i = random() % torture_entries;
+ key.dptr = (uint8_t *)talloc_asprintf(tmp_ctx, "S-1-5-21-53173311-3623041448-2049097239-%u", i);
+ key.dsize = strlen((char *)key.dptr)+1;
+ data = tdb_fetch(tdbw->tdb, key);
+ if (data.dptr == NULL) {
+ torture_fail(torture, "Failed to fetch SID %d", i);
+ goto failed;
+ }
+ free(data.dptr);
+ key.dptr = (uint8_t *)talloc_asprintf(tmp_ctx, "UID %u", i);
+ key.dsize = strlen((char *)key.dptr)+1;
+ data = tdb_fetch(tdbw->tdb, key);
+ if (data.dptr == NULL) {
+ torture_fail(torture, "Failed to fetch UID %d", i);
+ goto failed;
+ }
+ free(data.dptr);
+ }
+
+ torture_comment(torture, "tdb speed %.2f ops/sec", count/timeval_elapsed(&tv));
+
+
+ unlink("test.tdb");
+ talloc_free(tmp_ctx);
+ return True;
+
+failed:
+ unlink("test.tdb");
+ talloc_free(tmp_ctx);
+ return False;
+}
+
+
+static BOOL ldb_add_record(struct ldb_context *ldb, unsigned rid)
+{
+ struct ldb_message *msg;
+ int ret;
+
+ msg = ldb_msg_new(ldb);
+ if (msg == NULL) {
+ return False;
+ }
+
+ msg->dn = ldb_dn_string_compose(msg, NULL, "SID=S-1-5-21-53173311-3623041448-2049097239-%u",
+ rid);
+ if (msg->dn == NULL) {
+ return False;
+ }
+
+ if (ldb_msg_add_fmt(msg, "UID", "%u", rid) != 0) {
+ return False;
+ }
+
+ ret = ldb_add(ldb, msg);
+
+ talloc_free(msg);
+
+ return ret == LDB_SUCCESS;
+}
+
+
+/*
+ test ldb speed
+*/
+static BOOL test_ldb_speed(struct torture_context *torture, const void *_data)
+{
+ struct timeval tv;
+ struct ldb_context *ldb;
+ int timelimit = lp_parm_int(-1, "torture", "timelimit", 10);
+ int i, count;
+ TALLOC_CTX *tmp_ctx = talloc_new(torture);
+ struct ldb_ldif *ldif;
+ const char *init_ldif = "dn: @INDEXLIST\n" \
+ "@IDXATTR: UID\n";
+
+ unlink("./test.ldb");
+
+ torture_comment(torture, "Testing ldb speed for sidmap");
+
+ ldb = ldb_wrap_connect(tmp_ctx, "tdb://test.ldb",
+ NULL, NULL, LDB_FLG_NOSYNC, NULL);
+ if (!ldb) {
+ torture_fail(torture, "Failed to open test.ldb");
+ goto failed;
+ }
+
+ /* add an index */
+ ldif = ldb_ldif_read_string(ldb, &init_ldif);
+ if (ldif == NULL) goto failed;
+ if (ldb_add(ldb, ldif->msg) != LDB_SUCCESS) goto failed;
+ talloc_free(ldif);
+
+ torture_comment(torture, "Adding %d SID records", torture_entries);
+
+ for (i=0;i<torture_entries;i++) {
+ if (!ldb_add_record(ldb, i)) {
+ torture_fail(torture, "Failed to add SID %d", i);
+ goto failed;
+ }
+ }
+
+ if (talloc_total_blocks(torture) > 100) {
+ torture_fail(torture, "memory leak in ldb add");
+ goto failed;
+ }
+
+ torture_comment(torture, "Testing for %d seconds", timelimit);
+
+ tv = timeval_current();
+
+ for (count=0;timeval_elapsed(&tv) < timelimit;count++) {
+ struct ldb_dn *dn;
+ struct ldb_result *res;
+ char *expr;
+
+ i = random() % torture_entries;
+ dn = ldb_dn_string_compose(tmp_ctx, NULL, "SID=S-1-5-21-53173311-3623041448-2049097239-%u",
+ i);
+ if (ldb_search(ldb, dn, LDB_SCOPE_BASE, NULL, NULL, &res) != LDB_SUCCESS ||
+ res->count != 1) {
+ torture_fail(torture, "Failed to find SID %d", i);
+ }
+ talloc_free(res);
+ talloc_free(dn);
+ expr = talloc_asprintf(tmp_ctx, "(UID=%u)", i);
+ if (ldb_search(ldb, NULL, LDB_SCOPE_SUBTREE, expr, NULL, &res) != LDB_SUCCESS ||
+ res->count != 1) {
+ torture_fail(torture, "Failed to find UID %d", i);
+ }
+ talloc_free(res);
+ talloc_free(expr);
+ }
+
+ if (talloc_total_blocks(torture) > 100) {
+ torture_fail(torture, "memory leak in ldb search");
+ goto failed;
+ }
+
+ torture_comment(torture, "ldb speed %.2f ops/sec", count/timeval_elapsed(&tv));
+
+
+ unlink("./test.ldb");
+ talloc_free(tmp_ctx);
+ return True;
+
+failed:
+ unlink("./test.ldb");
+ talloc_free(tmp_ctx);
+ return False;
+}
+
+struct torture_suite *torture_local_dbspeed(TALLOC_CTX *mem_ctx)
+{
+ struct torture_suite *s = torture_suite_create(mem_ctx, "LOCAL-DBSPEED");
+ torture_suite_add_simple_tcase(s, "tdb_speed", test_tdb_speed, NULL);
+ torture_suite_add_simple_tcase(s, "ldb_speed", test_ldb_speed, NULL);
+ return s;
+}
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index ef9c3a91ff..4a6c43761a 100644
--- a/source4/torture/local/local.c
+++ b/source4/torture/local/local.c
@@ -42,6 +42,7 @@
torture_local_ndr,
torture_local_event,
torture_local_torture,
+ torture_local_dbspeed,
NULL
};