summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2020-03-17 06:41:40 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2020-03-17 06:41:40 (GMT)
commitc206691cd621378a03ba4c255699b14b2cef82d6 (patch) (side-by-side diff)
treec512d68569d82844ebd69dca1bbd8302884cb313
parent0cdf95fd770c59a018a4018e49aa777d3ed34e45 (diff)
downloadcache-benchmarks-c206691cd621378a03ba4c255699b14b2cef82d6.tar.gz
cache-benchmarks-c206691cd621378a03ba4c255699b14b2cef82d6.tar.bz2
Improve fetchkeys
The new option -b instructs it to fetch only the bucket for each given key without fetching the actual value, thus eliminating the imact of non-cached reads. * src/benchmark.mk.in: Pass FETCHKEYSOPT to fetchkeys. * src/fetchkeys.c: New option -b: read the bucket, don't fetch value
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--src/benchmark.mk.in2
-rw-r--r--src/fetchkeys.c49
2 files changed, 38 insertions, 13 deletions
diff --git a/src/benchmark.mk.in b/src/benchmark.mk.in
index 5e02f11..43c605c 100644
--- a/src/benchmark.mk.in
+++ b/src/benchmark.mk.in
@@ -30,7 +30,7 @@ test: master.log newcache.log
-e 's/\.$$//' \
-e 'p}') + 100))} \
--log-file=$*.log \
- $(abs_top_builddir)/src/$*/fetchkeys
+ $(abs_top_builddir)/src/$*/fetchkeys $(FETCHKEYSOPT)
clean:
rm -f master.log newcache.log
allclean: clean
diff --git a/src/fetchkeys.c b/src/fetchkeys.c
index 32f0199..a655a0d 100644
--- a/src/fetchkeys.c
+++ b/src/fetchkeys.c
@@ -9,6 +9,7 @@
#include <assert.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include "gdbmdefs.h"
static unsigned long
get_size (char const *str)
@@ -185,11 +186,16 @@ main (int argc, char **argv)
int flags = 0;
struct timeval t_start, t_open, t_now, td;
char *keystr;
+ int b_opt = 0;
- while ((i = getopt (argc, argv, "c:t:nTpv")) != EOF)
+ while ((i = getopt (argc, argv, "bc:t:nTpv")) != EOF)
{
switch (i)
{
+ case 'b':
+ b_opt = 1;
+ break;
+
case 'n':
flags |= GDBM_NOMMAP;
break;
@@ -279,24 +285,43 @@ main (int argc, char **argv)
key.dptr = keystr;
key.dsize = strlen (key.dptr);
- data = gdbm_fetch (dbf, key);
- if (data.dptr == NULL)
+ if (b_opt)
+ {
+ int new_hash_val; /* Computed hash value for the key */
+ int bucket_dir; /* Number of the bucket in directory. */
+ int elem_loc; /* The location in the bucket. */
+ _gdbm_hash_key (dbf, key, &new_hash_val, &bucket_dir, &elem_loc);
+ if (_gdbm_get_bucket (dbf, bucket_dir))
+ {
+ status = 2;
+ fprintf (stderr, "%s: error: %s\n", keystr,
+ gdbm_strerror (gdbm_errno));
+ }
+ }
+ else
{
- status = 2;
- if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+ data = gdbm_fetch (dbf, key);
+ if (data.dptr == NULL)
{
- fprintf (stderr, "%s: not found\n", keystr);
+ status = 2;
+ if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+ {
+ fprintf (stderr, "%s: not found\n", keystr);
+ }
+ else
+ {
+ fprintf (stderr, "%s: error: %s\n", keystr,
+ gdbm_strerror (gdbm_errno));
+ }
}
else
{
- fprintf (stderr, "%s: error: %s\n", keystr,
- gdbm_strerror (gdbm_errno));
+ if (print)
+ printf ("%s: %*.*s\n", keystr,
+ data.dsize, data.dsize, data.dptr);
+ free (data.dptr);
}
- continue;
}
- if (print)
- printf ("%s: %*.*s\n", keystr, data.dsize, data.dsize, data.dptr);
- free (data.dptr);
}
gdbm_close (dbf);
if (verbose)

Return to:

Send suggestions and report system problems to the System administrator.