equery.usp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!--#
  2. Test type 3: Multiple database queries
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. #include "world.h"
  7. static char buffer[128];
  8. static UElasticSearchClient* es;
  9. #ifndef AS_cpoll_cppsp_DO
  10. static UValue* pvalue;
  11. static UVector<World*>* pvworld_query;
  12. #endif
  13. #define QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
  14. static void usp_fork_equery()
  15. {
  16. U_TRACE(5, "::usp_fork_equery()")
  17. U_NEW(UElasticSearchClient, es, UElasticSearchClient);
  18. if (es->connect() == false)
  19. {
  20. U_WARNING("usp_fork_equery(): connection disabled or failed");
  21. return;
  22. }
  23. u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
  24. #ifndef AS_cpoll_cppsp_DO
  25. U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
  26. U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
  27. #endif
  28. }
  29. #ifdef DEBUG
  30. static void usp_end_equery()
  31. {
  32. U_TRACE(5, "::usp_end_equery()")
  33. delete es;
  34. #ifndef AS_cpoll_cppsp_DO
  35. if (pvalue)
  36. {
  37. delete pvalue;
  38. delete pvworld_query;
  39. }
  40. #endif
  41. }
  42. #endif
  43. -->
  44. <!--#header
  45. Content-Type: application/json
  46. -->
  47. <!--#code
  48. uint32_t id;
  49. UString rnumber;
  50. int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
  51. #ifdef AS_cpoll_cppsp_DO
  52. USP_PUTS_CHAR('[');
  53. #endif
  54. while (true)
  55. {
  56. (void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), buffer, QLEN+u__snprintf(buffer+QLEN, 128, "%u\"}}}", id = u_get_num_random(10000-1)));
  57. rnumber.clear();
  58. (void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
  59. #ifdef AS_cpoll_cppsp_DO
  60. USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
  61. #else
  62. World* pworld;
  63. U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
  64. pvworld_query->push_back(pworld);
  65. #endif
  66. if (++i == num_queries) break;
  67. #ifdef AS_cpoll_cppsp_DO
  68. USP_PUTS_CHAR(',');
  69. #endif
  70. rnumber.clear();
  71. }
  72. #ifdef AS_cpoll_cppsp_DO
  73. USP_PUTS_CHAR(']');
  74. #else
  75. USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
  76. pvalue->clear();
  77. pvworld_query->clear();
  78. #endif
  79. -->