summaryrefslogtreecommitdiff
path: root/src/namestore/perf_namestore_api_zone_iteration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/namestore/perf_namestore_api_zone_iteration.c')
-rw-r--r--src/namestore/perf_namestore_api_zone_iteration.c373
1 files changed, 187 insertions, 186 deletions
diff --git a/src/namestore/perf_namestore_api_zone_iteration.c b/src/namestore/perf_namestore_api_zone_iteration.c
index 6b79a35f6..e8277ae65 100644
--- a/src/namestore/perf_namestore_api_zone_iteration.c
+++ b/src/namestore/perf_namestore_api_zone_iteration.c
@@ -35,7 +35,7 @@
35 * modern system, so 30 minutes should be OK even for very, very 35 * modern system, so 30 minutes should be OK even for very, very
36 * slow systems. 36 * slow systems.
37 */ 37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 30) 38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
39 39
40/** 40/**
41 * The runtime of the benchmark is expected to be linear 41 * The runtime of the benchmark is expected to be linear
@@ -87,39 +87,39 @@ static struct GNUNET_TIME_Absolute start;
87 * @param cls NULL 87 * @param cls NULL
88 */ 88 */
89static void 89static void
90end(void *cls) 90end (void *cls)
91{ 91{
92 (void)cls; 92 (void) cls;
93 if (NULL != qe) 93 if (NULL != qe)
94 { 94 {
95 GNUNET_NAMESTORE_cancel(qe); 95 GNUNET_NAMESTORE_cancel (qe);
96 qe = NULL; 96 qe = NULL;
97 } 97 }
98 if (NULL != zi) 98 if (NULL != zi)
99 { 99 {
100 GNUNET_NAMESTORE_zone_iteration_stop(zi); 100 GNUNET_NAMESTORE_zone_iteration_stop (zi);
101 zi = NULL; 101 zi = NULL;
102 } 102 }
103 if (NULL != nsh) 103 if (NULL != nsh)
104 { 104 {
105 GNUNET_NAMESTORE_disconnect(nsh); 105 GNUNET_NAMESTORE_disconnect (nsh);
106 nsh = NULL; 106 nsh = NULL;
107 } 107 }
108 if (NULL != t) 108 if (NULL != t)
109 { 109 {
110 GNUNET_SCHEDULER_cancel(t); 110 GNUNET_SCHEDULER_cancel (t);
111 t = NULL; 111 t = NULL;
112 } 112 }
113 if (NULL != timeout_task) 113 if (NULL != timeout_task)
114 { 114 {
115 GNUNET_SCHEDULER_cancel(timeout_task); 115 GNUNET_SCHEDULER_cancel (timeout_task);
116 timeout_task = NULL; 116 timeout_task = NULL;
117 } 117 }
118 if (NULL != privkey) 118 if (NULL != privkey)
119 { 119 {
120 GNUNET_free(privkey); 120 GNUNET_free (privkey);
121 privkey = NULL; 121 privkey = NULL;
122 } 122 }
123} 123}
124 124
125 125
@@ -128,228 +128,229 @@ end(void *cls)
128 * fail hard but return "skipped". 128 * fail hard but return "skipped".
129 */ 129 */
130static void 130static void
131timeout(void *cls) 131timeout (void *cls)
132{ 132{
133 (void)cls; 133 (void) cls;
134 timeout_task = NULL; 134 timeout_task = NULL;
135 GNUNET_SCHEDULER_shutdown(); 135 GNUNET_SCHEDULER_shutdown ();
136 res = 77; 136 res = 77;
137} 137}
138 138
139 139
140static struct GNUNET_GNSRECORD_Data * 140static struct GNUNET_GNSRECORD_Data *
141create_record(unsigned int count) 141create_record (unsigned int count)
142{ 142{
143 struct GNUNET_GNSRECORD_Data *rd; 143 struct GNUNET_GNSRECORD_Data *rd;
144 144
145 rd = GNUNET_malloc(count + sizeof(struct GNUNET_GNSRECORD_Data)); 145 rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data));
146 rd->expiration_time = GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS).abs_value_us; 146 rd->expiration_time = GNUNET_TIME_relative_to_absolute (
147 GNUNET_TIME_UNIT_HOURS).abs_value_us;
147 rd->record_type = TEST_RECORD_TYPE; 148 rd->record_type = TEST_RECORD_TYPE;
148 rd->data_size = count; 149 rd->data_size = count;
149 rd->data = (void *)&rd[1]; 150 rd->data = (void *) &rd[1];
150 rd->flags = 0; 151 rd->flags = 0;
151 memset(&rd[1], 152 memset (&rd[1],
152 'a', 153 'a',
153 count); 154 count);
154 return rd; 155 return rd;
155} 156}
156 157
157 158
158static void 159static void
159zone_end(void *cls) 160zone_end (void *cls)
160{ 161{
161 struct GNUNET_TIME_Relative delay; 162 struct GNUNET_TIME_Relative delay;
162 163
163 zi = NULL; 164 zi = NULL;
164 delay = GNUNET_TIME_absolute_get_duration(start); 165 delay = GNUNET_TIME_absolute_get_duration (start);
165 fprintf(stdout, 166 fprintf (stdout,
166 "Iterating over %u records took %s\n", 167 "Iterating over %u records took %s\n",
167 off, 168 off,
168 GNUNET_STRINGS_relative_time_to_string(delay, 169 GNUNET_STRINGS_relative_time_to_string (delay,
169 GNUNET_YES)); 170 GNUNET_YES));
170 if (BENCHMARK_SIZE == off) 171 if (BENCHMARK_SIZE == off)
171 { 172 {
172 res = 0; 173 res = 0;
173 } 174 }
174 else 175 else
175 { 176 {
176 GNUNET_break(0); 177 GNUNET_break (0);
177 res = 1; 178 res = 1;
178 } 179 }
179 GNUNET_SCHEDULER_shutdown(); 180 GNUNET_SCHEDULER_shutdown ();
180} 181}
181 182
182 183
183static void 184static void
184fail_cb(void *cls) 185fail_cb (void *cls)
185{ 186{
186 zi = NULL; 187 zi = NULL;
187 res = 2; 188 res = 2;
188 GNUNET_break(0); 189 GNUNET_break (0);
189 GNUNET_SCHEDULER_shutdown(); 190 GNUNET_SCHEDULER_shutdown ();
190} 191}
191 192
192 193
193static void 194static void
194zone_proc(void *cls, 195zone_proc (void *cls,
195 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, 196 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
196 const char *label, 197 const char *label,
197 unsigned int rd_count, 198 unsigned int rd_count,
198 const struct GNUNET_GNSRECORD_Data *rd) 199 const struct GNUNET_GNSRECORD_Data *rd)
199{ 200{
200 struct GNUNET_GNSRECORD_Data *wrd; 201 struct GNUNET_GNSRECORD_Data *wrd;
201 unsigned int xoff; 202 unsigned int xoff;
202 203
203 GNUNET_assert(NULL != zone); 204 GNUNET_assert (NULL != zone);
204 if (1 != sscanf(label, 205 if (1 != sscanf (label,
205 "l%u", 206 "l%u",
206 &xoff)) 207 &xoff))
207 { 208 {
208 res = 3; 209 res = 3;
209 GNUNET_break(0); 210 GNUNET_break (0);
210 GNUNET_SCHEDULER_shutdown(); 211 GNUNET_SCHEDULER_shutdown ();
211 return; 212 return;
212 } 213 }
213 if ((xoff > BENCHMARK_SIZE) || 214 if ((xoff > BENCHMARK_SIZE) ||
214 (0 != (seen[xoff / 8] & (1U << (xoff % 8))))) 215 (0 != (seen[xoff / 8] & (1U << (xoff % 8)))))
215 { 216 {
216 res = 3; 217 res = 3;
217 GNUNET_break(0); 218 GNUNET_break (0);
218 GNUNET_SCHEDULER_shutdown(); 219 GNUNET_SCHEDULER_shutdown ();
219 return; 220 return;
220 } 221 }
221 seen[xoff / 8] |= (1U << (xoff % 8)); 222 seen[xoff / 8] |= (1U << (xoff % 8));
222 wrd = create_record(xoff % MAX_REC_SIZE); 223 wrd = create_record (xoff % MAX_REC_SIZE);
223 if ((rd->record_type != wrd->record_type) || 224 if ((rd->record_type != wrd->record_type) ||
224 (rd->data_size != wrd->data_size) || 225 (rd->data_size != wrd->data_size) ||
225 (rd->flags != wrd->flags)) 226 (rd->flags != wrd->flags))
226 { 227 {
227 res = 4; 228 res = 4;
228 GNUNET_break(0); 229 GNUNET_break (0);
229 GNUNET_SCHEDULER_shutdown(); 230 GNUNET_SCHEDULER_shutdown ();
230 GNUNET_free(wrd); 231 GNUNET_free (wrd);
231 return; 232 return;
232 } 233 }
233 if (0 != memcmp(rd->data, 234 if (0 != memcmp (rd->data,
234 wrd->data, 235 wrd->data,
235 wrd->data_size)) 236 wrd->data_size))
236 { 237 {
237 res = 4; 238 res = 4;
238 GNUNET_break(0); 239 GNUNET_break (0);
239 GNUNET_SCHEDULER_shutdown(); 240 GNUNET_SCHEDULER_shutdown ();
240 GNUNET_free(wrd); 241 GNUNET_free (wrd);
241 return; 242 return;
242 } 243 }
243 GNUNET_free(wrd); 244 GNUNET_free (wrd);
244 if (0 != GNUNET_memcmp(zone, 245 if (0 != GNUNET_memcmp (zone,
245 privkey)) 246 privkey))
246 { 247 {
247 res = 5; 248 res = 5;
248 GNUNET_break(0); 249 GNUNET_break (0);
249 GNUNET_SCHEDULER_shutdown(); 250 GNUNET_SCHEDULER_shutdown ();
250 return; 251 return;
251 } 252 }
252 off++; 253 off++;
253 left_until_next--; 254 left_until_next--;
254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Obtained record %u, expecting %u more until asking for mor explicitly\n", 256 "Obtained record %u, expecting %u more until asking for mor explicitly\n",
256 off, 257 off,
257 left_until_next); 258 left_until_next);
258 if (0 == left_until_next) 259 if (0 == left_until_next)
259 { 260 {
260 left_until_next = BLOCK_SIZE; 261 left_until_next = BLOCK_SIZE;
261 GNUNET_NAMESTORE_zone_iterator_next(zi, 262 GNUNET_NAMESTORE_zone_iterator_next (zi,
262 left_until_next); 263 left_until_next);
263 } 264 }
264} 265}
265 266
266 267
267static void 268static void
268publish_record(void *cls); 269publish_record (void *cls);
269 270
270 271
271static void 272static void
272put_cont(void *cls, 273put_cont (void *cls,
273 int32_t success, 274 int32_t success,
274 const char *emsg) 275 const char *emsg)
275{ 276{
276 (void)cls; 277 (void) cls;
277 qe = NULL; 278 qe = NULL;
278 if (GNUNET_OK != success) 279 if (GNUNET_OK != success)
279 { 280 {
280 GNUNET_break(0); 281 GNUNET_break (0);
281 GNUNET_SCHEDULER_shutdown(); 282 GNUNET_SCHEDULER_shutdown ();
282 return; 283 return;
283 } 284 }
284 t = GNUNET_SCHEDULER_add_now(&publish_record, 285 t = GNUNET_SCHEDULER_add_now (&publish_record,
285 NULL); 286 NULL);
286} 287}
287 288
288 289
289static void 290static void
290publish_record(void *cls) 291publish_record (void *cls)
291{ 292{
292 struct GNUNET_GNSRECORD_Data *rd; 293 struct GNUNET_GNSRECORD_Data *rd;
293 char *label; 294 char *label;
294 295
295 (void)cls; 296 (void) cls;
296 t = NULL; 297 t = NULL;
297 if (BENCHMARK_SIZE == off) 298 if (BENCHMARK_SIZE == off)
298 { 299 {
299 struct GNUNET_TIME_Relative delay; 300 struct GNUNET_TIME_Relative delay;
300 301
301 delay = GNUNET_TIME_absolute_get_duration(start); 302 delay = GNUNET_TIME_absolute_get_duration (start);
302 fprintf(stdout, 303 fprintf (stdout,
303 "Inserting %u records took %s\n", 304 "Inserting %u records took %s\n",
304 off, 305 off,
305 GNUNET_STRINGS_relative_time_to_string(delay, 306 GNUNET_STRINGS_relative_time_to_string (delay,
306 GNUNET_YES)); 307 GNUNET_YES));
307 start = GNUNET_TIME_absolute_get(); 308 start = GNUNET_TIME_absolute_get ();
308 off = 0; 309 off = 0;
309 left_until_next = 1; 310 left_until_next = 1;
310 zi = GNUNET_NAMESTORE_zone_iteration_start(nsh, 311 zi = GNUNET_NAMESTORE_zone_iteration_start (nsh,
311 NULL, 312 NULL,
312 &fail_cb, 313 &fail_cb,
313 NULL, 314 NULL,
314 &zone_proc, 315 &zone_proc,
315 NULL, 316 NULL,
316 &zone_end, 317 &zone_end,
317 NULL); 318 NULL);
318 GNUNET_assert(NULL != zi); 319 GNUNET_assert (NULL != zi);
319 return; 320 return;
320 } 321 }
321 rd = create_record((++off) % MAX_REC_SIZE); 322 rd = create_record ((++off) % MAX_REC_SIZE);
322 GNUNET_asprintf(&label, 323 GNUNET_asprintf (&label,
323 "l%u", 324 "l%u",
324 off); 325 off);
325 qe = GNUNET_NAMESTORE_records_store(nsh, 326 qe = GNUNET_NAMESTORE_records_store (nsh,
326 privkey, 327 privkey,
327 label, 328 label,
328 1, rd, 329 1, rd,
329 &put_cont, 330 &put_cont,
330 NULL); 331 NULL);
331 GNUNET_free(label); 332 GNUNET_free (label);
332 GNUNET_free(rd); 333 GNUNET_free (rd);
333} 334}
334 335
335 336
336static void 337static void
337run(void *cls, 338run (void *cls,
338 const struct GNUNET_CONFIGURATION_Handle *cfg, 339 const struct GNUNET_CONFIGURATION_Handle *cfg,
339 struct GNUNET_TESTING_Peer *peer) 340 struct GNUNET_TESTING_Peer *peer)
340{ 341{
341 GNUNET_SCHEDULER_add_shutdown(&end, 342 GNUNET_SCHEDULER_add_shutdown (&end,
343 NULL);
344 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
345 &timeout,
346 NULL);
347 nsh = GNUNET_NAMESTORE_connect (cfg);
348 GNUNET_assert (NULL != nsh);
349 privkey = GNUNET_CRYPTO_ecdsa_key_create ();
350 GNUNET_assert (NULL != privkey);
351 start = GNUNET_TIME_absolute_get ();
352 t = GNUNET_SCHEDULER_add_now (&publish_record,
342 NULL); 353 NULL);
343 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
344 &timeout,
345 NULL);
346 nsh = GNUNET_NAMESTORE_connect(cfg);
347 GNUNET_assert(NULL != nsh);
348 privkey = GNUNET_CRYPTO_ecdsa_key_create();
349 GNUNET_assert(NULL != privkey);
350 start = GNUNET_TIME_absolute_get();
351 t = GNUNET_SCHEDULER_add_now(&publish_record,
352 NULL);
353} 354}
354 355
355 356
@@ -357,25 +358,25 @@ run(void *cls,
357 358
358 359
359int 360int
360main(int argc, 361main (int argc,
361 char *argv[]) 362 char *argv[])
362{ 363{
363 const char *plugin_name; 364 const char *plugin_name;
364 char *cfg_name; 365 char *cfg_name;
365 366
366 SETUP_CFG(plugin_name, cfg_name); 367 SETUP_CFG (plugin_name, cfg_name);
367 res = 1; 368 res = 1;
368 if (0 != 369 if (0 !=
369 GNUNET_TESTING_peer_run("perf-namestore-api-zone-iteration", 370 GNUNET_TESTING_peer_run ("perf-namestore-api-zone-iteration",
370 cfg_name, 371 cfg_name,
371 &run, 372 &run,
372 NULL)) 373 NULL))
373 { 374 {
374 res = 1; 375 res = 1;
375 } 376 }
376 GNUNET_DISK_purge_cfg_dir(cfg_name, 377 GNUNET_DISK_purge_cfg_dir (cfg_name,
377 "GNUNET_TEST_HOME"); 378 "GNUNET_TEST_HOME");
378 GNUNET_free(cfg_name); 379 GNUNET_free (cfg_name);
379 return res; 380 return res;
380} 381}
381 382