aboutsummaryrefslogtreecommitdiff
path: root/src/datacache/perf_datacache.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/datacache/perf_datacache.c')
-rw-r--r--src/datacache/perf_datacache.c174
1 files changed, 0 insertions, 174 deletions
diff --git a/src/datacache/perf_datacache.c b/src/datacache/perf_datacache.c
deleted file mode 100644
index adbb958cc..000000000
--- a/src/datacache/perf_datacache.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2010 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @file datacache/perf_datacache.c
22 * @brief Performance evaluation for the datacache implementations.
23 * @author Nils Durner
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_datacache_lib.h"
28#include "gnunet_testing_lib.h"
29#include <gauger.h>
30
31
32#define ASSERT(x) do { if (! (x)) { printf ("Error at %s:%d\n", __FILE__, \
33 __LINE__); goto FAILURE; \
34 } } while (0)
35
36#define ITERATIONS 10000
37
38static int ok;
39
40static unsigned int found;
41
42/**
43 * Name of plugin under test.
44 */
45static const char *plugin_name;
46
47
48static int
49checkIt (void *cls,
50 const struct GNUNET_HashCode *key,
51 size_t size,
52 const char *data,
53 enum GNUNET_BLOCK_Type type,
54 struct GNUNET_TIME_Absolute exp,
55 unsigned int path_len,
56 const struct GNUNET_DHT_PathElement *path)
57{
58 if ( (size == sizeof(struct GNUNET_HashCode)) &&
59 (0 == memcmp (data,
60 cls,
61 size)) )
62 found++;
63 return GNUNET_OK;
64}
65
66
67static void
68run (void *cls,
69 char *const *args,
70 const char *cfgfile,
71 const struct GNUNET_CONFIGURATION_Handle *cfg)
72{
73 struct GNUNET_DATACACHE_Handle *h;
74 struct GNUNET_HashCode k;
75 struct GNUNET_HashCode n;
76 struct GNUNET_TIME_Absolute exp;
77 struct GNUNET_TIME_Absolute start;
78 unsigned int i;
79 char gstr[128];
80
81 ok = 0;
82 h = GNUNET_DATACACHE_create (cfg, "perfcache");
83
84 if (h == NULL)
85 {
86 fprintf (stderr, "%s",
87 "Failed to initialize datacache. Database likely not setup, skipping test.\n");
88 ok = 77; /* mark test as skipped */
89 return;
90 }
91 exp = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS);
92 start = GNUNET_TIME_absolute_get ();
93 memset (&k, 0, sizeof(struct GNUNET_HashCode));
94 for (i = 0; i < ITERATIONS; i++)
95 {
96 if (0 == i % (ITERATIONS / 80))
97 fprintf (stderr, "%s", ".");
98 GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n);
99 ASSERT (GNUNET_OK ==
100 GNUNET_DATACACHE_put (h, &k, sizeof(struct GNUNET_HashCode),
101 (const char *) &n, 1 + i % 16, exp,
102 0, NULL));
103 k = n;
104 }
105 fprintf (stderr, "%s", "\n");
106 fprintf (stdout, "Stored %u items in %s\n", ITERATIONS,
107 GNUNET_STRINGS_relative_time_to_string (
108 GNUNET_TIME_absolute_get_duration (start), GNUNET_YES));
109 GNUNET_snprintf (gstr, sizeof(gstr), "DATACACHE-%s", plugin_name);
110 GAUGER (gstr, "Time to PUT item in datacache",
111 GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL
112 / ITERATIONS,
113 "ms/item");
114 start = GNUNET_TIME_absolute_get ();
115 memset (&k, 0, sizeof(struct GNUNET_HashCode));
116 for (i = 0; i < ITERATIONS; i++)
117 {
118 if (0 == i % (ITERATIONS / 80))
119 fprintf (stderr, "%s", ".");
120 GNUNET_CRYPTO_hash (&k, sizeof(struct GNUNET_HashCode), &n);
121 GNUNET_DATACACHE_get (h, &k, 1 + i % 16, &checkIt, &n);
122 k = n;
123 }
124 fprintf (stderr, "%s", "\n");
125 fprintf (stdout,
126 "Found %u/%u items in %s (%u were deleted during storage processing)\n",
127 found, ITERATIONS,
128 GNUNET_STRINGS_relative_time_to_string (
129 GNUNET_TIME_absolute_get_duration (start), GNUNET_YES),
130 ITERATIONS - found);
131 if (found > 0)
132 GAUGER (gstr, "Time to GET item from datacache",
133 GNUNET_TIME_absolute_get_duration (start).rel_value_us / 1000LL
134 / found,
135 "ms/item");
136 GNUNET_DATACACHE_destroy (h);
137 ASSERT (ok == 0);
138 return;
139FAILURE:
140 if (h != NULL)
141 GNUNET_DATACACHE_destroy (h);
142 ok = GNUNET_SYSERR;
143}
144
145
146int
147main (int argc, char *argv[])
148{
149 char cfg_name[PATH_MAX];
150 char *const xargv[] = {
151 "perf-datacache",
152 "-c",
153 cfg_name,
154 NULL
155 };
156 struct GNUNET_GETOPT_CommandLineOption options[] = {
157 GNUNET_GETOPT_OPTION_END
158 };
159
160 GNUNET_log_setup ("perf-datacache",
161 "WARNING",
162 NULL);
163 plugin_name = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
164 GNUNET_snprintf (cfg_name, sizeof(cfg_name), "perf_datacache_data_%s.conf",
165 plugin_name);
166 GNUNET_PROGRAM_run ((sizeof(xargv) / sizeof(char *)) - 1, xargv,
167 "perf-datacache", "nohelp", options, &run, NULL);
168 if ((0 != ok) && (77 != ok))
169 fprintf (stderr, "Missed some perfcases: %d\n", ok);
170 return ok;
171}
172
173
174/* end of perf_datacache.c */