diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2014-06-11 09:15:37 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2014-06-11 09:15:37 +0000 |
commit | 82192cd2ab03977cf175507372e0f8cd12d1db7d (patch) | |
tree | fed20812f62450427ee40168d268fda70019ee75 /src/peerstore/perf_peerstore_store.c | |
parent | 464bc25469fa8c415d0a852ca374da3593bc94a6 (diff) | |
download | gnunet-82192cd2ab03977cf175507372e0f8cd12d1db7d.tar.gz gnunet-82192cd2ab03977cf175507372e0f8cd12d1db7d.zip |
renaming to perf test
Diffstat (limited to 'src/peerstore/perf_peerstore_store.c')
-rw-r--r-- | src/peerstore/perf_peerstore_store.c | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/src/peerstore/perf_peerstore_store.c b/src/peerstore/perf_peerstore_store.c new file mode 100644 index 000000000..4f5366225 --- /dev/null +++ b/src/peerstore/perf_peerstore_store.c | |||
@@ -0,0 +1,118 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
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 | |||
31 | static int ok = 1; | ||
32 | |||
33 | struct GNUNET_PEERSTORE_Handle *h; | ||
34 | |||
35 | char *ss = "test_peerstore_stress"; | ||
36 | struct GNUNET_PeerIdentity p; | ||
37 | char *k = "test_peerstore_stress_key"; | ||
38 | char *v = "test_peerstore_stress_val"; | ||
39 | |||
40 | int count = 0; | ||
41 | |||
42 | void | ||
43 | disconnect() | ||
44 | { | ||
45 | if(NULL != h) | ||
46 | GNUNET_PEERSTORE_disconnect(h); | ||
47 | GNUNET_SCHEDULER_shutdown(); | ||
48 | } | ||
49 | |||
50 | void | ||
51 | store() | ||
52 | { | ||
53 | GNUNET_PEERSTORE_store(h, | ||
54 | ss, | ||
55 | &p, | ||
56 | k, | ||
57 | v, | ||
58 | strlen(v) + 1, | ||
59 | GNUNET_TIME_UNIT_FOREVER_ABS, | ||
60 | (count == 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE : GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | ||
61 | NULL, | ||
62 | NULL); | ||
63 | count++; | ||
64 | } | ||
65 | |||
66 | static int | ||
67 | watch_cb(void *cls, | ||
68 | struct GNUNET_PEERSTORE_Record *record, | ||
69 | char *emsg) | ||
70 | { | ||
71 | GNUNET_assert(NULL == emsg); | ||
72 | if(STORES == count) | ||
73 | { | ||
74 | ok = 0; | ||
75 | disconnect(); | ||
76 | } | ||
77 | else | ||
78 | store(); | ||
79 | return GNUNET_YES; | ||
80 | } | ||
81 | |||
82 | static void | ||
83 | run (void *cls, | ||
84 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
85 | struct GNUNET_TESTING_Peer *peer) | ||
86 | { | ||
87 | memset (&p, 5, sizeof (p)); | ||
88 | h = GNUNET_PEERSTORE_connect(cfg); | ||
89 | GNUNET_assert(NULL != h); | ||
90 | GNUNET_PEERSTORE_watch(h, | ||
91 | ss, | ||
92 | &p, | ||
93 | k, | ||
94 | &watch_cb, | ||
95 | NULL); | ||
96 | store(); | ||
97 | } | ||
98 | |||
99 | int | ||
100 | main (int argc, char *argv[]) | ||
101 | { | ||
102 | struct GNUNET_TIME_Absolute start; | ||
103 | struct GNUNET_TIME_Relative diff; | ||
104 | |||
105 | start = GNUNET_TIME_absolute_get(); | ||
106 | if (0 != GNUNET_TESTING_service_run ("perf-peerstore-store", | ||
107 | "peerstore", | ||
108 | "test_peerstore_api_data.conf", | ||
109 | &run, NULL)) | ||
110 | return 1; | ||
111 | diff = GNUNET_TIME_absolute_get_duration(start); | ||
112 | fprintf(stderr, "Stored and retrieved %d records in %s (%s).\n", | ||
113 | STORES, GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_YES), | ||
114 | GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_NO)); | ||
115 | return ok; | ||
116 | } | ||
117 | |||
118 | /* end of perf_peerstore_store.c */ | ||