瀏覽代碼

ULib: code and setup update (#2803)

stefano casazza 8 年之前
父節點
當前提交
58aded18e6

+ 36 - 0
frameworks/C++/ulib/benchmark_config.json

@@ -19,6 +19,24 @@
       "notes": "",
       "versus": ""
     },
+    "plaintext_fit": {
+      "setup_file": "setup_plaintext_fit",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "None",
+      "framework": "ULib",
+      "language": "C++",
+      "orm": "Micro",
+      "platform": "None",
+      "webserver": "ULib",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "ULib-fit",
+      "notes": "",
+      "versus": ""
+    },
     "json": {
       "setup_file": "setup_json",
       "json_url": "/json",
@@ -37,6 +55,24 @@
       "notes": "",
       "versus": ""
     },
+    "json_fit": {
+      "setup_file": "setup_json_fit",
+      "json_url": "/json",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "database": "None",
+      "framework": "ULib",
+      "language": "C++",
+      "orm": "Micro",
+      "platform": "None",
+      "webserver": "ULib",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "ULib-fit",
+      "notes": "",
+      "versus": ""
+    },
     "mysql": {
       "setup_file": "setup_mysql",
       "db_url": "/db",

+ 28 - 0
frameworks/C++/ulib/setup_json_fit.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+
+fw_depends ulib
+
+# Travis is broken
+if [ "$TRAVIS" != "true" ]; then
+MAX_THREADS=$CPU_COUNT
+else
+MAX_THREADS=$(( 2 * $CPU_COUNT ))
+fi
+
+# 1. Change ULib Server (userver_tcp) configuration
+sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g"									  $IROOT/ULib/benchmark.cfg
+sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g"								  $IROOT/ULib/benchmark.cfg
+sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g"					  $IROOT/ULib/benchmark.cfg
+sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 100|g" $IROOT/ULib/benchmark.cfg
+
+# 2. Start ULib Server (userver_tcp)
+export UMEMPOOL="58,0,0,41,273,-15,-14,-20,36"
+
+# Never use setcap inside of TRAVIS 
+[ "$TRAVIS" != "true" ] || { \
+if [ `ulimit -r` -eq 99 ]; then
+	sudo setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp
+fi
+}
+
+$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg &

+ 28 - 0
frameworks/C++/ulib/setup_plaintext_fit.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+
+fw_depends ulib
+
+# Travis is broken
+if [ "$TRAVIS" != "true" ]; then
+MAX_THREADS=$CPU_COUNT
+else
+MAX_THREADS=$(( 2 * $CPU_COUNT ))
+fi
+
+# 1. Change ULib Server (userver_tcp) configuration
+sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g"										$IROOT/ULib/benchmark.cfg
+sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 16384|g"								$IROOT/ULib/benchmark.cfg
+sed -i "s|PREFORK_CHILD .*|PREFORK_CHILD ${MAX_THREADS}|g"						$IROOT/ULib/benchmark.cfg
+sed -i "s|CLIENT_FOR_PARALLELIZATION .*|CLIENT_FOR_PARALLELIZATION 8000|g" $IROOT/ULib/benchmark.cfg
+
+# 2. Start ULib Server (userver_tcp)
+export UMEMPOOL="58,0,0,41,16401,-14,-15,11,25"
+
+# Never use setcap inside of TRAVIS 
+[ "$TRAVIS" != "true" ] || { \
+if [ `ulimit -r` -eq 99 ]; then
+	sudo setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp
+fi
+}
+
+$IROOT/ULib/bin/userver_tcp -c $IROOT/ULib/benchmark.cfg &

+ 9 - 16
frameworks/C++/ulib/src/db.usp

@@ -9,10 +9,6 @@ static World*         pworld_db;
 static UOrmSession*   psql_db;
 static UOrmStatement* pstmt_db;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 static void usp_fork_db()
 {
    U_TRACE(5, "::usp_fork_db()")
@@ -23,16 +19,17 @@ static void usp_fork_db()
       {
       U_NEW(UOrmStatement, pstmt_db, UOrmStatement(*psql_db, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
 
-      if (pstmt_db == 0) U_WARNING("usp_fork_db(): we cound't connect to db");
+      if (pstmt_db == U_NULLPTR)
+         {
+         U_WARNING("usp_fork_db(): we cound't connect to db");
+
+         return;
+         }
 
       U_NEW(World, pworld_db, World);
 
       pstmt_db->use( pworld_db->id);
       pstmt_db->into(pworld_db->randomNumber);
-
-#  ifndef AS_cpoll_cppsp_DO
-      U_NEW(UValue, pvalue, UValue);
-#  endif
       }
 }
 
@@ -41,15 +38,12 @@ static void usp_end_db()
 {
    U_TRACE(5, "::usp_end_db()")
 
+   delete psql_db;
+
    if (pstmt_db)
       {
       delete  pstmt_db;
-      delete   psql_db;
       delete pworld_db;
-
-#  ifndef AS_cpoll_cppsp_DO
-      delete pvalue;
-#  endif
       }
 }
 #endif
@@ -65,7 +59,6 @@ pstmt_db->execute();
 #ifdef AS_cpoll_cppsp_DO
 USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%u}", pworld_db->id, pworld_db->randomNumber);
 #else
-USP_JSON_stringify(*pvalue, World, *pworld_db);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pworld_db);
 #endif
 -->

+ 1 - 14
frameworks/C++/ulib/src/edb.usp

@@ -8,10 +8,6 @@ TechEmpower Web Framework Benchmarks
 static char buffer[128];
 static UElasticSearchClient* es;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 #define QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
 
 static void usp_fork_edb()
@@ -28,10 +24,6 @@ static void usp_fork_edb()
       }
 
    U_MEMCPY(buffer,  "{\"query\":{\"match\":{\"_id\":\"", QLEN);
