diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-06-05 12:05:13 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-06-05 12:05:13 +0000 |
commit | d33c98924608b9aa01fe5e77330a7d7f11849acb (patch) | |
tree | 4dea172fdc5fcec35db6d71d4457d4f811313d11 /src/peerstore | |
parent | ed152ee424088c09368b865afaa1117f0a207963 (diff) | |
download | gnunet-d33c98924608b9aa01fe5e77330a7d7f11849acb.tar.gz gnunet-d33c98924608b9aa01fe5e77330a7d7f11849acb.zip |
peerstore: stress test + minor fix
Diffstat (limited to 'src/peerstore')
-rw-r--r-- | src/peerstore/Makefile.am | 10 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 1 | ||||
-rw-r--r-- | src/peerstore/peerstore_api.c | 6 | ||||
-rw-r--r-- | src/peerstore/peerstore_common.c | 2 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_stress_store.c | 120 |
5 files changed, 132 insertions, 7 deletions
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index 5b3c918db..1defd0c72 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am | |||
@@ -67,7 +67,8 @@ libgnunet_plugin_peerstore_sqlite_la_DEPENDENCIES = \ | |||
67 | check_PROGRAMS = \ | 67 | check_PROGRAMS = \ |
68 | test_peerstore_api_store \ | 68 | test_peerstore_api_store \ |
69 | test_peerstore_api_iterate \ | 69 | test_peerstore_api_iterate \ |
70 | test_peerstore_api_watch | 70 | test_peerstore_api_watch \ |
71 | test_peerstore_stress_store | ||
71 | 72 | ||
72 | if ENABLE_TEST_RUN | 73 | if ENABLE_TEST_RUN |
73 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; | 74 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH; |
@@ -94,3 +95,10 @@ test_peerstore_api_watch_LDADD = \ | |||
94 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | 95 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ |
95 | $(top_builddir)/src/testing/libgnunettesting.la \ | 96 | $(top_builddir)/src/testing/libgnunettesting.la \ |
96 | $(top_builddir)/src/util/libgnunetutil.la | 97 | $(top_builddir)/src/util/libgnunetutil.la |
98 | |||
99 | test_peerstore_stress_store_SOURCES = \ | ||
100 | test_peerstore_stress_store.c | ||
101 | test_peerstore_stress_store_LDADD = \ | ||
102 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | ||
103 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
104 | $(top_builddir)/src/util/libgnunetutil.la | ||
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 082ab38ac..c620bd57b 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -202,7 +202,6 @@ void watch_notifier (struct GNUNET_PEERSTORE_Record *record) | |||
202 | { | 202 | { |
203 | struct GNUNET_HashCode keyhash; | 203 | struct GNUNET_HashCode keyhash; |
204 | 204 | ||
205 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending update to any watchers.\n"); | ||
206 | PEERSTORE_hash_key(record->sub_system, | 205 | PEERSTORE_hash_key(record->sub_system, |
207 | record->peer, | 206 | record->peer, |
208 | record->key, | 207 | record->key, |
diff --git a/src/peerstore/peerstore_api.c b/src/peerstore/peerstore_api.c index 0143c58cc..ea8579517 100644 --- a/src/peerstore/peerstore_api.c +++ b/src/peerstore/peerstore_api.c | |||
@@ -387,8 +387,6 @@ void store_request_sent (void *cls) | |||
387 | void | 387 | void |
388 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) | 388 | GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc) |
389 | { | 389 | { |
390 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
391 | "Canceling store request.\n"); | ||
392 | if(NULL != sc->ev) | 390 | if(NULL != sc->ev) |
393 | { | 391 | { |
394 | GNUNET_MQ_send_cancel(sc->ev); | 392 | GNUNET_MQ_send_cancel(sc->ev); |
@@ -548,7 +546,6 @@ void iterate_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
548 | void | 546 | void |
549 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) | 547 | GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic) |
550 | { | 548 | { |
551 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Canceling iterate request.\n"); | ||
552 | if(GNUNET_SCHEDULER_NO_TASK != ic->timeout_task) | 549 | if(GNUNET_SCHEDULER_NO_TASK != ic->timeout_task) |
553 | { | 550 | { |
554 | GNUNET_SCHEDULER_cancel(ic->timeout_task); | 551 | GNUNET_SCHEDULER_cancel(ic->timeout_task); |
@@ -728,7 +725,8 @@ GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, | |||
728 | GNUNET_CONTAINER_multihashmap_put(h->watches, &wc->keyhash, | 725 | GNUNET_CONTAINER_multihashmap_put(h->watches, &wc->keyhash, |
729 | wc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 726 | wc, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
730 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 727 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
731 | "Sending a watch request for sub system `%s'.\n", sub_system); | 728 | "Sending a watch request for ss `%s', peer `%s', key `%s'.\n", |
729 | sub_system, GNUNET_i2s(peer), key); | ||
732 | GNUNET_MQ_notify_sent(ev, &watch_request_sent, wc); | 730 | GNUNET_MQ_notify_sent(ev, &watch_request_sent, wc); |
733 | GNUNET_MQ_send(h->mq, ev); | 731 | GNUNET_MQ_send(h->mq, ev); |
734 | return wc; | 732 | return wc; |
diff --git a/src/peerstore/peerstore_common.c b/src/peerstore/peerstore_common.c index 48c04010a..384a68f39 100644 --- a/src/peerstore/peerstore_common.c +++ b/src/peerstore/peerstore_common.c | |||
@@ -44,7 +44,7 @@ PEERSTORE_hash_key(const char *sub_system, | |||
44 | 44 | ||
45 | sssize = strlen(sub_system) + 1; | 45 | sssize = strlen(sub_system) + 1; |
46 | psize = sizeof(struct GNUNET_PeerIdentity); | 46 | psize = sizeof(struct GNUNET_PeerIdentity); |
47 | ksize = strlen(sub_system) + 1; | 47 | ksize = strlen(key) + 1; |
48 | totalsize = sssize + psize + ksize; | 48 | totalsize = sssize + psize + ksize; |
49 | block = GNUNET_malloc(totalsize); | 49 | block = GNUNET_malloc(totalsize); |
50 | blockptr = block; | 50 | blockptr = block; |
diff --git a/src/peerstore/test_peerstore_stress_store.c b/src/peerstore/test_peerstore_stress_store.c new file mode 100644 index 000000000..523274c16 --- /dev/null +++ b/src/peerstore/test_peerstore_stress_store.c | |||
@@ -0,0 +1,120 @@ | |||
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/test_peerstore_stress_store.c | ||
22 | * @brief stress 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 100 | ||
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_Absolute end; | ||
104 | struct GNUNET_TIME_Relative diff; | ||
105 | |||
106 | start = GNUNET_TIME_absolute_get(); | ||
107 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", | ||
108 | "peerstore", | ||
109 | "test_peerstore_api_data.conf", | ||
110 | &run, NULL)) | ||
111 | return 1; | ||
112 | end = GNUNET_TIME_absolute_get(); | ||
113 | diff = GNUNET_TIME_absolute_get_difference(start, end); | ||
114 | printf("Stored and retrieved %d records in %s (%s).\n", | ||
115 | STORES, GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_YES), | ||
116 | GNUNET_STRINGS_relative_time_to_string(diff, GNUNET_NO)); | ||
117 | return ok; | ||
118 | } | ||
119 | |||
120 | /* end of test_peerstore_stress.c */ | ||