aboutsummaryrefslogtreecommitdiff
path: root/src/datastore/perf_datastore_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-06-17 02:23:24 +0000
committerChristian Grothoff <christian@grothoff.org>2009-06-17 02:23:24 +0000
commit4ac29e4a039e4f403a03f3bfb959c1bef4501846 (patch)
tree46ab02de49a3449c06e2eb1ba44e4f1755b4be8d /src/datastore/perf_datastore_api.c
parent20945e0603fd6817a87165a9b471654130cb6d67 (diff)
downloadgnunet-4ac29e4a039e4f403a03f3bfb959c1bef4501846.tar.gz
gnunet-4ac29e4a039e4f403a03f3bfb959c1bef4501846.zip
towards compiling tests
Diffstat (limited to 'src/datastore/perf_datastore_api.c')
-rw-r--r--src/datastore/perf_datastore_api.c217
1 files changed, 110 insertions, 107 deletions
diff --git a/src/datastore/perf_datastore_api.c b/src/datastore/perf_datastore_api.c
index 5001ff2a6..7b3b6cfff 100644
--- a/src/datastore/perf_datastore_api.c
+++ b/src/datastore/perf_datastore_api.c
@@ -18,8 +18,8 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/* 20/*
21 * @file applications/sqstore_sqlite/sqlitetest2.c 21 * @file datastore/perf_datastore_api.c
22 * @brief Test for the sqstore implementations. 22 * @brief performance measurement for the datastore implementation
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * 24 *
25 * This testcase inserts a bunch of (variable size) data and then deletes 25 * This testcase inserts a bunch of (variable size) data and then deletes
@@ -42,12 +42,11 @@
42 */ 42 */
43 43
44#include "platform.h" 44#include "platform.h"
45#include "gnunet_util.h" 45#include "gnunet_util_lib.h"
46#include "gnunet_protocols.h" 46#include "gnunet_protocols.h"
47#include "gnunet_sqstore_service.h" 47#include "gnunet_datastore_service.h"
48#include "core.h"
49 48
50#define ASSERT(x) do { if (! (x)) { printf("Error at %s:%d\n", __FILE__, __LINE__); goto FAILURE;} } while (0) 49static struct GNUNET_DATASTORE_Handle *datastore;
51 50
52/** 51/**
53 * Target datastore size (in bytes). 52 * Target datastore size (in bytes).
@@ -110,7 +109,7 @@
110 * permission to the respective directory in order 109 * permission to the respective directory in order
111 * to obtain all of the performance information. 110 * to obtain all of the performance information.
112 */ 111 */
113#define DB_NAME "/tmp/gnunet-sqlite-sqstore-test/data/fs/" 112#define DB_NAME "/tmp/gnunet-datastore-test/data/fs/"
114 113
115static unsigned long long stored_bytes; 114static unsigned long long stored_bytes;
116 115
@@ -118,93 +117,81 @@ static unsigned long long stored_entries;
118 117
119static unsigned long long stored_ops; 118static unsigned long long stored_ops;
120 119
121static GNUNET_CronTime start_time; 120static struct GNUNET_TIME_Absolute start_time;
122 121
123static int 122static int
124putValue (GNUNET_SQstore_ServiceAPI * api, int i, int k) 123putValue (int i, int k)
125{ 124{
126 GNUNET_DatastoreValue *value;
127 size_t size; 125 size_t size;
128 static GNUNET_HashCode key; 126 static GNUNET_HashCode key;
129 static int ic; 127 static int ic;
128 static char data[65536];
130 129
131 /* most content is 32k */ 130 /* most content is 32k */
132 size = sizeof (GNUNET_DatastoreValue) + 32 * 1024; 131 size = 32 * 1024;
133 if (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 16) == 0) /* but some of it is less! */ 132 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16) == 0) /* but some of it is less! */
134 size = 133 size = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 32 * 1024);
135 sizeof (GNUNET_DatastoreValue) +
136 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 32 * 1024);
137 size = size - (size & 7); /* always multiple of 8 */ 134 size = size - (size & 7); /* always multiple of 8 */
138 135
139 /* generate random key */ 136 GNUNET_CRYPTO_hash (&key, sizeof (GNUNET_HashCode), &key);
140 GNUNET_hash (&key, sizeof (GNUNET_HashCode), &key); 137 memset (data, i, size);
141 value = GNUNET_malloc (size);
142 value->size = htonl (size);
143 value->type = htonl (i);
144 value->priority =
145 htonl (GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 100));
146 value->anonymity_level = htonl (i);
147 value->expiration_time =
148 GNUNET_htonll (GNUNET_get_time () +
149 GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 1000));
150 memset (&value[1], i, size - sizeof (GNUNET_DatastoreValue));
151 if (i > 255) 138 if (i > 255)
152 memset (&value[1], i - 255, (size - sizeof (GNUNET_DatastoreValue)) / 2); 139 memset (data, i - 255, size / 2);
153 ((char *) &value[1])[0] = k; 140 data[0] = k;
154 if (GNUNET_OK != api->put (&key, value)) 141 GNUNET_DATASTORE_put (datastore,
155 { 142 0,
156 GNUNET_free (value); 143 &key,
157 fprintf (stderr, "E"); 144 size,
158 return GNUNET_SYSERR; 145 data,
159 } 146 i,
147 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100),
148 i,
149 GNUNET_TIME_relative_to_absolute
150 (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
151 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000))),
152 NULL, NULL);
160 ic++; 153 ic++;
161#if REPORT_ID 154#if REPORT_ID
162 if (ic % REP_FREQ == 0) 155 if (ic % REP_FREQ == 0)
163 fprintf (stderr, "I"); 156 fprintf (stderr, "I");
164#endif 157#endif
165 stored_bytes += ntohl (value->size); 158 stored_bytes += size;
166 stored_ops++; 159 stored_ops++;
167 stored_entries++; 160 stored_entries++;
168 GNUNET_free (value);
169 return GNUNET_OK; 161 return GNUNET_OK;
170} 162}
171 163
172static int 164
173iterateDelete (const GNUNET_HashCode * key, 165static void
174 const GNUNET_DatastoreValue * val, void *cls, 166iterate_delete (void *cls,
175 unsigned long long uid) 167 const GNUNET_HashCode * key,
168 uint32_t size,
169 const void *data,
170 uint32_t type,
171 uint32_t priority,
172 uint32_t anonymity,
173 struct GNUNET_TIME_Absolute
174 expiration, uint64_t uid)
176{ 175{
177 GNUNET_SQstore_ServiceAPI *api = cls; 176 GNUNET_DATASTORE_remove (datastore, key, size, data, NULL, NULL);
178 static int dc;
179
180 if (api->getSize () < MAX_SIZE)
181 return GNUNET_SYSERR;
182 if (GNUNET_shutdown_test () == GNUNET_YES)
183 return GNUNET_SYSERR;
184 dc++;
185#if REPORT_ID
186 if (dc % REP_FREQ == 0)
187 fprintf (stderr, "D");
188#endif
189 stored_bytes -= ntohl (val->size);
190 stored_entries--;
191 return GNUNET_NO;
192} 177}
193 178
194/** 179
195 * Add testcode here! 180
196 */ 181static void
197static int 182run (void *cls,
198test (GNUNET_SQstore_ServiceAPI * api) 183 struct GNUNET_SCHEDULER_Handle *sched,
184 char *const *args,
185 const char *cfgfile, struct GNUNET_CONFIGURATION_Handle *cfg)
199{ 186{
200 int i;
201 int j; 187 int j;
202 unsigned long long size; 188 unsigned long long size;
203 int have_file; 189 int have_file;
204 struct stat sbuf; 190 struct stat sbuf;
191 int i;
205 192
193 datastore = GNUNET_DATASTORE_connect (cfg, sched);
206 have_file = 0 == stat (DB_NAME, &sbuf); 194 have_file = 0 == stat (DB_NAME, &sbuf);
207
208 for (i = 0; i < ITERATIONS; i++) 195 for (i = 0; i < ITERATIONS; i++)
209 { 196 {
210#if REPORT_ID 197#if REPORT_ID
@@ -212,18 +199,11 @@ test (GNUNET_SQstore_ServiceAPI * api)
212#endif 199#endif
213 /* insert data equivalent to 1/10th of MAX_SIZE */ 200 /* insert data equivalent to 1/10th of MAX_SIZE */
214 for (j = 0; j < PUT_10; j++) 201 for (j = 0; j < PUT_10; j++)
215 { 202 GNUNET_assert (GNUNET_OK == putValue (j, i));
216 ASSERT (GNUNET_OK == putValue (api, j, i));
217 if (GNUNET_shutdown_test () == GNUNET_YES)
218 break;
219 }
220 203
221 /* trim down below MAX_SIZE again */ 204 /* trim down below MAX_SIZE again */
222 if ((i % 2) == 0) 205 if ((i % 2) == 0)
223 api->iterateLowPriority (0, &iterateDelete, api); 206 GNUNET_DATASTORE_get_random (datastore, &iterate_delete, NULL);
224 else
225 api->iterateExpirationTime (0, &iterateDelete, api);
226
227 size = 0; 207 size = 0;
228 if (have_file) 208 if (have_file)
229 GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO); 209 GNUNET_disk_file_size (NULL, DB_NAME, &size, GNUNET_NO);
@@ -231,8 +211,8 @@ test (GNUNET_SQstore_ServiceAPI * api)
231#if REPORT_ID 211#if REPORT_ID
232 "\n" 212 "\n"
233#endif 213#endif
234 "Useful %llu, API %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n", stored_bytes / 1024, /* used size in k */ 214 "Useful %llu, disk %llu (%.2f%%) / %lluk ops / %llu ops/s\n",
235 api->getSize () / 1024, /* API-reported size in k */ 215 stored_bytes / 1024, /* used size in k */
236 size / 1024, /* disk size in kb */ 216 size / 1024, /* disk size in kb */
237 (100.0 * size / stored_bytes) - 100, /* overhead */ 217 (100.0 * size / stored_bytes) - 100, /* overhead */
238 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */ 218 (stored_ops * 2 - stored_entries) / 1024, /* total operations (in k) */
@@ -240,45 +220,68 @@ test (GNUNET_SQstore_ServiceAPI * api)
240 if (GNUNET_shutdown_test () == GNUNET_YES) 220 if (GNUNET_shutdown_test () == GNUNET_YES)
241 break; 221 break;
242 } 222 }
243 api->drop ();
244 return GNUNET_OK;
245 223
246FAILURE: 224 GNUNET_DATASTORE_disconnect (datastore, GNUNET_YES);
247 api->drop (); 225}
248 return GNUNET_SYSERR; 226
227
228static int
229check ()
230{
231 int ok = 1 + 2 + 4 + 8;
232 pid_t pid;
233 char *const argv[] = { "perf-datastore-api",
234 "-c",
235 "test_datastore_api_data.conf",
236#if VERBOSE
237 "-L", "DEBUG",
238#endif
239 NULL
240 };
241 struct GNUNET_GETOPT_CommandLineOption options[] = {
242 GNUNET_GETOPT_OPTION_END
243 };
244 pid = GNUNET_OS_start_process ("gnunet-service-datastore",
245 "gnunet-service-datastore",
246#if VERBOSE
247 "-L", "DEBUG",
248#endif
249 "-c", "perf_datastore_api_data.conf", NULL);
250 sleep (1);
251 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
252 argv, "perf-datastore-api", "nohelp",
253 options, &run, &ok);
254 if (0 != PLIBC_KILL (pid, SIGTERM))
255 {
256 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
257 ok = 1;
258 }
259 GNUNET_OS_process_wait(pid);
260 if (ok != 0)
261 fprintf (stderr, "Missed some testcases: %u\n", ok);
262 return ok;
249} 263}
250 264
265
251int 266int
252main (int argc, char *argv[]) 267main (int argc, char *argv[])
253{ 268{
254 GNUNET_SQstore_ServiceAPI *api; 269 int ret;
255 int ok;
256 struct GNUNET_GC_Configuration *cfg;
257 struct GNUNET_CronManager *cron;
258 270
259 cfg = GNUNET_GC_create (); 271 GNUNET_log_setup ("perf-datastore-api",
260 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 272#if VERBOSE
261 { 273 "DEBUG",
262 GNUNET_GC_free (cfg); 274#else
263 return -1; 275 "WARNING",
264 } 276#endif
265 cron = GNUNET_cron_create (NULL); 277 NULL);
266 GNUNET_CORE_init (NULL, cfg, cron, NULL); 278 ret = check ();
267 api = GNUNET_CORE_request_service ("sqstore"); 279
268 if (api != NULL) 280 return ret;
269 {
270 start_time = GNUNET_get_time ();
271 ok = test (api);
272 GNUNET_CORE_release_service (api);
273 }
274 else
275 ok = GNUNET_SYSERR;
276 GNUNET_CORE_done ();
277 GNUNET_cron_destroy (cron);
278 GNUNET_GC_free (cfg);
279 if (ok == GNUNET_SYSERR)
280 return 1;
281 return 0;
282} 281}
283 282
284/* end of mysqltest2.c */ 283
284
285
286
287/* end of perf_datastore_api.c */