123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <!--#
- Test type 3: Multiple database queries
- TechEmpower Web Framework Benchmarks
- -->
- <!--#declaration
- #include "world.h"
- static char buffer[128];
- static UElasticSearchClient* es;
- #ifndef AS_cpoll_cppsp_DO
- static UValue* pvalue;
- static UVector<World*>* pvworld_query;
- #endif
- #define QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
- static void usp_fork_equery()
- {
- U_TRACE(5, "::usp_fork_equery()")
- U_NEW(UElasticSearchClient, es, UElasticSearchClient);
- if (es->connect() == false)
- {
- U_WARNING("usp_fork_equery(): connection disabled or failed");
- return;
- }
- u__memcpy(buffer, "{\"query\":{\"match\":{\"_id\":\"", QLEN, __PRETTY_FUNCTION__);
- #ifndef AS_cpoll_cppsp_DO
- U_NEW(UValue, pvalue, UValue(ARRAY_VALUE));
- U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
- #endif
- }
- #ifdef DEBUG
- static void usp_end_equery()
- {
- U_TRACE(5, "::usp_end_equery()")
- delete es;
- #ifndef AS_cpoll_cppsp_DO
- if (pvalue)
- {
- delete pvalue;
- delete pvworld_query;
- }
- #endif
- }
- #endif
- -->
- <!--#header
- Content-Type: application/json
- -->
- <!--#code
- uint32_t id;
- UString rnumber;
- int i = 0, num_queries = UHTTP::getFormFirstNumericValue(1, 500);
- #ifdef AS_cpoll_cppsp_DO
- USP_PUTS_CHAR('[');
- #endif
- while (true)
- {
- (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)));
- rnumber.clear();
- (void) UValue::jfind(es->getContent(), U_CONSTANT_TO_PARAM("randomNumber"), rnumber);
- #ifdef AS_cpoll_cppsp_DO
- USP_PRINTF("{\"id\":%u,\"randomNumber\":%v}", id, rnumber.rep);
- #else
- World* pworld;
- U_NEW(World, pworld, World(id, u_strtoul(rnumber.data(), rnumber.end())));
- pvworld_query->push_back(pworld);
- #endif
- if (++i == num_queries) break;
- #ifdef AS_cpoll_cppsp_DO
- USP_PUTS_CHAR(',');
- #endif
- rnumber.clear();
- }
- #ifdef AS_cpoll_cppsp_DO
- USP_PUTS_CHAR(']');
- #else
- USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
- pvalue->clear();
- pvworld_query->clear();
- #endif
- -->
|