aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/perf_plugin_datastore.c
diff options
context:
space:
mode:
authorDavid Barksdale <amatus.amongus@gmail.com>2015-03-21 03:38:29 +0000
committerDavid Barksdale <amatus.amongus@gmail.com>2015-03-21 03:38:29 +0000
commitc77d4e5c69ac54ffddf5bd60c18bcb0504389311 (patch)
treebb40b73db6ed428d6ab44ffee91ca0ed6f16b592 /src/datastore/perf_plugin_datastore.c
parentce6f1156a58aafed6563585b3be560ec0b4eabe7 (diff)
downloadgnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.tar.gz
gnunet-c77d4e5c69ac54ffddf5bd60c18bcb0504389311.zip
Convert datastore plugin API to asynchronous
Diffstat (limited to 'src/datastore/perf_plugin_datastore.c')
-rw-r--r--src/datastore/perf_plugin_datastore.c107
1 files changed, 61 insertions, 46 deletions
diff --git a/src/datastore/perf_plugin_datastore.c b/src/datastore/perf_plugin_datastore.c
index f845b5a59..2ff8340f3 100644
--- a/src/datastore/perf_plugin_datastore.c
+++ b/src/datastore/perf_plugin_datastore.c
@@ -99,15 +99,60 @@ disk_utilization_change_cb (void *cls, int delta)
99 99
100 100
101static void 101static void
102putValue (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k) 102test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
103
104
105static void
106put_continuation (void *cls, const struct GNUNET_HashCode *key,
107 uint32_t size, int status, char *msg)
108{
109 struct CpsRunContext *crc = cls;
110
111 if (GNUNET_OK != status)
112 {
113 FPRINTF (stderr, "ERROR: `%s'\n", msg);
114 }
115 else
116 {
117 stored_bytes += size;
118 stored_ops++;
119 stored_entries++;
120 }
121 GNUNET_SCHEDULER_add_now (&test, crc);
122}
123
124static void
125do_put (struct CpsRunContext *crc)
103{ 126{
104 char value[65536]; 127 char value[65536];
105 size_t size; 128 size_t size;
106 static struct GNUNET_HashCode key; 129 static struct GNUNET_HashCode key;
107 static int ic; 130 static int i;
108 char *msg;
109 unsigned int prio; 131 unsigned int prio;
110 132
133 if (0 == i)
134 crc->start = GNUNET_TIME_absolute_get ();
135 if (PUT_10 == i)
136 {
137 i = 0;
138 crc->end = GNUNET_TIME_absolute_get ();
139 {
140 printf ("%s took %s for %llu items\n", "Storing an item",
141 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start,
142 crc->end),
143 GNUNET_YES),
144 PUT_10);
145 if (PUT_10 > 0)
146 GAUGER (category, "Storing an item",
147 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10,
148 "ms/item");
149 }
150 crc->i++;
151 crc->start = GNUNET_TIME_absolute_get ();
152 crc->phase++;
153 GNUNET_SCHEDULER_add_now (&test, crc);
154 return;
155 }
111 /* most content is 32k */ 156 /* most content is 32k */
112 size = 32 * 1024; 157 size = 32 * 1024;
113 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 158 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
@@ -120,33 +165,22 @@ putValue (struct GNUNET_DATASTORE_PluginFunctions *api, int i, int k)
120 memset (value, i, size); 165 memset (value, i, size);
121 if (i > 255) 166 if (i > 255)
122 memset (value, i - 255, size / 2); 167 memset (value, i - 255, size / 2);
123 value[0] = k; 168 value[0] = crc->i;
124 memcpy (&value[4], &i, sizeof (i)); 169 memcpy (&value[4], &i, sizeof (i));
125 msg = NULL;
126 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); 170 prio = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
127 if (GNUNET_OK != api->put (api->cls, &key, size, value, 1 + i % 4 /* type */ , 171 crc->api->put (crc->api->cls, &key, size, value, 1 + i % 4 /* type */ ,
128 prio, i % 4 /* anonymity */ , 172 prio, i % 4 /* anonymity */ ,
129 0 /* replication */ , 173 0 /* replication */ ,
130 GNUNET_TIME_relative_to_absolute 174 GNUNET_TIME_relative_to_absolute
131 (GNUNET_TIME_relative_multiply 175 (GNUNET_TIME_relative_multiply
132 (GNUNET_TIME_UNIT_MILLISECONDS, 176 (GNUNET_TIME_UNIT_MILLISECONDS,
133 60 * 60 * 60 * 1000 + 177 60 * 60 * 60 * 1000 +
134 GNUNET_CRYPTO_random_u32 178 GNUNET_CRYPTO_random_u32
135 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))), &msg)) 179 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
136 { 180 put_continuation, crc);
137 FPRINTF (stderr, "ERROR: `%s'\n", msg); 181 i++;
138 GNUNET_free_non_null (msg);
139 return;
140 }
141 ic++;
142 stored_bytes += size;
143 stored_ops++;
144 stored_entries++;
145} 182}
146 183
147static void
148test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
149
150 184
151static int 185static int
152iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size, 186iterate_zeros (void *cls, const struct GNUNET_HashCode * key, uint32_t size,
@@ -342,7 +376,6 @@ static void
342test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 376test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
343{ 377{
344 struct CpsRunContext *crc = cls; 378 struct CpsRunContext *crc = cls;
345 int j;
346 379
347 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 380 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
348 { 381 {
@@ -361,25 +394,7 @@ test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
361 &cleaning_task, crc); 394 &cleaning_task, crc);
362 break; 395 break;
363 case RP_PUT: 396 case RP_PUT:
364 crc->start = GNUNET_TIME_absolute_get (); 397 do_put (crc);
365 for (j = 0; j < PUT_10; j++)
366 putValue (crc->api, j, crc->i);
367 crc->end = GNUNET_TIME_absolute_get ();
368 {
369 printf ("%s took %s for %llu items\n", "Storing an item",
370 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_difference (crc->start,
371 crc->end),
372 GNUNET_YES),
373 PUT_10);
374 if (PUT_10 > 0)
375 GAUGER (category, "Storing an item",
376 (crc->end.abs_value_us - crc->start.abs_value_us) / 1000LL / PUT_10,
377 "ms/item");
378 }
379 crc->i++;
380 crc->start = GNUNET_TIME_absolute_get ();
381 crc->phase++;
382 GNUNET_SCHEDULER_add_now (&test, crc);
383 break; 398 break;
384 case RP_REP_GET: 399 case RP_REP_GET:
385 crc->api->get_replication (crc->api->cls, &replication_get, crc); 400 crc->api->get_replication (crc->api->cls, &replication_get, crc);