-
-#ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
-#endif
 }
 
 #ifdef DEBUG
@@ -40,10 +32,6 @@ static void usp_end_edb()
    U_TRACE(5, "::usp_end_edb()")
 
    delete es;
-
-#ifndef AS_cpoll_cppsp_DO
-   if (pvalue) delete pvalue;
-#endif
 }
 #endif
 -->
@@ -62,7 +50,6 @@ UString result;
 USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
 #else
 World world(id, result.strtoul());
-USP_JSON_stringify(*pvalue, World, world);
-pvalue->clear();
+USP_OBJ_JSON_stringify(world);
 #endif
 -->

+ 2 - 9
frameworks/C++/ulib/src/equery.usp

@@ -9,7 +9,6 @@ static char buffer[128];
 static UElasticSearchClient* es;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_query;
 #endif
 
@@ -31,7 +30,6 @@ static void usp_fork_equery()
    U_MEMCPY(buffer,  "{\"query\":{\"match\":{\"_id\":\"", QLEN);
 
 #ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
    U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
 #endif
 }
@@ -44,11 +42,7 @@ static void usp_end_equery()
    delete es;
 
 #ifndef AS_cpoll_cppsp_DO
-   if (pvalue)
-      {
-      delete pvalue;
-      delete pvworld_query;
-      }
+   if (pvworld_query) delete pvworld_query;
 #endif
 }
 #endif
@@ -95,8 +89,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_query);
 pvworld_query->clear();
 #endif
 -->

+ 2 - 9
frameworks/C++/ulib/src/eupdate.usp

@@ -12,7 +12,6 @@ static char buffer2[128];
 static UElasticSearchClient* es;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_update;
 #endif
 
@@ -41,7 +40,6 @@ static void usp_fork_eupdate()
    pbuffer2 = buffer2 + QLEN;
 
 #ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
    U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
 #endif
 }
@@ -54,11 +52,7 @@ static void usp_end_eupdate()
    delete es;
 
 #ifndef AS_cpoll_cppsp_DO
-   if (pvalue)
-      {
-      delete pvalue;
-      delete pvworld_update;
-      }
+   if (pvworld_update) delete pvworld_update;
 #endif
 }
 #endif
@@ -101,8 +95,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_update);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_update);
 pvworld_update->clear();
 #endif
 -->

+ 34 - 45
frameworks/C++/ulib/src/fortune.h

@@ -69,71 +69,60 @@ public:
 #  endif
       }
 
-#ifdef DEBUG
-   const char* dump(bool breset) const
-      {
-      *UObjectIO::os << "id               " << id              << '\n'
-                     << "message (UString " << (void*)&message << ')';
+   // JSON
 
-      if (breset)
-         {
-         UObjectIO::output();
-
-         return UObjectIO::buffer_output;
-         }
+   void toJSON(UString& json)
+      {
+      U_TRACE(0, "Fortune::toJSON(%V)", json.rep)
 
-      return 0;
+      json.toJSON(U_JSON_METHOD_HANDLER(id,      unsigned int));
+      json.toJSON(U_JSON_METHOD_HANDLER(message, UString));
       }
-#endif
 
-private:
-   U_DISALLOW_ASSIGN(Fortune)
-};
+   void fromJSON(UValue& json)
+      {
+      U_TRACE(0, "Fortune::fromJSON(%p)", &json)
 
-// ORM TEMPLATE SPECIALIZATIONS
+      json.fromJSON(U_JSON_METHOD_HANDLER(id,      unsigned int));
+      json.fromJSON(U_JSON_METHOD_HANDLER(message, UString));
+      }
 
