diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_namestore_service.h | 1 | ||||
-rw-r--r-- | src/namestore/Makefile.am | 21 | ||||
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 92 | ||||
-rw-r--r-- | src/namestore/perf_namestore_api_import.c | 457 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.conf | 1 |
5 files changed, 533 insertions, 39 deletions
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index b795494af..a42619156 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -172,7 +172,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
172 | * @param cont_cls closure for @a cont | 172 | * @param cont_cls closure for @a cont |
173 | * @return handle to abort the request | 173 | * @return handle to abort the request |
174 | */ | 174 | */ |
175 | |||
176 | struct GNUNET_NAMESTORE_QueueEntry * | 175 | struct GNUNET_NAMESTORE_QueueEntry * |
177 | GNUNET_NAMESTORE_records_store2 ( | 176 | GNUNET_NAMESTORE_records_store2 ( |
178 | struct GNUNET_NAMESTORE_Handle *h, | 177 | struct GNUNET_NAMESTORE_Handle *h, |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index d5e110206..bfe4c6e22 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -36,6 +36,8 @@ SQLITE_TESTS = test_plugin_namestore_sqlite \ | |||
36 | test_namestore_api_monitoring_existing_sqlite \ | 36 | test_namestore_api_monitoring_existing_sqlite \ |
37 | test_namestore_api_zone_to_name_sqlite \ | 37 | test_namestore_api_zone_to_name_sqlite \ |
38 | perf_namestore_api_zone_iteration_sqlite \ | 38 | perf_namestore_api_zone_iteration_sqlite \ |
39 | perf_namestore_api_import_sqlite \ | ||
40 | perf_namestore_api_import_postgres \ | ||
39 | test_namestore_api_tx_rollback_sqlite | 41 | test_namestore_api_tx_rollback_sqlite |
40 | endif | 42 | endif |
41 | 43 | ||
@@ -494,6 +496,25 @@ perf_namestore_api_zone_iteration_postgres_LDADD = \ | |||
494 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | 496 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ |
495 | libgnunetnamestore.la | 497 | libgnunetnamestore.la |
496 | 498 | ||
499 | perf_namestore_api_import_sqlite_SOURCES = \ | ||
500 | perf_namestore_api_import.c | ||
501 | perf_namestore_api_import_sqlite_LDADD = \ | ||
502 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
503 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
504 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
505 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
506 | libgnunetnamestore.la | ||
507 | |||
508 | perf_namestore_api_import_postgres_SOURCES = \ | ||
509 | perf_namestore_api_import.c | ||
510 | perf_namestore_api_import_postgres_LDADD = \ | ||
511 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
512 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
513 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
514 | $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ | ||
515 | libgnunetnamestore.la | ||
516 | |||
517 | |||
497 | perf_namestore_api_zone_iteration_sqlite_SOURCES = \ | 518 | perf_namestore_api_zone_iteration_sqlite_SOURCES = \ |
498 | perf_namestore_api_zone_iteration.c | 519 | perf_namestore_api_zone_iteration.c |
499 | perf_namestore_api_zone_iteration_sqlite_LDADD = \ | 520 | perf_namestore_api_zone_iteration_sqlite_LDADD = \ |
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index fbe188122..027b19a2e 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -1128,8 +1128,9 @@ warn_monitor_slow (void *cls) | |||
1128 | * | 1128 | * |
1129 | * @param sa store activity to process | 1129 | * @param sa store activity to process |
1130 | */ | 1130 | */ |
1131 | static void | 1131 | static int |
1132 | continue_store_activity (struct StoreActivity *sa) | 1132 | continue_store_activity (struct StoreActivity *sa, |
1133 | int call_continue) | ||
1133 | { | 1134 | { |
1134 | const struct RecordSet *rd_set = sa->rs; | 1135 | const struct RecordSet *rd_set = sa->rs; |
1135 | unsigned int rd_count; | 1136 | unsigned int rd_count; |
@@ -1148,8 +1149,9 @@ continue_store_activity (struct StoreActivity *sa) | |||
1148 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1149 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1149 | "Transaction not yet committed, delaying monitor and cache updates\n"); | 1150 | "Transaction not yet committed, delaying monitor and cache updates\n"); |
1150 | send_store_response (sa->nc, GNUNET_YES, NULL, sa->rid); | 1151 | send_store_response (sa->nc, GNUNET_YES, NULL, sa->rid); |
1151 | GNUNET_SERVICE_client_continue (sa->nc->client); | 1152 | if (GNUNET_YES == call_continue) |
1152 | return; | 1153 | GNUNET_SERVICE_client_continue (sa->nc->client); |
1154 | return GNUNET_OK; | ||
1153 | } | 1155 | } |
1154 | buf = (const char *) &sa[1]; | 1156 | buf = (const char *) &sa[1]; |
1155 | for (int i = sa->rd_set_pos; i < sa->rd_set_count; i++) | 1157 | for (int i = sa->rd_set_pos; i < sa->rd_set_count; i++) |
@@ -1190,7 +1192,7 @@ continue_store_activity (struct StoreActivity *sa) | |||
1190 | &warn_monitor_slow, | 1192 | &warn_monitor_slow, |
1191 | zm); | 1193 | zm); |
1192 | GNUNET_free (conv_name); | 1194 | GNUNET_free (conv_name); |
1193 | return; /* blocked on zone monitor */ | 1195 | return GNUNET_NO; /* blocked on zone monitor */ |
1194 | } | 1196 | } |
1195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1196 | "Notifying monitor about changes under label `%s'\n", | 1198 | "Notifying monitor about changes under label `%s'\n", |
@@ -1217,9 +1219,10 @@ continue_store_activity (struct StoreActivity *sa) | |||
1217 | GNUNET_free (conv_name); | 1219 | GNUNET_free (conv_name); |
1218 | } | 1220 | } |
1219 | } | 1221 | } |
1220 | GNUNET_SERVICE_client_continue (sa->nc->client); | 1222 | if (GNUNET_YES == call_continue) |
1223 | GNUNET_SERVICE_client_continue (sa->nc->client); | ||
1221 | free_store_activity (sa); | 1224 | free_store_activity (sa); |
1222 | return; | 1225 | return GNUNET_OK; |
1223 | } | 1226 | } |
1224 | 1227 | ||
1225 | 1228 | ||
@@ -1296,7 +1299,7 @@ client_disconnect_cb (void *cls, | |||
1296 | { | 1299 | { |
1297 | sa->zm_pos = zm->next; | 1300 | sa->zm_pos = zm->next; |
1298 | /* this may free sa */ | 1301 | /* this may free sa */ |
1299 | continue_store_activity (sa); | 1302 | continue_store_activity (sa, GNUNET_YES); |
1300 | } | 1303 | } |
1301 | } | 1304 | } |
1302 | GNUNET_free (zm); | 1305 | GNUNET_free (zm); |
@@ -1705,6 +1708,8 @@ store_record_set (struct NamestoreClient *nc, | |||
1705 | struct GNUNET_TIME_Absolute new_block_exp; | 1708 | struct GNUNET_TIME_Absolute new_block_exp; |
1706 | *len = sizeof (struct RecordSet); | 1709 | *len = sizeof (struct RecordSet); |
1707 | 1710 | ||
1711 | existing_block_exp = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1712 | new_block_exp = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1708 | name_len = ntohs (rd_set->name_len); | 1713 | name_len = ntohs (rd_set->name_len); |
1709 | *len += name_len; | 1714 | *len += name_len; |
1710 | rd_count = ntohs (rd_set->rd_count); | 1715 | rd_count = ntohs (rd_set->rd_count); |
@@ -1882,15 +1887,11 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1882 | ssize_t read; | 1887 | ssize_t read; |
1883 | struct StoreActivity *sa; | 1888 | struct StoreActivity *sa; |
1884 | struct RecordSet *rs; | 1889 | struct RecordSet *rs; |
1885 | struct GNUNET_TIME_Absolute existing_block_exp; | ||
1886 | struct GNUNET_TIME_Absolute new_block_exp; | ||
1887 | enum GNUNET_GenericReturnValue res; | 1890 | enum GNUNET_GenericReturnValue res; |
1888 | int blocked = GNUNET_NO; | 1891 | int blocked = GNUNET_NO; |
1889 | 1892 | ||
1890 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1891 | "Received NAMESTORE_RECORD_STORE message\n"); | 1894 | "Received NAMESTORE_RECORD_STORE message\n"); |
1892 | existing_block_exp = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1893 | new_block_exp = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1894 | rid = ntohl (rp_msg->gns_header.r_id); | 1895 | rid = ntohl (rp_msg->gns_header.r_id); |
1895 | rd_set_count = ntohs (rp_msg->rd_set_count); | 1896 | rd_set_count = ntohs (rp_msg->rd_set_count); |
1896 | buf = (const char *) &rp_msg[1]; | 1897 | buf = (const char *) &rp_msg[1]; |
@@ -1923,7 +1924,32 @@ handle_record_store (void *cls, const struct RecordStoreMessage *rp_msg) | |||
1923 | sa->private_key = rp_msg->private_key; | 1924 | sa->private_key = rp_msg->private_key; |
1924 | sa->zm_pos = monitor_head; | 1925 | sa->zm_pos = monitor_head; |
1925 | sa->uncommited = nc->in_transaction; | 1926 | sa->uncommited = nc->in_transaction; |
1926 | continue_store_activity (sa); | 1927 | continue_store_activity (sa, GNUNET_YES); |
1928 | } | ||
1929 | |||
1930 | static void | ||
1931 | send_tx_response (int rid, int status, char *emsg, struct NamestoreClient *nc) | ||
1932 | { | ||
1933 | struct TxControlResultMessage *txr_msg; | ||
1934 | struct GNUNET_MQ_Envelope *env; | ||
1935 | char *err_tmp; | ||
1936 | size_t err_len; | ||
1937 | |||
1938 | err_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; | ||
1939 | env = | ||
1940 | GNUNET_MQ_msg_extra (txr_msg, | ||
1941 | err_len, | ||
1942 | GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT); | ||
1943 | txr_msg->gns_header.header.size = htons (sizeof (struct | ||
1944 | TxControlResultMessage) | ||
1945 | + err_len); | ||
1946 | txr_msg->gns_header.r_id = rid; | ||
1947 | txr_msg->success = htons (status); | ||
1948 | err_tmp = (char *) &txr_msg[1]; | ||
1949 | GNUNET_memcpy (err_tmp, emsg, err_len); | ||
1950 | GNUNET_free (emsg); | ||
1951 | GNUNET_MQ_send (nc->mq, env); | ||
1952 | |||
1927 | } | 1953 | } |
1928 | 1954 | ||
1929 | /** | 1955 | /** |
@@ -1936,14 +1962,11 @@ static void | |||
1936 | handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | 1962 | handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) |
1937 | { | 1963 | { |
1938 | struct NamestoreClient *nc = cls; | 1964 | struct NamestoreClient *nc = cls; |
1939 | struct TxControlResultMessage *txr_msg; | ||
1940 | struct GNUNET_MQ_Envelope *env; | ||
1941 | struct StoreActivity *sa = sa_head; | 1965 | struct StoreActivity *sa = sa_head; |
1942 | struct StoreActivity *sn; | 1966 | struct StoreActivity *sn; |
1943 | enum GNUNET_GenericReturnValue ret; | 1967 | enum GNUNET_GenericReturnValue ret; |
1944 | char *emsg = NULL; | 1968 | char *emsg = NULL; |
1945 | char *err_tmp; | 1969 | int blocked; |
1946 | size_t err_len; | ||
1947 | 1970 | ||
1948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TX_CONTROL message\n"); | 1971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received TX_CONTROL message\n"); |
1949 | 1972 | ||
@@ -1952,11 +1975,14 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | |||
1952 | case GNUNET_NAMESTORE_TX_BEGIN: | 1975 | case GNUNET_NAMESTORE_TX_BEGIN: |
1953 | ret = nc->GSN_database->transaction_begin (nc->GSN_database->cls, | 1976 | ret = nc->GSN_database->transaction_begin (nc->GSN_database->cls, |
1954 | &emsg); | 1977 | &emsg); |
1978 | send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); | ||
1979 | GNUNET_SERVICE_client_continue (nc->client); | ||
1955 | nc->in_transaction = GNUNET_YES; | 1980 | nc->in_transaction = GNUNET_YES; |
1956 | break; | 1981 | break; |
1957 | case GNUNET_NAMESTORE_TX_COMMIT: | 1982 | case GNUNET_NAMESTORE_TX_COMMIT: |
1958 | ret = nc->GSN_database->transaction_commit (nc->GSN_database->cls, | 1983 | ret = nc->GSN_database->transaction_commit (nc->GSN_database->cls, |
1959 | &emsg); | 1984 | &emsg); |
1985 | send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); | ||
1960 | if (GNUNET_SYSERR != ret) | 1986 | if (GNUNET_SYSERR != ret) |
1961 | { | 1987 | { |
1962 | nc->in_transaction = GNUNET_NO; | 1988 | nc->in_transaction = GNUNET_NO; |
@@ -1969,14 +1995,20 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | |||
1969 | continue; | 1995 | continue; |
1970 | } | 1996 | } |
1971 | sa->uncommited = GNUNET_NO; | 1997 | sa->uncommited = GNUNET_NO; |
1972 | continue_store_activity (sa); | 1998 | sn = sa->next; |
1973 | sa = sa->next; | 1999 | if (GNUNET_OK != continue_store_activity (sa, GNUNET_NO)) |
2000 | blocked = GNUNET_YES; | ||
2001 | sa = sn; | ||
1974 | } | 2002 | } |
2003 | if (GNUNET_YES != blocked) | ||
2004 | GNUNET_SERVICE_client_continue (nc->client); | ||
1975 | } | 2005 | } |
1976 | break; | 2006 | break; |
1977 | case GNUNET_NAMESTORE_TX_ROLLBACK: | 2007 | case GNUNET_NAMESTORE_TX_ROLLBACK: |
1978 | ret = nc->GSN_database->transaction_rollback (nc->GSN_database->cls, | 2008 | ret = nc->GSN_database->transaction_rollback (nc->GSN_database->cls, |
1979 | &emsg); | 2009 | &emsg); |
2010 | send_tx_response (tx_msg->gns_header.r_id, ret, emsg, nc); | ||
2011 | GNUNET_SERVICE_client_continue (nc->client); | ||
1980 | if (GNUNET_SYSERR != ret) | 2012 | if (GNUNET_SYSERR != ret) |
1981 | { | 2013 | { |
1982 | nc->in_transaction = GNUNET_NO; | 2014 | nc->in_transaction = GNUNET_NO; |
@@ -1988,7 +2020,8 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | |||
1988 | sa = sa->next; | 2020 | sa = sa->next; |
1989 | continue; | 2021 | continue; |
1990 | } | 2022 | } |
1991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Discarding uncommited StoreActivity\n"); | 2023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2024 | "Discarding uncommited StoreActivity\n"); | ||
1992 | sn = sa->next; | 2025 | sn = sa->next; |
1993 | free_store_activity (sa); | 2026 | free_store_activity (sa); |
1994 | sa = sn; | 2027 | sa = sn; |
@@ -2000,23 +2033,6 @@ handle_tx_control (void *cls, const struct TxControlMessage *tx_msg) | |||
2000 | "Unknown control type %u\n", ntohs (tx_msg->control)); | 2033 | "Unknown control type %u\n", ntohs (tx_msg->control)); |
2001 | GNUNET_break (0); | 2034 | GNUNET_break (0); |
2002 | } | 2035 | } |
2003 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2004 | "TX status is %u\n", ret); | ||
2005 | err_len = (NULL == emsg) ? 0 : strlen (emsg) + 1; | ||
2006 | env = | ||
2007 | GNUNET_MQ_msg_extra (txr_msg, | ||
2008 | err_len, | ||
2009 | GNUNET_MESSAGE_TYPE_NAMESTORE_TX_CONTROL_RESULT); | ||
2010 | txr_msg->gns_header.header.size = htons (sizeof (struct | ||
2011 | TxControlResultMessage) | ||
2012 | + err_len); | ||
2013 | txr_msg->gns_header.r_id = tx_msg->gns_header.r_id; | ||
2014 | txr_msg->success = htons (ret); | ||
2015 | err_tmp = (char *) &txr_msg[1]; | ||
2016 | GNUNET_memcpy (err_tmp, emsg, err_len); | ||
2017 | GNUNET_free (emsg); | ||
2018 | GNUNET_MQ_send (nc->mq, env); | ||
2019 | GNUNET_SERVICE_client_continue (nc->client); | ||
2020 | } | 2036 | } |
2021 | 2037 | ||
2022 | /** | 2038 | /** |
@@ -2399,7 +2415,7 @@ monitor_unblock (struct ZoneMonitor *zm) | |||
2399 | struct StoreActivity *sn = sa->next; | 2415 | struct StoreActivity *sn = sa->next; |
2400 | 2416 | ||
2401 | if (sa->zm_pos == zm) | 2417 | if (sa->zm_pos == zm) |
2402 | continue_store_activity (sa); | 2418 | continue_store_activity (sa, GNUNET_YES); |
2403 | sa = sn; | 2419 | sa = sn; |
2404 | } | 2420 | } |
2405 | if (zm->limit > zm->iteration_cnt) | 2421 | if (zm->limit > zm->iteration_cnt) |
diff --git a/src/namestore/perf_namestore_api_import.c b/src/namestore/perf_namestore_api_import.c new file mode 100644 index 000000000..a2c989ebf --- /dev/null +++ b/src/namestore/perf_namestore_api_import.c | |||
@@ -0,0 +1,457 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file namestore/perf_namestore_api_import.c | ||
22 | * @brief testcase for namestore: Import a lot of records | ||
23 | * @author Martin Schanzenbach | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_namestore_service.h" | ||
27 | #include "gnunet_testing_lib.h" | ||
28 | #include "namestore.h" | ||
29 | #include "gnunet_dnsparser_lib.h" | ||
30 | |||
31 | #define TEST_RECORD_TYPE GNUNET_DNSPARSER_TYPE_TXT | ||
32 | |||
33 | #define TEST_BATCH_COUNT 5 | ||
34 | |||
35 | #define TEST_BATCH_SIZE 1000 | ||
36 | |||
37 | #define TEST_RECORD_COUNT TEST_BATCH_COUNT * TEST_BATCH_SIZE | ||
38 | |||
39 | /** | ||
40 | * A #BENCHMARK_SIZE of 1000 takes less than a minute on a reasonably | ||
41 | * modern system, so 30 minutes should be OK even for very, very | ||
42 | * slow systems. | ||
43 | */ | ||
44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30) | ||
45 | |||
46 | /** | ||
47 | * The runtime of the benchmark is expected to be linear | ||
48 | * for the iteration phase with a *good* database. The FLAT | ||
49 | * database uses a quadratic retrieval algorithm, | ||
50 | * hence it should be quadratic in the size. | ||
51 | */ | ||
52 | #define BENCHMARK_SIZE 1000 | ||
53 | |||
54 | /** | ||
55 | * Maximum record size | ||
56 | */ | ||
57 | #define MAX_REC_SIZE 500 | ||
58 | |||
59 | /** | ||
60 | * How big are the blocks we fetch? Note that the first block is | ||
61 | * always just 1 record set per current API. Smaller block | ||
62 | * sizes will make quadratic iteration-by-offset penalties | ||
63 | * more pronounced. | ||
64 | */ | ||
65 | #define BLOCK_SIZE 100 | ||
66 | |||
67 | static struct GNUNET_NAMESTORE_Handle *nsh; | ||
68 | |||
69 | static struct GNUNET_SCHEDULER_Task *timeout_task; | ||
70 | |||
71 | static struct GNUNET_SCHEDULER_Task *t; | ||
72 | |||
73 | static struct GNUNET_IDENTITY_PrivateKey privkey; | ||
74 | |||
75 | static struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
76 | |||
77 | static int res; | ||
78 | |||
79 | static unsigned int left_until_next; | ||
80 | |||
81 | static uint8_t seen[1 + BENCHMARK_SIZE / 8]; | ||
82 | |||
83 | static struct GNUNET_TIME_Absolute start; | ||
84 | |||
85 | const struct GNUNET_GNSRECORD_Data *a_rd[TEST_RECORD_COUNT]; | ||
86 | |||
87 | unsigned int a_rd_count[TEST_RECORD_COUNT]; | ||
88 | |||
89 | const char *a_label[TEST_RECORD_COUNT]; | ||
90 | |||
91 | int single_put_pos; | ||
92 | |||
93 | static int bulk_count = 0; | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Terminate everything | ||
98 | * | ||
99 | * @param cls NULL | ||
100 | */ | ||
101 | static void | ||
102 | end (void *cls) | ||
103 | { | ||
104 | (void) cls; | ||
105 | if (NULL != qe) | ||
106 | { | ||
107 | GNUNET_NAMESTORE_cancel (qe); | ||
108 | qe = NULL; | ||
109 | } | ||
110 | if (NULL != nsh) | ||
111 | { | ||
112 | GNUNET_NAMESTORE_disconnect (nsh); | ||
113 | nsh = NULL; | ||
114 | } | ||
115 | if (NULL != t) | ||
116 | { | ||
117 | GNUNET_SCHEDULER_cancel (t); | ||
118 | t = NULL; | ||
119 | } | ||
120 | if (NULL != timeout_task) | ||
121 | { | ||
122 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
123 | timeout_task = NULL; | ||
124 | } | ||
125 | } | ||
126 | |||
127 | |||
128 | /** | ||
129 | * End with timeout. As this is a benchmark, we do not | ||
130 | * fail hard but return "skipped". | ||
131 | */ | ||
132 | static void | ||
133 | timeout (void *cls) | ||
134 | { | ||
135 | (void) cls; | ||
136 | timeout_task = NULL; | ||
137 | GNUNET_SCHEDULER_shutdown (); | ||
138 | res = 77; | ||
139 | } | ||
140 | |||
141 | |||
142 | static struct GNUNET_GNSRECORD_Data * | ||
143 | create_record (unsigned int count) | ||
144 | { | ||
145 | struct GNUNET_GNSRECORD_Data *rd; | ||
146 | |||
147 | rd = GNUNET_malloc (count + sizeof(struct GNUNET_GNSRECORD_Data)); | ||
148 | rd->expiration_time = GNUNET_TIME_relative_to_absolute ( | ||
149 | GNUNET_TIME_UNIT_HOURS).abs_value_us; | ||
150 | rd->record_type = TEST_RECORD_TYPE; | ||
151 | rd->data_size = count; | ||
152 | rd->data = (void *) &rd[1]; | ||
153 | rd->flags = 0; | ||
154 | memset (&rd[1], | ||
155 | 'a', | ||
156 | count); | ||
157 | return rd; | ||
158 | } | ||
159 | |||
160 | |||
161 | static void | ||
162 | fail_cb (void *cls) | ||
163 | { | ||
164 | res = 2; | ||
165 | GNUNET_break (0); | ||
166 | GNUNET_SCHEDULER_shutdown (); | ||
167 | } | ||
168 | |||
169 | static void | ||
170 | publish_records_single (void *cls); | ||
171 | |||
172 | static void | ||
173 | commit_cont (void *cls, | ||
174 | int32_t success, | ||
175 | const char *emsg) | ||
176 | { | ||
177 | struct GNUNET_TIME_Relative delay; | ||
178 | |||
179 | (void) cls; | ||
180 | qe = NULL; | ||
181 | if (GNUNET_OK != success) | ||
182 | { | ||
183 | GNUNET_break (0); | ||
184 | GNUNET_SCHEDULER_shutdown (); | ||
185 | return; | ||
186 | } | ||
187 | single_put_pos++; | ||
188 | delay = GNUNET_TIME_absolute_get_duration (start); | ||
189 | fprintf (stdout, | ||
190 | "BULK-TX: Publishing %u records took %s\n", | ||
191 | TEST_RECORD_COUNT, | ||
192 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
193 | GNUNET_YES)); | ||
194 | GNUNET_SCHEDULER_shutdown (); | ||
195 | } | ||
196 | |||
197 | static void | ||
198 | put_cont_bulk_tx (void *cls, | ||
199 | int32_t success, | ||
200 | const char *emsg) | ||
201 | { | ||
202 | qe = NULL; | ||
203 | if (GNUNET_OK != success) | ||
204 | { | ||
205 | GNUNET_break (0); | ||
206 | GNUNET_SCHEDULER_shutdown (); | ||
207 | return; | ||
208 | } | ||
209 | qe = GNUNET_NAMESTORE_transaction_commit (nsh, commit_cont, NULL); | ||
210 | } | ||
211 | |||
212 | |||
213 | static void | ||
214 | publish_records_bulk_tx (void *cls); | ||
215 | |||
216 | static void | ||
217 | reput_cont_bulk_tx (void *cls, | ||
218 | int32_t success, | ||
219 | const char *emsg) | ||
220 | { | ||
221 | (void) cls; | ||
222 | qe = NULL; | ||
223 | if (GNUNET_OK != success) | ||
224 | { | ||
225 | GNUNET_break (0); | ||
226 | GNUNET_SCHEDULER_shutdown (); | ||
227 | return; | ||
228 | } | ||
229 | t = GNUNET_SCHEDULER_add_now (&publish_records_bulk_tx, NULL); | ||
230 | |||
231 | |||
232 | } | ||
233 | |||
234 | static void | ||
235 | publish_records_bulk_tx (void *cls) | ||
236 | { | ||
237 | t = NULL; | ||
238 | qe = GNUNET_NAMESTORE_records_store2 (nsh, | ||
239 | &privkey, | ||
240 | TEST_BATCH_SIZE, | ||
241 | &a_label[bulk_count * TEST_BATCH_SIZE], | ||
242 | &a_rd_count[bulk_count * TEST_BATCH_SIZE], | ||
243 | &a_rd[bulk_count * TEST_BATCH_SIZE], | ||
244 | (bulk_count == TEST_BATCH_COUNT - 1) ? &put_cont_bulk_tx : | ||
245 | &reput_cont_bulk_tx, | ||
246 | NULL); | ||
247 | bulk_count++; | ||
248 | |||
249 | } | ||
250 | |||
251 | |||
252 | static void | ||
253 | begin_cont (void *cls, | ||
254 | int32_t success, | ||
255 | const char *emsg) | ||
256 | { | ||
257 | qe = GNUNET_NAMESTORE_records_store2 (nsh, | ||
258 | &privkey, | ||
259 | TEST_BATCH_SIZE, | ||
260 | &a_label[bulk_count * TEST_BATCH_SIZE], | ||
261 | &a_rd_count[bulk_count * TEST_BATCH_SIZE], | ||
262 | &a_rd[bulk_count * TEST_BATCH_SIZE], | ||
263 | (bulk_count == TEST_BATCH_COUNT - 1) ? &put_cont_bulk_tx : | ||
264 | &reput_cont_bulk_tx, | ||
265 | NULL); | ||
266 | bulk_count++; | ||
267 | |||
268 | } | ||
269 | |||
270 | static void | ||
271 | put_cont_bulk (void *cls, | ||
272 | int32_t success, | ||
273 | const char *emsg) | ||
274 | { | ||
275 | struct GNUNET_TIME_Relative delay; | ||
276 | |||
277 | (void) cls; | ||
278 | qe = NULL; | ||
279 | if (GNUNET_OK != success) | ||
280 | { | ||
281 | GNUNET_break (0); | ||
282 | GNUNET_SCHEDULER_shutdown (); | ||
283 | return; | ||
284 | } | ||
285 | |||
286 | delay = GNUNET_TIME_absolute_get_duration (start); | ||
287 | fprintf (stdout, | ||
288 | "BULK: Publishing %u records took %s\n", | ||
289 | TEST_RECORD_COUNT, | ||
290 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
291 | GNUNET_YES)); | ||
292 | start = GNUNET_TIME_absolute_get (); | ||
293 | bulk_count = 0; | ||
294 | qe = GNUNET_NAMESTORE_transaction_begin (nsh, begin_cont, NULL); | ||
295 | |||
296 | } | ||
297 | |||
298 | static void | ||
299 | publish_records_bulk (void *cls); | ||
300 | |||
301 | static void | ||
302 | reput_cont_bulk (void *cls, | ||
303 | int32_t success, | ||
304 | const char *emsg) | ||
305 | { | ||
306 | struct GNUNET_TIME_Relative delay; | ||
307 | |||
308 | (void) cls; | ||
309 | qe = NULL; | ||
310 | if (GNUNET_OK != success) | ||
311 | { | ||
312 | GNUNET_break (0); | ||
313 | GNUNET_SCHEDULER_shutdown (); | ||
314 | return; | ||
315 | } | ||
316 | t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); | ||
317 | |||
318 | } | ||
319 | |||
320 | |||
321 | static void | ||
322 | publish_records_bulk (void *cls) | ||
323 | { | ||
324 | (void) cls; | ||
325 | t = NULL; | ||
326 | qe = GNUNET_NAMESTORE_records_store2 (nsh, | ||
327 | &privkey, | ||
328 | TEST_BATCH_SIZE, | ||
329 | &a_label[bulk_count * TEST_BATCH_SIZE], | ||
330 | &a_rd_count[bulk_count * TEST_BATCH_SIZE], | ||
331 | &a_rd[bulk_count * TEST_BATCH_SIZE], | ||
332 | (bulk_count == TEST_BATCH_COUNT - 1) ? &put_cont_bulk : | ||
333 | &reput_cont_bulk, | ||
334 | NULL); | ||
335 | bulk_count++; | ||
336 | } | ||
337 | |||
338 | |||
339 | static void | ||
340 | put_cont_single (void *cls, | ||
341 | int32_t success, | ||
342 | const char *emsg) | ||
343 | { | ||
344 | struct GNUNET_TIME_Relative delay; | ||
345 | (void) cls; | ||
346 | qe = NULL; | ||
347 | if (GNUNET_OK != success) | ||
348 | { | ||
349 | GNUNET_break (0); | ||
350 | GNUNET_SCHEDULER_shutdown (); | ||
351 | return; | ||
352 | } | ||
353 | single_put_pos++; | ||
354 | if (single_put_pos == TEST_RECORD_COUNT) | ||
355 | { | ||
356 | delay = GNUNET_TIME_absolute_get_duration (start); | ||
357 | fprintf (stdout, | ||
358 | "SINGLE: Publishing %u records took %s\n", | ||
359 | TEST_RECORD_COUNT, | ||
360 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
361 | GNUNET_YES)); | ||
362 | start = GNUNET_TIME_absolute_get (); | ||
363 | t = GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); | ||
364 | return; | ||
365 | } | ||
366 | t = GNUNET_SCHEDULER_add_now (&publish_records_single, | ||
367 | NULL); | ||
368 | } | ||
369 | |||
370 | |||
371 | static void | ||
372 | publish_records_single (void *cls) | ||
373 | { | ||
374 | struct GNUNET_GNSRECORD_Data *rd; | ||
375 | struct GNUNET_TIME_Relative delay; | ||
376 | |||
377 | char *label; | ||
378 | |||
379 | (void) cls; | ||
380 | t = NULL; | ||
381 | if (single_put_pos == TEST_RECORD_COUNT) | ||
382 | { | ||
383 | delay = GNUNET_TIME_absolute_get_duration (start); | ||
384 | fprintf (stdout, | ||
385 | "Publishing %u records took %s\n", | ||
386 | TEST_RECORD_COUNT, | ||
387 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
388 | GNUNET_YES)); | ||
389 | GNUNET_SCHEDULER_add_now (&publish_records_bulk, NULL); | ||
390 | } | ||
391 | qe = GNUNET_NAMESTORE_records_store (nsh, | ||
392 | &privkey, | ||
393 | a_label[single_put_pos], | ||
394 | a_rd_count[single_put_pos], | ||
395 | a_rd[single_put_pos], | ||
396 | &put_cont_single, | ||
397 | NULL); | ||
398 | GNUNET_free (label); | ||
399 | GNUNET_free (rd); | ||
400 | } | ||
401 | |||
402 | |||
403 | static void | ||
404 | run (void *cls, | ||
405 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
406 | struct GNUNET_TESTING_Peer *peer) | ||
407 | { | ||
408 | |||
409 | for (int i = 0; i < TEST_RECORD_COUNT; i++) | ||
410 | { | ||
411 | a_rd[i] = create_record (1); | ||
412 | a_rd_count[i] = 1; | ||
413 | GNUNET_asprintf ((char**) &a_label[i], "label_%d", i); | ||
414 | } | ||
415 | GNUNET_SCHEDULER_add_shutdown (&end, | ||
416 | NULL); | ||
417 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
418 | &timeout, | ||
419 | NULL); | ||
420 | nsh = GNUNET_NAMESTORE_connect (cfg); | ||
421 | GNUNET_assert (NULL != nsh); | ||
422 | privkey.type = htonl (GNUNET_GNSRECORD_TYPE_PKEY); | ||
423 | GNUNET_CRYPTO_ecdsa_key_create (&privkey.ecdsa_key); | ||
424 | start = GNUNET_TIME_absolute_get (); | ||
425 | t = GNUNET_SCHEDULER_add_now (&publish_records_single, | ||
426 | NULL); | ||
427 | } | ||
428 | |||
429 | |||
430 | #include "test_common.c" | ||
431 | |||
432 | |||
433 | int | ||
434 | main (int argc, | ||
435 | char *argv[]) | ||
436 | { | ||
437 | const char *plugin_name; | ||
438 | char *cfg_name; | ||
439 | |||
440 | SETUP_CFG (plugin_name, cfg_name); | ||
441 | res = 1; | ||
442 | if (0 != | ||
443 | GNUNET_TESTING_peer_run ("perf-namestore-api-import", | ||
444 | cfg_name, | ||
445 | &run, | ||
446 | NULL)) | ||
447 | { | ||
448 | res = 1; | ||
449 | } | ||
450 | GNUNET_DISK_purge_cfg_dir (cfg_name, | ||
451 | "GNUNET_TEST_HOME"); | ||
452 | GNUNET_free (cfg_name); | ||
453 | return res; | ||
454 | } | ||
455 | |||
456 | |||
457 | /* end of perf_namestore_api_zone_iteration.c */ | ||
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index ec685e2fe..f79c91dc1 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -7,6 +7,7 @@ GNUNET_TEST_HOME = $GNUNET_TMP/test-gnunet-namestore/ | |||
7 | [namestore] | 7 | [namestore] |
8 | DATABASE = sqlite | 8 | DATABASE = sqlite |
9 | START_ON_DEMAND = YES | 9 | START_ON_DEMAND = YES |
10 | #PREFIX = valgrind --track-origins=yes --log-file=/tmp/ns_tx.log | ||
10 | 11 | ||
11 | [namecache] | 12 | [namecache] |
12 | DATABASE = sqlite | 13 | DATABASE = sqlite |