]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
some basic stats.
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 1 May 2007 12:13:29 +0000 (12:13 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Tue, 1 May 2007 12:13:29 +0000 (12:13 +0000)
git-svn-id: file:///svn/unbound/trunk@271 be551aaa-1e26-0410-a405-d3ace91eadb9

Makefile.in
daemon/stats.c [new file with mode: 0644]
daemon/stats.h [new file with mode: 0644]
daemon/worker.c
daemon/worker.h
doc/Changelog

index 7b9eff8b2f89d10337b0af53eebf26693020986c..4a0971921c10b561997fe81229940fd71ff8820f 100644 (file)
@@ -57,7 +57,7 @@ UNITTEST_SRC=$(wildcard testcode/unit*.c) testcode/readhex.c $(COMMON_SRC)
 UNITTEST_OBJ=$(addprefix $(BUILD),$(UNITTEST_SRC:.c=.o)) $(COMPAT_OBJ)
 DAEMON_SRC=$(wildcard daemon/*.c) $(COMMON_SRC)
 DAEMON_OBJ=$(addprefix $(BUILD),$(DAEMON_SRC:.c=.o)) $(COMPAT_OBJ)
-TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c daemon/daemon.c testcode/replay.c testcode/fake_event.c $(filter-out util/netevent.c services/listen_dnsport.c services/outside_network.c, $(COMMON_SRC))
+TESTBOUND_SRC=testcode/testbound.c testcode/ldns-testpkts.c daemon/worker.c daemon/daemon.c daemon/stats.c testcode/replay.c testcode/fake_event.c $(filter-out util/netevent.c services/listen_dnsport.c services/outside_network.c, $(COMMON_SRC))
 TESTBOUND_OBJ=$(addprefix $(BUILD),$(TESTBOUND_SRC:.c=.o)) $(COMPAT_OBJ)
 LOCKVERIFY_SRC=testcode/lock_verify.c $(COMMON_SRC)
 LOCKVERIFY_OBJ=$(addprefix $(BUILD),$(LOCKVERIFY_SRC:.c=.o)) $(COMPAT_OBJ)
diff --git a/daemon/stats.c b/daemon/stats.c
new file mode 100644 (file)
index 0000000..afb1c1a
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * daemon/stats.c - collect runtime performance indicators.
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * This software is open source.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the NLNET LABS nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ *
+ * This file describes the data structure used to collect runtime performance
+ * numbers. These 'statistics' may be of interest to the operator.
+ */
+#include "config.h"
+#include "daemon/stats.h"
+#include "daemon/worker.h"
+
+void server_stats_init(struct server_stats* stats)
+{
+       memset(stats, 0, sizeof(stats));
+}
+
+void server_stats_querymiss(struct server_stats* stats, struct worker* worker)
+{
+       stats->num_queries_missed_cache++;
+       stats->sum_query_list_size += worker->num_requests;
+       if(worker->num_requests > stats->max_query_list_size)
+               stats->max_query_list_size = worker->num_requests;
+}
+
+void server_stats_log(struct server_stats* stats, int threadnum)
+{
+       log_info("server stats for thread %d: %u queries, %u from cache", 
+               threadnum, (unsigned)stats->num_queries, 
+               (unsigned)(stats->num_queries - 
+                       stats->num_queries_missed_cache));
+       log_info("server stats for thread %d: requestlist max %u avg %g "
+               "exceeded %u", threadnum, (unsigned)stats->max_query_list_size,
+               stats->num_queries_missed_cache?
+               (double)stats->sum_query_list_size/
+               stats->num_queries_missed_cache:0.0,
+               (unsigned)stats->num_query_list_exceeded);
+}
diff --git a/daemon/stats.h b/daemon/stats.h
new file mode 100644 (file)
index 0000000..a3f2bc6
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * daemon/stats.h - collect runtime performance indicators.
+ *
+ * Copyright (c) 2007, NLnet Labs. All rights reserved.
+ *
+ * This software is open source.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 
+ * Neither the name of the NLNET LABS nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * \file
+ *
+ * This file describes the data structure used to collect runtime performance
+ * numbers. These 'statistics' may be of interest to the operator.
+ */
+
+#ifndef DAEMON_STATS_H
+#define DAEMON_STATS_H
+struct worker;
+
+/** per worker statistics */
+struct server_stats {
+       /** number of queries from clients received. */
+       size_t num_queries;
+       /** number of queries that had a cache-miss. */
+       size_t num_queries_missed_cache;
+
+       /**
+        * Sum of the querylistsize of the worker for 
+        * every query that missed cache. To calculate average.
+        */
+       size_t sum_query_list_size;
+       /** max value of query list size reached. */
+       size_t max_query_list_size;
+       /** number of times that the query_list_size was insufficient */
+       size_t num_query_list_exceeded;
+};
+
+/** 
+ * Initialize server stats to 0.
+ * @param stats: what to init (this is alloced by the caller).
+ */
+void server_stats_init(struct server_stats* stats);
+
+/** add query if it missed the cache */
+void server_stats_querymiss(struct server_stats* stats, struct worker* worker);
+
+/** display the stats to the log */
+void server_stats_log(struct server_stats* stats, int threadnum);
+
+#endif /* DAEMON_STATS_H */
index 67a4b34231a009993eb360bb8e5fcc23a2c7091b..51c94a8b3fdd77beeeff82efa0c816ece65a944b 100644 (file)
@@ -284,6 +284,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
                comm_point_drop_reply(repinfo);
                return 0;
        }
+       worker->stats.num_queries++;
        /* see if query is in the cache */
        if(!query_info_parse(&qinfo, c->buffer)) {
                LDNS_QR_SET(ldns_buffer_begin(c->buffer));
@@ -303,6 +304,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
                return 0;
        }
        ldns_buffer_rewind(c->buffer);
+       server_stats_querymiss(&worker->stats, worker);
        /* perform memory allocation(s) */
        if(!query_info_allocqname(&qinfo)) {
                comm_point_drop_reply(repinfo);
@@ -315,6 +317,7 @@ worker_handle_request(struct comm_point* c, void* arg, int error,
                   that started before we performed listen_pushback */
                verbose(VERB_DETAIL, "worker: too many incoming requests "
                        "active. dropping incoming query.");
+               worker->stats.num_query_list_exceeded++;
                comm_point_drop_reply(repinfo);
                query_info_clear(&qinfo);
                return 0;
@@ -525,6 +528,7 @@ worker_init(struct worker* worker, struct config_file *cfg,
                        fatal_exit("could not set forwarder address");
                }
        }
+       server_stats_init(&worker->stats);
        alloc_init(&worker->alloc, &worker->daemon->superalloc, 
                worker->thread_num);
        return 1;
@@ -541,6 +545,7 @@ worker_delete(struct worker* worker)
 {
        if(!worker) 
                return;
+       server_stats_log(&worker->stats, worker->thread_num);
        reqs_delete(worker);
        listen_delete(worker->front);
        outside_network_delete(worker->back);
index c3b82ae8c4f745a148bccd2ad442c1afae07a919..210889564315d58d31800d4af6389ebd065fda35 100644 (file)
@@ -48,6 +48,7 @@
 #include "util/locks.h"
 #include "util/alloc.h"
 #include "util/data/msgreply.h"
+#include "daemon/stats.h"
 struct listen_dnsport;
 struct outside_network;
 struct config_file;
@@ -130,6 +131,8 @@ struct worker {
        int need_to_restart;
        /** allocation cache for this thread */
        struct alloc_cache alloc;
+       /** per thread statistics */
+       struct server_stats stats;
 };
 
 /**
index 75ec347f046d01f642401a301d4e4f8caea719ba..43386e3c4b74252a556d51d711e677ccfdf0fc83 100644 (file)
@@ -2,6 +2,7 @@
        - decompress query section, extremely lenient acceptance.
          But only for answers from other servers, not for plain queries.
        - compression and decompression test cases.
+       - some stats added.
 
 27 April 2007: Wouter
        - removed iov usage, it is not good for dns message encoding.