-template <> class U_EXPORT UOrmTypeHandler<Fortune> : public UOrmTypeHandler_Base {
-public:
-   explicit UOrmTypeHandler(Fortune& val) : UOrmTypeHandler_Base(&val) {}
+   // ORM
 
-   void bindParam(UOrmStatement* stmt) const
+   void bindParam(UOrmStatement* stmt)
       {
-      U_TRACE(0, "UOrmTypeHandler<Fortune>::bindParam(%p)", stmt)
+      U_TRACE(0, "Fortune::bindParam(%p)", stmt)
 
-      stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, id,      unsigned int));
-      stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString));
+      stmt->bindParam(U_ORM_TYPE_HANDLER(id,      unsigned int));
+      stmt->bindParam(U_ORM_TYPE_HANDLER(message, UString));
       }
 
    void bindResult(UOrmStatement* stmt)
       {
-      U_TRACE(0, "UOrmTypeHandler<Fortune>::bindResult(%p)", stmt)
+      U_TRACE(0, "Fortune::bindResult(%p)", stmt)
 
-      stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, id,      unsigned int));
-      stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString));
+      stmt->bindResult(U_ORM_TYPE_HANDLER(id,      unsigned int));
+      stmt->bindResult(U_ORM_TYPE_HANDLER(message, UString));
       }
-};
 
-// JSON TEMPLATE SPECIALIZATIONS
-
-template <> class U_EXPORT UJsonTypeHandler<Fortune> : public UJsonTypeHandler_Base {
-public:
-   explicit UJsonTypeHandler(Fortune& val) : UJsonTypeHandler_Base(&val) {}
-
-   void toJSON(UValue& json)
+#ifdef DEBUG
+   const char* dump(bool breset) const
       {
-      U_TRACE(0, "UJsonTypeHandler<Fortune>::toJSON(%p)", &json)
+      *UObjectIO::os << "id               " << id              << '\n'
+                     << "message (UString " << (void*)&message << ')';
 
-      json.toJSON(U_JSON_TYPE_HANDLER(Fortune, id,      unsigned int));
-      json.toJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString));
-      }
+      if (breset)
+         {
+         UObjectIO::output();
 
-   void fromJSON(UValue& json)
-      {
-      U_TRACE(0, "UJsonTypeHandler<Fortune>::fromJSON(%p)", &json)
+         return UObjectIO::buffer_output;
+         }
 
-      json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, id,      unsigned int));
-      json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString));
+      return U_NULLPTR;
       }
-};
+#endif
 
+private:
+   U_DISALLOW_ASSIGN(Fortune)
+};
 #endif

+ 13 - 4
frameworks/C++/ulib/src/fortune.usp

@@ -18,11 +18,18 @@ static void usp_fork_fortune()
 
    U_NEW(UOrmSession, psql_fortune, UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
 
+   U_INTERNAL_DUMP("psql_fortune = %p", psql_fortune)
+
    if (psql_fortune->isReady())
       {
       U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
 
-      if (pstmt_fortune == 0) U_WARNING("usp_fork_fortune(): we cound't connect to db");
+      if (pstmt_fortune == U_NULLPTR)
+         {
+         U_WARNING("usp_fork_fortune(): we cound't connect to db");
+
+         return;
+         }
 
       if (UOrmDriver::isPGSQL()) *psql_fortune << "BEGIN ISOLATION LEVEL SERIALIZABLE; COMMIT";
 
@@ -41,14 +48,16 @@ static void usp_end_fortune()
 {
    U_TRACE(5, "::usp_end_fortune()")
 
+   U_INTERNAL_DUMP("psql_fortune = %p", psql_fortune)
+
+   delete psql_fortune;
+
    if (pstmt_fortune)
       {
       delete pstmt_fortune;
-
+      delete pfortune;
       delete pencoded;
-      delete psql_fortune;
       delete pvfortune;
-      delete pfortune;
       delete pfortune2add;
       }
 }

+ 2 - 15
frameworks/C++/ulib/src/mdb.usp

@@ -7,17 +7,13 @@ TechEmpower Web Framework Benchmarks
 
 static UMongoDBClient* mc;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 static void usp_fork_mdb()
 {
    U_TRACE(5, "::usp_fork_mdb()")
 
    U_NEW(UMongoDBClient, mc, UMongoDBClient);
 
-   if (mc->connect(0,0) == false)
+   if (mc->connect(U_NULLPTR, 0) == false)
       {
       U_WARNING("usp_fork_mdb(): connection failed");
 
@@ -30,10 +26,6 @@ static void usp_fork_mdb()
 
       return;
       }
-
-#ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
-#endif
 }
 
 #ifdef DEBUG
@@ -42,10 +34,6 @@ static void usp_end_mdb()
    U_TRACE(5, "::usp_end_mdb()")
 
    delete mc;
-
-#ifndef AS_cpoll_cppsp_DO
-   if (pvalue) delete pvalue;
-#endif
 }
 #endif
 -->
@@ -64,7 +52,6 @@ UString result;
 USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, result.rep);
 #else
 World world(id, result.strtoul());
