queries.usp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!--#
  2. Test 3: Multiple database queries
  3. This test is a variation of Test #2 and also uses the World table. Multiple rows are fetched to more dramatically
  4. punish the database driver and connection pool. At the highest queries-per-request tested (20), this test demonstrates
  5. all frameworks' convergence toward zero requests-per-second as database activity increases.
  6. Requirements
  7. 1. For every request, an integer query string parameter named queries must be retrieved from the request.
  8. The parameter specifies the number of database queries to execute in preparing the HTTP response (see below).
  9. 2. The recommended URI is /queries.
  10. 3. The queries parameter must be bounded to between 1 and 500. If the parameter is missing, is not an integer,
  11. or is an integer less than 1, the value should be interpreted as 1; if greater than 500, the value should be interpreted as 500.
  12. 3. The schema for World is id (int, primary key) and randomNumber (int).
  13. 4. The request handler must retrieve a set of World objects, equal in count to the queries parameter, from the World database table.
  14. 5. Each row must be selected randomly in the same fashion as the single database query test (Test #2 above).
  15. 6. Since this test is designed to exercise multiple queries, each row must be selected individually by a query.
  16. It is not acceptable to retrieve all required rows using a SELECT ... WHERE id IN (...) clause.
  17. 7. Each World object must be added to a list or array.
  18. 8. The list or array must be serialized to JSON and sent as a response.
  19. 9. The response content type must be set to application/json.
  20. 10. The response headers must include either Content-Length or Transfer-Encoding.
  21. 11. The response headers must include Server and Date.
  22. 12. Use of an in-memory cache of World objects or rows by the application is not permitted.
  23. 13. Use of prepared statements for SQL database tests (e.g., for MySQL) is encouraged but not required.
  24. 14. gzip compression is not permitted.
  25. 15. Server support for HTTP Keep-Alive is strongly encouraged but not required.
  26. 16. If HTTP Keep-Alive is enabled, no maximum Keep-Alive timeout is specified by this test.
  27. 17. The request handler will be exercised at 256 concurrency only.
  28. 18. The request handler will be exercised with query counts of 1, 5, 10, 15, and 20.
  29. 19. The request handler will be exercised using GET requests.
  30. Example request:
  31. GET /queries?queries=10 HTTP/1.1
  32. Host: server
  33. User-Agent: Mozilla/5.0 (X11; Linux x86_64) Gecko/20130501 Firefox/30.0 AppleWebKit/600.00 Chrome/30.0.0000.0 Trident/10.0 Safari/600.00
  34. Cookie: uid=12345678901234567890; __utma=1.1234567890.1234567890.1234567890.1234567890.12; wd=2560x1600
  35. Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  36. Accept-Language: en-US,en;q=0.5
  37. Connection: keep-alive
  38. Example response:
  39. HTTP/1.1 200 OK
  40. Content-Type: application/json; charset=UTF-8
  41. Content-Length: 315
  42. Server: Example
  43. Date: Wed, 17 Apr 2013 12:00:00 GMT
  44. [{"id":4174,"randomNumber":331},{"id":51,"randomNumber":6544},{"id":4462,"randomNumber":952},{"id":2221,"randomNumber":532},{"id":9276,"randomNumber":3097},{"id":3056,"randomNumber":7293},{"id":6964,"randomNumber":620},{"id":675,"randomNumber":6601},{"id":8414,"randomNumber":6569},{"id":2753,"randomNumber":4065}]
  45. -->
  46. <!--#declaration
  47. #include "world.h"
  48. #define AS_cpoll_cppsp_DO
  49. #ifndef AS_cpoll_cppsp_DO
  50. static UValue* pvalue;
  51. #endif
  52. static UOrmSession* psql_queries;
  53. static UOrmStatement* pstmt_queries;
  54. static World* pworld_queries;
  55. static UVector<World*>* pvworld_queries;
  56. static void usp_init_queries()
  57. {
  58. U_TRACE(5, "::usp_init_queries()")
  59. psql_queries = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
  60. pstmt_queries = U_NEW(UOrmStatement(*psql_queries, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
  61. if (pstmt_queries == 0) U_ERROR("usp_init_queries(): we cound't connect to db, exiting...");
  62. pworld_queries = U_NEW(World);
  63. pvworld_queries = U_NEW(UVector<World*>(500));
  64. pstmt_queries->use( pworld_queries->id);
  65. pstmt_queries->into(pworld_queries->randomNumber);
  66. #ifndef AS_cpoll_cppsp_DO
  67. pvalue = U_NEW(UValue(ARRAY_VALUE));
  68. #endif
  69. }
  70. static void usp_end_queries()
  71. {
  72. U_TRACE(5, "::usp_end_queries()")
  73. delete pstmt_queries;
  74. delete psql_queries;
  75. delete pvworld_queries;
  76. delete pworld_queries;
  77. #ifndef AS_cpoll_cppsp_DO
  78. delete pvalue;
  79. #endif
  80. }
  81. -->
  82. <!--#args
  83. queries;
  84. -->
  85. <!--#header
  86. Content-Type: application/json; charset=UTF-8
  87. -->
  88. <!--#code
  89. int i = 0, num_queries = queries.strtol();
  90. if (num_queries < 1) num_queries = 1;
  91. else if (num_queries > 500) num_queries = 500;
  92. #ifdef AS_cpoll_cppsp_DO
  93. USP_PUTS_CHAR('[');
  94. #endif
  95. while (true)
  96. {
  97. pworld_queries->id = u_get_num_random(10000);
  98. pstmt_queries->execute();
  99. #ifdef AS_cpoll_cppsp_DO
  100. USP_PRINTF("{\"id\":%d,\"randomNumber\":%d}", pworld_queries->id, pworld_queries->randomNumber);
  101. #endif
  102. pvworld_queries->push_back(U_NEW(World(*pworld_queries)));
  103. if (++i == num_queries) break;
  104. #ifdef AS_cpoll_cppsp_DO
  105. USP_PUTS_CHAR(',');
  106. #endif
  107. }
  108. #ifdef AS_cpoll_cppsp_DO
  109. USP_PUTS_CHAR(']');
  110. #else
  111. USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_queries);
  112. #endif
  113. pvworld_queries->clear();
  114. -->