[Unbound-users] [PATCH] Add msg, rrset, infra and key cache sizes to stats command

W.C.A. Wijngaards wouter at nlnetlabs.nl
Fri Aug 1 13:30:02 UTC 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Maciej,

On 08/01/2014 03:00 PM, Maciej Soltysiak wrote:
> Hi list!
> 
> This patch adds 4 lines to the output of the unbound-control 
> [stats|stats_noreset]: msg.cache.count=78 rrset.cache.count=346 
> infra.cache.count=14 key.cache.count=3
> 
> I added this functionality because I was often doing dump_cache
> and then working on the output to find out some statistics on the
> cache contents. Unfortunately this means locking the resolver
> because dump_cache has to lock the slabhash.

Thank you for the patch!  I have integrated it.

Changes your patch a little, such as adding locks that protect the
counts.  Also added documentation for it, and added it to the munin
memory graph.

Best regards,
   Wouter


> This patch does not use any locks because it uses the counts 
> maintained within the structures.
> 
> Also it utilizes the fact that all these are struct slabhash type, 
> therefore I created only one generic function for that: size_t 
> count_slabhash_entries(struct slabhash *sh)
> 
> Please review this patch (on top of 1.4.22 tarball) for 1.4.23
> 
> Patch attached as well as inlined.
> 
> Best regards, Maciej Soltysiak
> 
> diff -Nru /home/solt/orig/unbound-1.4.22.deb/daemon/remote.c 
> ./unbound-1.4.22/daemon/remote.c ---
> /home/solt/orig/unbound-1.4.22.deb/daemon/remote.c    2014-02-07 
> 14:28:39.000000000 +0100 +++ ./unbound-1.4.22/daemon/remote.c
> 2014-08-01 14:06:49.530833070 +0200 @@ -874,6 +874,15 @@ 
> (unsigned)s->svr.unwanted_queries)) return 0; if(!ssl_printf(ssl,
> "unwanted.replies"SQ"%u\n", (unsigned)s->svr.unwanted_replies))
> return 0; +    /* cache counts */ +    if(!ssl_printf(ssl,
> "msg.cache.count"SQ"%u\n", +
> (unsigned)s->svr.msg_cache_count)) return 0; +
> if(!ssl_printf(ssl, "rrset.cache.count"SQ"%u\n", +
> (unsigned)s->svr.rrset_cache_count)) return 0; +
> if(!ssl_printf(ssl, "infra.cache.count"SQ"%u\n", +
> (unsigned)s->svr.infra_cache_count)) return 0; +
> if(!ssl_printf(ssl, "key.cache.count"SQ"%u\n", +
> (unsigned)s->svr.key_cache_count)) return 0; return 1; }
> 
> diff -Nru /home/solt/orig/unbound-1.4.22.deb/daemon/stats.c 
> ./unbound-1.4.22/daemon/stats.c ---
> /home/solt/orig/unbound-1.4.22.deb/daemon/stats.c    2014-02-07 
> 14:28:39.000000000 +0100 +++ ./unbound-1.4.22/daemon/stats.c
> 2014-08-01 14:34:05.066975149 +0200 @@ -56,6 +56,9 @@ #include
> "util/net_help.h" #include "validator/validator.h" #include
> "ldns/sbuffer.h" +#include "services/cache/rrset.h" +#include
> "services/cache/infra.h" +#include "validator/val_kcache.h"
> 
> /** add timers and the values do not overflow or become negative
> */ static void @@ -162,6 +165,12 @@ /* get and reset validator
> rrset bogus number */ s->svr.rrset_bogus =
> get_rrset_bogus(worker);
> 
> +    /* get cache sizes */ +    s->svr.msg_cache_count =
> count_slabhash_entries(worker->env.msg_cache); +
> s->svr.rrset_cache_count = 
> count_slabhash_entries(&worker->env.rrset_cache->table); +
> s->svr.infra_cache_count = 
> count_slabhash_entries(worker->env.infra_cache->hosts); +
> s->svr.key_cache_count = 
> count_slabhash_entries(worker->env.key_cache->slab); + if(reset &&
> !worker->env.cfg->stat_cumulative) { worker_stats_clear(worker); } 
> diff -Nru /home/solt/orig/unbound-1.4.22.deb/daemon/stats.h 
> ./unbound-1.4.22/daemon/stats.h ---
> /home/solt/orig/unbound-1.4.22.deb/daemon/stats.h    2014-02-07 
> 14:28:39.000000000 +0100 +++ ./unbound-1.4.22/daemon/stats.h
> 2014-08-01 14:34:21.934978790 +0200 @@ -133,6 +133,15 @@ * if all
> histograms are same size (is so by default) then * adding up works
> well. */ size_t hist[NUM_BUCKETS_HIST]; + +    /** number of
> message cache entries */ +    size_t msg_cache_count; +    /**
> number of rrset cache entries */ +    size_t rrset_cache_count; +
> /** number of infra cache entries */ +    size_t
> infra_cache_count; +    /** number of key cache entries */ +
> size_t key_cache_count; };
> 
> /** diff -Nru
> /home/solt/orig/unbound-1.4.22.deb/util/storage/slabhash.c 
> ./unbound-1.4.22/util/storage/slabhash.c ---
> ./unbound-1.4.22/util/storage/slabhash.c    2014-02-07 
> 14:28:39.000000000 +0100 +++
> ../test/unbound-1.4.22/util/storage/slabhash.c    2014-08-01 
> 14:43:52.611119849 +0200 @@ -217,3 +217,13 @@ for(i=0; i<sh->size;
> i++) lruhash_traverse(sh->array[i], wr, func, arg); } + +size_t
> count_slabhash_entries(struct slabhash* sh) +{ +    size_t slab,
> cnt; + +    for(slab=0, cnt=0; slab<sh->size; slab++) { +
> cnt += sh->array[slab]->num; +    } +    return cnt; +} diff -Nru
> /home/solt/orig/unbound-1.4.22.deb/util/storage/slabhash.h 
> ./unbound-1.4.22/util/storage/slabhash.h ---
> /home/solt/orig/unbound-1.4.22.deb/util/storage/slabhash.h 
> 2014-02-07 14:28:39.000000000 +0100 +++
> ./unbound-1.4.22/util/storage/slabhash.h    2014-08-01 
> 14:06:49.534833070 +0200 @@ -184,6 +184,12 @@ void
> slabhash_traverse(struct slabhash* table, int wr, void
> (*func)(struct lruhash_entry*, void*), void* arg);
> 
> +/* + * Count entries in slabhash. + * @param table: slabbed hash
> table; + */ +size_t count_slabhash_entries(struct slabhash*
> table); + /* --- test representation --- */ /** test structure
> contains test key */ struct slabhash_testkey {
> 
> 
> 
> _______________________________________________ Unbound-users
> mailing list Unbound-users at unbound.net 
> http://unbound.nlnetlabs.nl/mailman/listinfo/unbound-users
> 

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBAgAGBQJT25ZaAAoJEJ9vHC1+BF+Nf5YP/RnUwQvOIHsdx20bwzvwiFr6
+OlIQ/lLqYLHiDjghTqDM8ohUGrf5rK1k4OfNi6cFfUb+6SMZbtYE4ipxamtgccy
srYIJbEXoV0FjgpH7E9I59AMHS/3fVAwfXhqi8sBZK4WyPDF70zLZzL3NboXOS9C
lDN8bo9pvsUUxqFbiwZYiNg4piwTjeljRQc7efFZwAo9H9pU5Q2r0IUU998tLm44
+PTs8eTXp5aKmMQUyavuMVGWjwYko1JUiad6jORFzYo4Tq2qPmcXA3cGoXsQCdLr
hbxAtvq9Jyx1+MyaeZxOq9rJ3J0MD3o1ukJVj787LOuXLfkKOGq6yU8LeeGiskrk
mWSEIkzyrDPrVBfIoemMoGgqTUFO8C8hNjQRyzixYJc+HqggXKDw9OCFtZnS0DS4
cyNzviErlwLTbmvmM0R1mnIkV671cdOAXbohBs3mSn8t8Nnj6ICqRMTey8PPQepQ
0SsEwOjuDeuT2SgVPR29pBMrFVdiYYz+nhibumsVRGUSWsoRc9DHIB1y4h68Cnrt
eSmJ92gBgcdSyPKcWDrLPnB8KZMa+9lWG88bKyaZskh68aFj666ukdt5tDqt+a8S
89jMVRTpMY08CAqvvqW8z063ZPzlfjOD04P2P+uZnvR7wahl3Xrs051IqSip3woA
+winwhkbwZN+m5EXMJWs
=y++7
-----END PGP SIGNATURE-----



More information about the Unbound-users mailing list