-USP_JSON_stringify(*pvalue, World, world);
-pvalue->clear();
+USP_OBJ_JSON_stringify(world);
 #endif
 -->

+ 1 - 1
frameworks/C++/ulib/src/mfortune.usp

@@ -16,7 +16,7 @@ static void usp_fork_mfortune()
 
    U_NEW(UMongoDBClient, mc, UMongoDBClient);
 
-   if (mc->connect(0,0) == false)
+   if (mc->connect(U_NULLPTR, 0) == false)
       {
       U_WARNING("usp_fork_mfortune(): connection failed");
 

+ 3 - 10
frameworks/C++/ulib/src/mquery.usp

@@ -8,7 +8,6 @@ TechEmpower Web Framework Benchmarks
 static UMongoDBClient* mc;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_query;
 #endif
 
@@ -18,7 +17,7 @@ static void usp_fork_mquery()
 
    U_NEW(UMongoDBClient, mc, UMongoDBClient);
 
-   if (mc->connect(0,0) == false)
+   if (mc->connect(U_NULLPTR, 0) == false)
       {
       U_WARNING("usp_fork_mquery(): connection disabled or failed");
 
@@ -33,7 +32,6 @@ static void usp_fork_mquery()
       }
 
 #ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
    U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
 #endif
 }
@@ -46,11 +44,7 @@ static void usp_end_mquery()
    delete mc;
 
 #ifndef AS_cpoll_cppsp_DO
-   if (pvalue)
-      {
-      delete pvalue;
-      delete pvworld_query;
-      }
+   if (pvworld_query) delete pvworld_query;
 #endif
 }
 #endif
@@ -95,8 +89,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_query);
 pvworld_query->clear();
 #endif
 -->

+ 3 - 10
frameworks/C++/ulib/src/mupdate.usp

@@ -8,7 +8,6 @@ TechEmpower Web Framework Benchmarks
 static UMongoDBClient* mc;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_update;
 #endif
 
@@ -18,7 +17,7 @@ static void usp_fork_mupdate()
 
    U_NEW(UMongoDBClient, mc, UMongoDBClient);
 
-   if (mc->connect(0,0) == false)
+   if (mc->connect(U_NULLPTR, 0) == false)
       {
       U_WARNING("usp_fork_mupdate(): connection disabled or failed");
 
@@ -33,7 +32,6 @@ static void usp_fork_mupdate()
       }
 
 #ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
    U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
 #endif
 }
@@ -46,11 +44,7 @@ static void usp_end_mupdate()
    delete mc;
 
 #ifndef AS_cpoll_cppsp_DO
-   if (pvalue)
-      {
-      delete pvalue;
-      delete pvworld_update;
-      }
+   if (pvworld_update) delete pvworld_update;
 #endif
 }
 #endif
@@ -97,8 +91,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_update);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_update);
 pvworld_update->clear();
 #endif
 -->

+ 9 - 7
frameworks/C++/ulib/src/query.usp

@@ -10,7 +10,6 @@ static UOrmSession*   psql_query;
 static UOrmStatement* pstmt_query;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_query;
 #endif
 
@@ -24,7 +23,12 @@ static void usp_fork_query()
       {
       U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
 
-      if (pstmt_query == 0) U_WARNING("usp_fork_query(): we cound't connect to db");
+      if (pstmt_query == U_NULLPTR)
+         {
+         U_WARNING("usp_fork_query(): we cound't connect to db");
+
+         return;
+         }
 
       if (UOrmDriver::isPGSQL()) *psql_query << "BEGIN TRANSACTION";
 
@@ -34,7 +38,6 @@ static void usp_fork_query()
       pstmt_query->into(pworld_query->randomNumber);
 
 #  ifndef AS_cpoll_cppsp_DO
-      U_NEW(UValue, pvalue, UValue);
       U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
 #  endif
       }
