eupdate.usp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--#
  2. Test type 5: Database updates
  3. TechEmpower Web Framework Benchmarks
  4. -->
  5. <!--#declaration
  6. #include "world.h"
  7. static char* pbuffer1;
  8. static char* pbuffer2;
  9. static char buffer1[128];
  10. static char buffer2[128];
  11. static UElasticSearchClient* es;
  12. #ifndef AS_cpoll_cppsp_DO
  13. static UValue* pvalue;
  14. static UVector<World*>* pvworld_update;
  15. #endif
  16. #define ULEN U_CONSTANT_SIZE("/tfb/world/")
  17. #define QLEN U_CONSTANT_SIZE("{\"doc\":{\"_id\":\"")
  18. static void usp_fork_eupdate()
  19. {
  20. U_TRACE(5, "::usp_fork_eupdate()")
  21. U_NEW(UElasticSearchClient, es, UElasticSearchClient);
  22. if (es->connect() == false)
  23. {
  24. U_WARNING("usp_fork_eupdate(): connection disabled or failed");
  25. return;
  26. }
  27. U_MEMCPY(buffer1, "/tfb/world/", ULEN);
  28. pbuffer1 = buffer1 + ULEN;
  29. U_MEMCPY(buffer2, "{\"doc\":{\"_id\":\"", QLEN);
  30. pbuffer2 = buffer2 + QLEN;
  31. #ifndef AS_cpoll_cppsp_DO
  32. U_NEW(UValue, pvalue, UValue);
  33. U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
  34. #endif
  35. }
  36. #ifdef DEBUG
  37. static void usp_end_eupdate()
  38. {
  39. U_TRACE(5, "::usp_end_eupdate()")
  40. delete es;
  41. #ifndef AS_cpoll_cppsp_DO
  42. if (pvalue)
  43. {
  44. delete pvalue;
  45. delete pvworld_update;
  46. }
  47. #endif
  48. }
  49. #endif
  50. -->
  51. <!--#header
  52. Content-Type: application/json
  53. -->
  54. <!--#code
  55. uint32_t len1, len2, id, rnum;
  56. int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
  57. #ifdef AS_cpoll_cppsp_DO
  58. USP_PUTS_CHAR('[');
  59. #endif
  60. while (true)
  61. {
  62. len1 = u__snprintf(pbuffer1, 100, U_CONSTANT_TO_PARAM("%u/_update"), id = u_get_num_random(10000-1));
  63. len2 = u__snprintf(pbuffer2, 100, U_CONSTANT_TO_PARAM("%u\"}}"), rnum = u_get_num_random(10000-1));
  64. (void) es->sendPOST(buffer1, len1+ULEN, buffer2, len2+QLEN);
  65. #ifdef AS_cpoll_cppsp_DO
  66. USP_PRINTF("{\"id\":%u,\"randomNumber\":%u}", id, rnum);
  67. #else
  68. World* pworld;
  69. U_NEW(World, pworld, World(id, rnum));
  70. pvworld_update->push_back(pworld);
  71. #endif
  72. if (++i == num_queries) break;
  73. #ifdef AS_cpoll_cppsp_DO
  74. USP_PUTS_CHAR(',');
  75. #endif
  76. }
  77. #ifdef AS_cpoll_cppsp_DO
  78. USP_PUTS_CHAR(']');
  79. #else
  80. USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_update);
  81. pvalue->clear();
  82. pvworld_update->clear();
  83. #endif
  84. -->