aboutsummaryrefslogtreecommitdiff
path: root/src/service/peerstore/perf_peerstore_store.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/peerstore/perf_peerstore_store.c')
-rw-r--r--src/service/peerstore/perf_peerstore_store.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/service/peerstore/perf_peerstore_store.c b/src/service/peerstore/perf_peerstore_store.c
new file mode 100644
index 000000000..24c7e4f01
--- /dev/null
+++ b/src/service/peerstore/perf_peerstore_store.c
@@ -0,0 +1,109 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C)
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 peerstore/perf_peerstore_store.c
22 * @brief performance test for peerstore store operation
23 */
24#include "platform.h"
25#include "gnunet_util_lib.h"
26#include "gnunet_testing_lib.h"
27#include "gnunet_peerstore_service.h"
28
29#define STORES 10000
30
31static int ok = 1;
32
33static struct GNUNET_PEERSTORE_Handle *h;
34
35static char *ss = "test_peerstore_stress";
36static struct GNUNET_PeerIdentity p;
37static char *k = "test_peerstore_stress_key";
38static char *v = "test_peerstore_stress_val";
39
40static int count = 0;
41
42static void
43disconnect ()
44{
45 if (NULL != h)
46 GNUNET_PEERSTORE_disconnect (h, GNUNET_YES);
47 GNUNET_SCHEDULER_shutdown ();
48}
49
50
51static void
52store ()
53{
54 GNUNET_PEERSTORE_store (h, ss, &p, k, v, strlen (v) + 1,
55 GNUNET_TIME_UNIT_FOREVER_ABS,
56 (count ==
57 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE :
58 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
59 count++;
60}
61
62
63static void
64watch_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record,
65 const char *emsg)
66{
67 GNUNET_assert (NULL == emsg);
68 if (STORES == count)
69 {
70 ok = 0;
71 disconnect ();
72 }
73 else
74 store ();
75}
76
77
78static void
79run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
80 struct GNUNET_TESTING_Peer *peer)
81{
82 memset (&p, 5, sizeof(p));
83 h = GNUNET_PEERSTORE_connect (cfg);
84 GNUNET_assert (NULL != h);
85 GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL);
86 store ();
87}
88
89
90int
91main (int argc, char *argv[])
92{
93 struct GNUNET_TIME_Absolute start;
94 struct GNUNET_TIME_Relative diff;
95
96 start = GNUNET_TIME_absolute_get ();
97 if (0 !=
98 GNUNET_TESTING_service_run ("perf-peerstore-store", "peerstore",
99 "test_peerstore_api_data.conf", &run, NULL))
100 return 1;
101 diff = GNUNET_TIME_absolute_get_duration (start);
102 fprintf (stderr, "Stored and retrieved %d records in %s (%s).\n", STORES,
103 GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_YES),
104 GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_NO));
105 return ok;
106}
107
108
109/* end of perf_peerstore_store.c */