@@ -45,14 +48,14 @@ static void usp_end_query()
 {
    U_TRACE(5, "::usp_end_query()")
 
+   delete psql_query;
+
    if (pstmt_query)
       {
       delete pstmt_query;
-      delete psql_query;
       delete pworld_query;
 
 #  ifndef AS_cpoll_cppsp_DO
-      delete pvalue;
       delete pvworld_query;
 #  endif
       }
@@ -95,8 +98,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_query);
 pvworld_query->clear();
 #endif
 -->

+ 1 - 14
frameworks/C++/ulib/src/rdb.usp

@@ -9,10 +9,6 @@ static char buffer[128];
 static char* ptr = buffer+6;
 static UREDISClient_Base* rc;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 static void usp_fork_rdb()
 {
    U_TRACE(5, "::usp_fork_rdb()")
@@ -27,10 +23,6 @@ static void usp_fork_rdb()
       }
 
    U_MEMCPY(buffer, "world:", U_CONSTANT_SIZE("world:"));
-
-#ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
-#endif
 }
 
 #ifdef DEBUG
@@ -39,10 +31,6 @@ static void usp_end_rdb()
    U_TRACE(5, "::usp_end_rdb()")
 
    delete rc;
-
-#ifndef AS_cpoll_cppsp_DO
-   if (pvalue) delete pvalue;
-#endif
 }
 #endif
 -->
@@ -58,7 +46,6 @@ uint32_t id;
 USP_PRINTF_ADD("{\"id\":%u,\"randomNumber\":%v}", id, rc->vitem[0].rep);
 #else
 World world(id, rc->vitem[0].strtoul());
-USP_JSON_stringify(*pvalue, World, world);
-pvalue->clear();
+USP_OBJ_JSON_stringify(world);
 #endif
 -->

+ 2 - 18
frameworks/C++/ulib/src/rquery.usp

@@ -9,10 +9,6 @@ static char buffer[8192];
 static UREDISClient_Base* rc;
 static UVector<World*>* pvworld_query;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 static void usp_fork_rquery()
 {
    U_TRACE(5, "::usp_fork_rquery()")
@@ -27,10 +23,6 @@ static void usp_fork_rquery()
       }
 
    U_NEW(UVector<World*>, pvworld_query, UVector<World*>(500));
-
-#ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
-#endif
 }
 
 #ifdef DEBUG
@@ -40,14 +32,7 @@ static void usp_end_rquery()
 
    delete rc;
 
-   if (pvworld_query)
-      {
-      delete pvworld_query;
-
-#  ifndef AS_cpoll_cppsp_DO
-      delete pvalue;
-#  endif
-      }
+   if (pvworld_query) delete pvworld_query;
 }
 #endif
 -->
@@ -101,8 +86,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_query);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_query);
 #endif
 pvworld_query->clear();
 -->

+ 2 - 18
frameworks/C++/ulib/src/rupdate.usp

@@ -9,10 +9,6 @@ static char buffer[8192];
 static UREDISClient_Base* rc;
 static UVector<World*>* pvworld;
 
-#ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
-#endif
-
 static void usp_fork_rupdate()
 {
    U_TRACE(5, "::usp_fork_rupdate()")
@@ -27,10 +23,6 @@ static void usp_fork_rupdate()
       }
 
    U_NEW(UVector<World*>, pvworld, UVector<World*>(500));
-
-#ifndef AS_cpoll_cppsp_DO
-   U_NEW(UValue, pvalue, UValue);
-#endif
 }
 
 #ifdef DEBUG
@@ -40,14 +32,7 @@ static void usp_end_rupdate()
 
    delete rc;
 
-   if (pvworld)
-      {
-      delete pvworld;
-
-#  ifndef AS_cpoll_cppsp_DO
-      delete pvalue;
-#  endif
-      }
+   if (pvworld) delete pvworld;
 }
 #endif
 -->
@@ -105,8 +90,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld);
 #endif
 pvworld->clear();
 -->

+ 7 - 8
frameworks/C++/ulib/src/update.usp

@@ -11,7 +11,6 @@ static UOrmStatement* pstmt1;
 static UOrmStatement* pstmt2;
 
 #ifndef AS_cpoll_cppsp_DO
-static UValue* pvalue;
 static UVector<World*>* pvworld_update;
 #endif
 
