perf_peerstore_store.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C)
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file peerstore/perf_peerstore_store.c
  18. * @brief performance test for peerstore store operation
  19. */
  20. #include "platform.h"
  21. #include "gnunet_util_lib.h"
  22. #include "gnunet_testing_lib.h"
  23. #include "gnunet_peerstore_service.h"
  24. #define STORES 10000
  25. static int ok = 1;
  26. static struct GNUNET_PEERSTORE_Handle *h;
  27. static char *ss = "test_peerstore_stress";
  28. static struct GNUNET_PeerIdentity p;
  29. static char *k = "test_peerstore_stress_key";
  30. static char *v = "test_peerstore_stress_val";
  31. static int count = 0;
  32. static void
  33. disconnect ()
  34. {
  35. if (NULL != h)
  36. GNUNET_PEERSTORE_disconnect (h, GNUNET_YES);
  37. GNUNET_SCHEDULER_shutdown ();
  38. }
  39. static void
  40. store ()
  41. {
  42. GNUNET_PEERSTORE_store (h, ss, &p, k, v, strlen (v) + 1,
  43. GNUNET_TIME_UNIT_FOREVER_ABS,
  44. (count ==
  45. 0) ? GNUNET_PEERSTORE_STOREOPTION_REPLACE :
  46. GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
  47. count++;
  48. }
  49. static void
  50. watch_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record,
  51. const char *emsg)
  52. {
  53. GNUNET_assert (NULL == emsg);
  54. if (STORES == count)
  55. {
  56. ok = 0;
  57. disconnect ();
  58. }
  59. else
  60. store ();
  61. }
  62. static void
  63. run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
  64. struct GNUNET_TESTING_Peer *peer)
  65. {
  66. memset (&p, 5, sizeof(p));
  67. h = GNUNET_PEERSTORE_connect (cfg);
  68. GNUNET_assert (NULL != h);
  69. GNUNET_PEERSTORE_watch (h, ss, &p, k, &watch_cb, NULL);
  70. store ();
  71. }
  72. int
  73. main (int argc, char *argv[])
  74. {
  75. struct GNUNET_TIME_Absolute start;
  76. struct GNUNET_TIME_Relative diff;
  77. start = GNUNET_TIME_absolute_get ();
  78. if (0 !=
  79. GNUNET_TESTING_service_run ("perf-peerstore-store", "peerstore",
  80. "test_peerstore_api_data.conf", &run, NULL))
  81. return 1;
  82. diff = GNUNET_TIME_absolute_get_duration (start);
  83. fprintf (stderr, "Stored and retrieved %d records in %s (%s).\n", STORES,
  84. GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_YES),
  85. GNUNET_STRINGS_relative_time_to_string (diff, GNUNET_NO));
  86. return ok;
  87. }
  88. /* end of perf_peerstore_store.c */