@@ -26,10 +25,12 @@ static void usp_fork_update()
       U_NEW(UOrmStatement, pstmt1, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
       U_NEW(UOrmStatement, pstmt2, UOrmStatement(*psql_update, U_CONSTANT_TO_PARAM("UPDATE World SET randomNumber = ? WHERE id = ?")));
 
-      if (pstmt1 == 0 ||
-          pstmt2 == 0)
+      if (pstmt1 == U_NULLPTR ||
+          pstmt2 == U_NULLPTR)
          {
          U_WARNING("usp_fork_update(): we cound't connect to db");
+
+         return;
          }
 
       if (UOrmDriver::isPGSQL()) *psql_update << "SET synchronous_commit TO OFF";
@@ -41,7 +42,6 @@ static void usp_fork_update()
       pstmt2->use( pworld_update->randomNumber, pworld_update->id);
 
 #  ifndef AS_cpoll_cppsp_DO
-      U_NEW(UValue, pvalue, UValue);
       U_NEW(UVector<World*>, pvworld_update, UVector<World*>(500));
 #  endif
       }
@@ -52,16 +52,16 @@ static void usp_end_update()
 {
    U_TRACE(5, "::usp_end_update()")
 
+   delete psql_update;
+
    if (pstmt1 &&
        pstmt2)
       {
       delete pstmt1;
       delete pstmt2;
-      delete psql_update;
       delete pworld_update;
 
 #  ifndef AS_cpoll_cppsp_DO
-      delete pvalue;
       delete pvworld_update;
 #  endif
       }
@@ -108,8 +108,7 @@ while (true)
 #ifdef AS_cpoll_cppsp_DO
 USP_PUTS_CHAR(']');
 #else
-USP_JSON_stringify(*pvalue, UVector<World*>, *pvworld_update);
-pvalue->clear();
+USP_OBJ_JSON_stringify(*pvworld_update);
 pvworld_update->clear();
 #endif
 -->

+ 34 - 45
frameworks/C++/ulib/src/world.h

@@ -37,71 +37,60 @@ public:
       U_TRACE_UNREGISTER_OBJECT(5, World)
       }
 
-#ifdef DEBUG
-   const char* dump(bool breset) const
-      {
-      *UObjectIO::os << "id           " << id            << '\n'
-                     << "randomNumber " << randomNumber;
+   // JSON
 
-      if (breset)
-         {
-         UObjectIO::output();
-
-         return UObjectIO::buffer_output;
-         }
+   void toJSON(UString& json)
+      {
+      U_TRACE(0, "World::toJSON(%V)", json.rep)
 
-      return 0;
+      json.toJSON(U_JSON_METHOD_HANDLER(id,           unsigned int));
+      json.toJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
       }
-#endif
 
-private:
-   World& operator=(const World&) { return *this; }
-};
+   void fromJSON(UValue& json)
+      {
+      U_TRACE(0, "World::fromJSON(%p)", &json)
 
-// ORM TEMPLATE SPECIALIZATIONS
+      json.fromJSON(U_JSON_METHOD_HANDLER(id,           unsigned int));
+      json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
+      }
 
-template <> class U_EXPORT UOrmTypeHandler<World> : public UOrmTypeHandler_Base {
-public:
-   explicit UOrmTypeHandler(World& val) : UOrmTypeHandler_Base(&val) {}
+   // ORM
 
-   void bindParam(UOrmStatement* stmt) const
+   void bindParam(UOrmStatement* stmt)
       {
-      U_TRACE(0, "UOrmTypeHandler<World>::bindParam(%p)", stmt)
+      U_TRACE(0, "World::bindParam(%p)", stmt)
 
-      stmt->bindParam(U_ORM_TYPE_HANDLER(World, id,            unsigned int));
-      stmt->bindParam(U_ORM_TYPE_HANDLER(World, randomNumber,  unsigned int));
+      stmt->bindParam(U_ORM_TYPE_HANDLER(id,           unsigned int));
+      stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
       }
 
    void bindResult(UOrmStatement* stmt)
       {
-      U_TRACE(0, "UOrmTypeHandler<World>::bindResult(%p)", stmt)
+      U_TRACE(0, "World::bindResult(%p)", stmt)
 
-      stmt->bindResult(U_ORM_TYPE_HANDLER(World, id,           unsigned int));
-      stmt->bindResult(U_ORM_TYPE_HANDLER(World, randomNumber, unsigned int));
+      stmt->bindResult(U_ORM_TYPE_HANDLER(id,           unsigned int));
+      stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
       }
-};
 
-// JSON TEMPLATE SPECIALIZATIONS
-
-template <> class U_EXPORT UJsonTypeHandler<World> : public UJsonTypeHandler_Base {
-public:
-   explicit UJsonTypeHandler(World& val) : UJsonTypeHandler_Base(&val) {}
-
-   void toJSON(UValue& json)
+#ifdef DEBUG
+   const char* dump(bool breset) const
       {
-      U_TRACE(0, "UJsonTypeHandler<World>::toJSON(%p)", &json)
+      *UObjectIO::os << "id           " << id            << '\n'
+                     << "randomNumber " << randomNumber;
 
-      json.toJSON(U_JSON_TYPE_HANDLER(World, id,            unsigned int));
-      json.toJSON(U_JSON_TYPE_HANDLER(World, randomNumber,  unsigned int));
-      }
+      if (breset)
+         {
+         UObjectIO::output();
 
-   void fromJSON(UValue& json)
-      {
-      U_TRACE(0, "UJsonTypeHandler<World>::fromJSON(%p)", &json)
+         return UObjectIO::buffer_output;
+         }
 
-      json.fromJSON(U_JSON_TYPE_HANDLER(World, id,           unsigned int));
-      json.fromJSON(U_JSON_TYPE_HANDLER(World, randomNumber, unsigned int));
+      return U_NULLPTR;
       }
-};
+#endif
 
+private:
+   U_DISALLOW_ASSIGN(World)
+};
 #endif

+ 61 - 56
toolset/setup/linux/frameworks/ulib.sh

@@ -11,9 +11,8 @@ ULIB_DOCUMENT_ROOT=$ULIB_ROOT/ULIB_DOCUMENT_ROOT
 # Create a run directory for ULIB
 [ ! -e $IROOT/ulib.installed -a -d $IROOT/ULib ] && rm -rf $IROOT/ULib*
 
-if [ ! -d "$ULIB_ROOT" ]; then
-  mkdir -p $ULIB_ROOT
-fi
+mkdir -p $ULIB_ROOT
+mkdir -p $ULIB_DOCUMENT_ROOT
 
 # AVOID "fatal error: postgres_fe.h: No such file or directory"
 # TODO: This should already be installed and unnecessary.
@@ -26,6 +25,21 @@ sudo apt-get install -y postgresql-server-dev-all
   sudo apt-get install -y libcap2-bin
 #fi
 
+# Check for the compiler support (We want at least g++ 4.8)
+CC=gcc  # C   compiler command
+CXX=g++ # C++ compiler command
+
+gcc_version=`g++ -dumpversion`
+
+case "$gcc_version" in
+  3*|4.0*|4.1*|4.2*|4.3*|4.4*|4.5*|4.6*|4.7*|4.8*)
+	  CC='gcc-4.9'
+	 CXX='g++-4.9'
+  ;;
+esac
+
+export CC CXX
+
 # We need to install mongo-c-driver (we don't have a ubuntu package)
 RETCODE=$(fw_exists ${IROOT}/mongo-c-driver.installed)
 if [ "$RETCODE" != 0 ]; then
@@ -37,21 +51,6 @@ if [ "$RETCODE" != 0 ]; then
   touch ${IROOT}/mongo-c-driver.installed
 fi
 
-# Add a simple configuration file to it
-cd $ULIB_ROOT
-if [ ! -f "benchmark.cfg" ]; then
-  cat <<EOF >benchmark.cfg
-userver {
- PORT 8080
- PREFORK_CHILD 4
- TCP_LINGER_SET -1
- LISTEN_BACKLOG 256
- ORM_DRIVER "mysql pgsql sqlite"
- DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT
-}
-EOF
-fi
-
 # 1. Download ULib
 cd $IROOT
 fw_get -o ULib-${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz 
@@ -60,61 +59,67 @@ fw_untar  ULib-${ULIB_VERSION}.tar.gz
 # 2. Compile application (userver_tcp)
 cd ULib-$ULIB_VERSION
 
-# Check for the compiler support (We want at least g++ 4.8)
-CC=gcc  # C   compiler command
-CXX=g++ # C++ compiler command
-
-gcc_version=`g++ -dumpversion`
-
-case "$gcc_version" in
-  3*|4.0*|4.1*|4.2*|4.3*|4.4*|4.5*|4.6*|4.7*|4.8*)
-	  CC='gcc-4.9'
-	 CXX='g++-4.9'
-  ;;
-esac
-
-export CC CXX
-
 # AVOID "configure: error: newly created file is older than distributed files! Check your system clock"
 find . -exec touch {} \;
 
+cp -r tests/examples/benchmark/FrameworkBenchmarks/ULib/db $ULIB_ROOT
+
+cat <<EOF >$ULIB_ROOT/benchmark.cfg
+userver {
+PORT 8080
+PREFORK_CHILD 2
+TCP_LINGER_SET 0 
+LISTEN_BACKLOG 16384
+ORM_DRIVER "mysql pgsql"
+CLIENT_FOR_PARALLELIZATION 100
+DOCUMENT_ROOT $ULIB_DOCUMENT_ROOT 
+}
+EOF
+
 USP_FLAGS="-DAS_cpoll_cppsp_DO" \
 ./configure --prefix=$ULIB_ROOT \
-   --disable-static --disable-examples \
-   --with-mysql --with-pgsql --with-sqlite3 \
-   --without-ssl --without-pcre --without-expat \
-   --without-libz --without-libuuid --without-magic --without-libares \
-   --enable-static-orm-driver='mysql pgsql sqlite' --enable-static-server-plugin=http \
-	--with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT"
-#  --enable-debug \
+--disable-static --disable-examples \
+--with-mysql --with-pgsql \
+--without-ssl --without-pcre --without-expat \
+--without-libz --without-libuuid --without-magic --without-libares \
+--enable-static-orm-driver='mysql pgsql' --enable-static-server-plugin=http \
+--with-mongodb --with-mongodb-includes="-I$IROOT/include/libbson-1.0 -I$IROOT/include/libmongoc-1.0" --with-mongodb-ldflags="-L$IROOT"
+# --enable-debug \
 #USP_LIBS="-ljson" \
+#cp $TROOT/src/* src/ulib/net/server/plugin/usp
 
 make install
-cp -r tests/examples/benchmark/FrameworkBenchmarks/ULib/db $ULIB_ROOT
-
 cd examples/userver
 make install
 
-# 3. Compile usp pages for benchmark (no more REDIS)
+# Never use setcap inside of TRAVIS 
+[ "$TRAVIS" != "true" ] || { \
+if [ `ulimit -r` -eq 99 ]; then
+	sudo setcap cap_sys_nice,cap_sys_resource,cap_net_bind_service,cap_net_raw+eip $IROOT/ULib/bin/userver_tcp
+fi
+}
+
+# Compile usp pages (no more REDIS)
 cd ../../src/ulib/net/server/plugin/usp
-make json.la plaintext.la  db.la  query.la  update.la  fortune.la \
-                          mdb.la mquery.la mupdate.la mfortune.la
-#                         rdb.la rquery.la rupdate.la rfortune.la
+make json.la plaintext.la db.la query.la update.la fortune.la \
+	  mdb.la mquery.la mupdate.la mfortune.la
+#    rdb.la rquery.la rupdate.la rfortune.la
 
 # Check that compilation worked
 if [ ! -e .libs/db.so ]; then
-   exit 1
+	exit 1
 fi
 
-mkdir -p $ULIB_DOCUMENT_ROOT
 cp .libs/json.so .libs/plaintext.so \
-	.libs/db.so  .libs/query.so  .libs/update.so  .libs/fortune.so \
-	.libs/mdb.so .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT
-#  .libs/rdb.so .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \
-
-echo "export ULIB_VERSION=${ULIB_VERSION}" >> $IROOT/ulib.installed
-echo "export ULIB_ROOT=${ULIB_ROOT}" >> $IROOT/ulib.installed
-echo "export ULIB_DOCUMENT_ROOT=${ULIB_DOCUMENT_ROOT}" >> $IROOT/ulib.installed
-echo -e "export PATH=\$ULIB_ROOT/bin:\$PATH" >> $IROOT/ulib.installed
+	.libs/db.so   .libs/query.so  .libs/update.so  .libs/fortune.so \
+	.libs/mdb.so  .libs/mquery.so .libs/mupdate.so .libs/mfortune.so $ULIB_DOCUMENT_ROOT
+#	.libs/rdb.so  .libs/rquery.so .libs/rupdate.so .libs/rfortune.so \
+
+cat <<EOF >$IROOT/ulib.installed
+export ULIB_ROOT=${ULIB_ROOT}
+export ULIB_VERSION=${ULIB_VERSION}
+export ULIB_DOCUMENT_ROOT=${ULIB_DOCUMENT_ROOT}
+export PATH=${ULIB_ROOT}/bin:${PATH}
+EOF
 
 source $IROOT/ulib.installed