1
0
mirror of https://github.com/stefanocasazza/ULib.git synced 2025-09-28 19:05:55 +08:00
This commit is contained in:
stefanocasazza 2018-07-28 20:07:07 +02:00
parent b5184ba45e
commit d2421aa734
28 changed files with 1171 additions and 943 deletions

View File

@ -109,6 +109,7 @@ cleandist:
$(distdir)/src/ulib/orm/driver/.libs \
$(distdir)/src/ulib/orm/driver/Makefile \
$(distdir)/src/ulib/orm/driver/libpq/Makefile \
$(distdir)/src/ulib/orm/driver/libpq/libpq.la \
$(distdir)/src/ulib/net/server/plugin/*.o \
$(distdir)/src/ulib/net/server/plugin/*.l? \
$(distdir)/src/ulib/net/server/plugin/.deps \

View File

@ -1032,6 +1032,7 @@ cleandist:
$(distdir)/src/ulib/orm/driver/.libs \
$(distdir)/src/ulib/orm/driver/Makefile \
$(distdir)/src/ulib/orm/driver/libpq/Makefile \
$(distdir)/src/ulib/orm/driver/libpq/libpq.la \
$(distdir)/src/ulib/net/server/plugin/*.o \
$(distdir)/src/ulib/net/server/plugin/*.l? \
$(distdir)/src/ulib/net/server/plugin/.deps \

101
configure vendored
View File

@ -775,8 +775,6 @@ TCC_TRUE
PRG_LDFLAGS
POSTGRESQL_USE_OPENSSL_FALSE
POSTGRESQL_USE_OPENSSL_TRUE
HAVE_PGSQL_BATCH_API_FALSE
HAVE_PGSQL_BATCH_API_TRUE
HAVE_PGSQL_FALSE
HAVE_PGSQL_TRUE
POSTGRESQL_LIBS
@ -30414,14 +30412,6 @@ else
HAVE_PGSQL_FALSE=
fi
if false; then
HAVE_PGSQL_BATCH_API_TRUE=
HAVE_PGSQL_BATCH_API_FALSE='#'
else
HAVE_PGSQL_BATCH_API_TRUE='#'
HAVE_PGSQL_BATCH_API_FALSE=
fi
if false; then
POSTGRESQL_USE_OPENSSL_TRUE=
POSTGRESQL_USE_OPENSSL_FALSE='#'
@ -30443,87 +30433,6 @@ fi
$as_echo "#define USE_PGSQL 1" >>confdefs.h
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing PQenterBatchMode" >&5
$as_echo_n "checking for library containing PQenterBatchMode... " >&6; }
if ${ac_cv_search_PQenterBatchMode+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS="$LIBS"
ac_cv_search_PQenterBatchMode="no"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char PQenterBatchMode ();
int
main ()
{
return PQenterBatchMode ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_search_PQenterBatchMode="none required"
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
test "$ac_cv_search_PQenterBatchMode" = "no" && for i in pq; do
LIBS="-l$i $ac_func_search_save_LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char PQenterBatchMode ();
int
main ()
{
return PQenterBatchMode ();
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_link "$LINENO"; then :
ac_cv_search_PQenterBatchMode="-l$i"
break
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
done
LIBS="$ac_func_search_save_LIBS"
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_PQenterBatchMode" >&5
$as_echo "$ac_cv_search_PQenterBatchMode" >&6; }
if test "$ac_cv_search_PQenterBatchMode" != "no"; then
test "$ac_cv_search_PQenterBatchMode" = "none required" || POSTGRESQL_LIBS="$POSTGRESQL_LIBS $ac_cv_search_PQenterBatchMode"
else :
fi
if test "$ac_cv_search_PQenterBatchMode" = "yes"; then
if true; then
HAVE_PGSQL_BATCH_API_TRUE=
HAVE_PGSQL_BATCH_API_FALSE='#'
else
HAVE_PGSQL_BATCH_API_TRUE='#'
HAVE_PGSQL_BATCH_API_FALSE=
fi
$as_echo "#define USE_PGSQL_BATCH_API 1" >>confdefs.h
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether PostgreSQL use openssl" >&5
$as_echo_n "checking whether PostgreSQL use openssl... " >&6; }
if test -n "`pg_config --configure | grep openssl`"; then
@ -34142,7 +34051,7 @@ fi
CXX_MAYBE_FLAGS_MODERN=""
if test "$found_postgresql" = "yes"; then
if test "$ac_cv_search_PQenterBatchMode" = "yes"; then
if test "$static_handler_pgsql" != "yes"; then
CC_MAYBE_FLAGS="$CC_MAYBE_FLAGS -Wc++-compat -Wold-style-definition"
else
CC_MAYBE_FLAGS="$CC_MAYBE_FLAGS -Wno-discarded-qualifiers -Wno-switch-enum -Wno-missing-field-initializers -Wno-sign-compare -Wno-strict-aliasing \
@ -36021,10 +35930,6 @@ if test -z "${HAVE_PGSQL_TRUE}" && test -z "${HAVE_PGSQL_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PGSQL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_PGSQL_BATCH_API_TRUE}" && test -z "${HAVE_PGSQL_BATCH_API_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PGSQL_BATCH_API\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${POSTGRESQL_USE_OPENSSL_TRUE}" && test -z "${POSTGRESQL_USE_OPENSSL_FALSE}"; then
as_fn_error $? "conditional \"POSTGRESQL_USE_OPENSSL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
@ -36033,10 +35938,6 @@ if test -z "${HAVE_PGSQL_TRUE}" && test -z "${HAVE_PGSQL_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PGSQL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_PGSQL_BATCH_API_TRUE}" && test -z "${HAVE_PGSQL_BATCH_API_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PGSQL_BATCH_API\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${POSTGRESQL_USE_OPENSSL_TRUE}" && test -z "${POSTGRESQL_USE_OPENSSL_FALSE}"; then
as_fn_error $? "conditional \"POSTGRESQL_USE_OPENSSL\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5

View File

@ -1433,17 +1433,11 @@ AC_CHECK_MYSQL
AX_LIB_POSTGRESQL
AM_CONDITIONAL(HAVE_PGSQL, false)
AM_CONDITIONAL(HAVE_PGSQL_BATCH_API, false)
AM_CONDITIONAL(POSTGRESQL_USE_OPENSSL, false)
if test "$found_postgresql" = "yes"; then
AM_CONDITIONAL(HAVE_PGSQL, true)
AC_DEFINE(USE_PGSQL, 1, [Define if enable PostgreSQL database support])
AC_SEARCH_LIBS_VAR([PQenterBatchMode], pq, , , , POSTGRESQL_LIBS)
if test "$ac_cv_search_PQenterBatchMode" = "yes"; then
AM_CONDITIONAL(HAVE_PGSQL_BATCH_API, true)
AC_DEFINE(USE_PGSQL_BATCH_API, 1, [Define if PostgreSQL database support batch API])
fi
AC_MSG_CHECKING([whether PostgreSQL use openssl])
if test -n "`pg_config --configure | grep openssl`"; then
AC_MSG_RESULT([yes])
@ -2424,7 +2418,7 @@ if test "$ac_cv_c_compiler_gnu" = "yes" -a "x$OPERATINGSYSTEM" = xlinux; then
CXX_MAYBE_FLAGS_MODERN=""
if test "$found_postgresql" = "yes"; then
if test "$ac_cv_search_PQenterBatchMode" = "yes"; then
if test "$static_handler_pgsql" != "yes"; then
CC_MAYBE_FLAGS="$CC_MAYBE_FLAGS -Wc++-compat -Wold-style-definition"
else
CC_MAYBE_FLAGS="$CC_MAYBE_FLAGS -Wno-discarded-qualifiers -Wno-switch-enum -Wno-missing-field-initializers -Wno-sign-compare -Wno-strict-aliasing \

View File

@ -777,9 +777,6 @@
/* Define if enable PostgreSQL database support */
#undef USE_PGSQL
/* Define if PostgreSQL database support batch API */
#undef USE_PGSQL_BATCH_API
/* Define if enable php support */
#undef USE_PHP

View File

@ -10,11 +10,9 @@ EXTRA_DIST = base/* container/* db/* debug/* dynamic/* flex/* internal/* ldap/*
if HAVE_PGSQL
if STATIC_ORM_DRIVER_PGSQL
if !HAVE_PGSQL_BATCH_API
SUBDIRS = orm/driver/libpq
endif
endif
endif
DEFAULT_INCLUDES = -I. -I$(top_builddir)/include
@ -311,10 +309,8 @@ lib@ULIB@_la_LDFLAGS = @ULIB_LIBS@
if STATIC_ORM_DRIVER_PGSQL
SRC_CPP += orm/driver/orm_driver_pgsql.cpp
if !HAVE_PGSQL_BATCH_API
lib@ULIB@_la_LDFLAGS += $(top_builddir)/src/ulib/orm/driver/libpq/libpq.la @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@
endif
endif
lib@ULIB@_la_LDFLAGS += -version-info 1:0:0 -release @ULIB_VERSION@

View File

@ -153,7 +153,7 @@ target_triplet = @target@
@STATIC_ORM_DRIVER_SQLITE_TRUE@am__append_63 = orm/driver/orm_driver_sqlite.cpp
@STATIC_ORM_DRIVER_MYSQL_TRUE@am__append_64 = orm/driver/orm_driver_mysql.cpp
@STATIC_ORM_DRIVER_PGSQL_TRUE@am__append_65 = orm/driver/orm_driver_pgsql.cpp
@HAVE_PGSQL_BATCH_API_FALSE@@STATIC_ORM_DRIVER_PGSQL_TRUE@am__append_66 = $(top_builddir)/src/ulib/orm/driver/libpq/libpq.la @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@
@STATIC_ORM_DRIVER_PGSQL_TRUE@am__append_66 = $(top_builddir)/src/ulib/orm/driver/libpq/libpq.la @POSTGRESQL_LDFLAGS@ @POSTGRESQL_LIBS@
@MINGW_TRUE@am__append_67 = -export-symbols $(srcdir)/@ULIB@.def -no-undefined -Wl,ULib-win32-res.o
# Handler static http servlet
@ -769,7 +769,7 @@ EXTRA_DIST = base/* container/* db/* debug/* dynamic/* flex/* internal/* ldap/*
net/server/plugin/*.cpp net/server/plugin/Makefile.* \
*.cpp all_c.c ULib.pc.in ULib.rc.in utility/bin
@HAVE_PGSQL_BATCH_API_FALSE@@HAVE_PGSQL_TRUE@@STATIC_ORM_DRIVER_PGSQL_TRUE@SUBDIRS = orm/driver/libpq
@HAVE_PGSQL_TRUE@@STATIC_ORM_DRIVER_PGSQL_TRUE@SUBDIRS = orm/driver/libpq
DEFAULT_INCLUDES = -I. -I$(top_builddir)/include
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = ULib.pc

View File

@ -39,7 +39,9 @@ void UEventDB::addClientImage(vPFpvu handlerResult, uint32_t num_query)
(void) U_SYSCALL(PQflush, "%p", (PGconn*)conn);
#endif
#if defined(U_SERVER_CAPTIVE_PORTAL) && defined(ENABLE_THREAD)
UClientImage_Base::setRequestProcessed();
#endif
U_INTERNAL_DUMP("start = %u end = %u", start, end)

View File

@ -3,6 +3,7 @@ Test type 1: JSON serialization
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
static char* ptr;
static UString* pkey;
static UString* pvalue;
@ -32,7 +33,7 @@ if (*pwbuffer == '\0')
u_put_unalignedp64(pwbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
u_put_unalignedp16(pwbuffer+52, U_MULTICHAR_CONSTANT16('\r','\n'));
UValue::pstringify = pwbuffer + U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n");
ptr = pwbuffer + U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n");
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n") + 27);
}
@ -40,5 +41,7 @@ if (*pwbuffer == '\0')
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->c_pointer(44)), U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'))
UValue::pstringify = ptr;
UValue(*pkey, *pvalue).stringify();
-->

View File

@ -1 +1,2 @@
loadStaticLinkedModules(U_STRING_FROM_CONSTANT("pgsql"));

View File

@ -105,12 +105,25 @@ set_ADDRESS() {
# function : prepare_usp
prepare_usp() {
# rm -f db.la query.la update.la fortune.la cached_worlds.la \
# mdb.la mquery.la mupdate.la mfortune.la \
# rdb.la rquery.la rupdate.la rfortune.la \
# edb.la equery.la eupdate.la; \
# AM_LDFLAGS="-lWorld" make db.la query.la update.la cached_worlds.la 2>&1; \
# AM_LDFLAGS="-lWorld -lWorldNoSql" make mdb.la mquery.la mupdate.la 2>&1; \
# AM_LDFLAGS="-lWorld -lWorldNoSql" make rdb.la rquery.la rupdate.la 2>&1; \
# AM_LDFLAGS="-lWorld -lWorldNoSql" make edb.la equery.la eupdate.la 2>&1; \
# AM_LDFLAGS="-lFortune" make fortune.la 2>&1; \
# AM_LDFLAGS="-lFortune -lFortuneNoSql" make mfortune.la 2>&1; \
# AM_LDFLAGS="-lFortune -lFortuneNoSql" make rfortune.la 2>&1; \
if [ "$TERM" != "cygwin" ]; then
if [ ! -d ../db ]; then
mkdir -p ../db
fi
rm -f ../db/session.ssl.jnl
( cd ../../src/ulib/net/server/plugin/usp/; ./usp2so.sh >/tmp/usp2so.sh.out 2>&1 || exit 1; \
( cd ../../src/ulib/net/server/plugin/usp/; make; \
./usp2so.sh >/tmp/usp2so.sh.out 2>&1 || exit 1; \
test -d ../.libs && cd ../.libs; \
ln -sf ../v8/.libs/server_plugin_v8.so; \
ln -sf ../php/.libs/server_plugin_php.so; \

View File

@ -32,36 +32,36 @@ export ORM_DRIVER ORM_OPTION UMEMPOOL
#Running 15s test @ http://localhost:8080/plaintext
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 0.91ms 564.97us 25.85ms 97.24%
# Req/Sec 615.24k 52.86k 0.90M 75.81%
# Latency 0.91ms 208.81us 11.38ms 80.51%
# Req/Sec 606.98k 39.03k 699.20k 71.14%
# Latency Distribution
# 50% 0.86ms
# 75% 0.95ms
# 90% 1.04ms
# 99% 1.80ms
# 34769232 requests in 15.00s, 4.18GB read
#Requests/sec: 2318061.92
#Transfer/sec: 285.18MB
# 50% 0.90ms
# 75% 1.01ms
# 90% 1.11ms
# 99% 1.76ms
# 34226368 requests in 14.94s, 4.11GB read
#Requests/sec: 2290284.44
#Transfer/sec: 281.76MB
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
# JSON
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
UMEMPOOL="237,0,0,49,273,-15,-14,-20,36"
sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
#UMEMPOOL="237,0,0,49,273,-15,-14,-20,36"
#sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET 0|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
#sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
#Running 15s test @ http://localhost:8080/json
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 404.71us 577.61us 13.07ms 98.46%
# Req/Sec 92.85k 19.62k 174.55k 79.88%
# Latency 353.08us 168.28us 8.74ms 84.43%
# Req/Sec 93.33k 8.35k 167.78k 68.27%
# Latency Distribution
# 50% 333.00us
# 75% 458.00us
# 90% 581.00us
# 99% 1.86ms
# 5256998 requests in 15.00s, 747.01MB read
#Requests/sec: 350480.62
#Transfer/sec: 49.80MB
# 50% 327.00us
# 75% 451.00us
# 90% 516.00us
# 99% 745.00us
# 5280348 requests in 15.00s, 750.32MB read
#Requests/sec: 352026.18
#Transfer/sec: 50.02MB
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
# DB
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
@ -69,53 +69,67 @@ export ORM_DRIVER ORM_OPTION UMEMPOOL
#ORM_OPTION="host=localhost dbname=../db/hello_world"
#ORM_DRIVER="mysql"
#ORM_OPTION="host=localhost user=benchmarkdbuser password=benchmarkdbpass character-set=utf8 dbname=hello_world"
#ORM_DRIVER="pgsql"
#ORM_OPTION="host=localhost user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world"
#UMEMPOOL="545,0,0,49,275,-14,-13,-25,41"
#sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET -2|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
#sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
ORM_DRIVER="pgsql"
ORM_OPTION="host=localhost user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world"
UMEMPOOL="581,0,0,66,16416,-7,-20,-23,31"
sed -i "s|TCP_LINGER_SET .*|TCP_LINGER_SET -2|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
sed -i "s|LISTEN_BACKLOG .*|LISTEN_BACKLOG 256|g" benchmark/FrameworkBenchmarks/fbenchmark.cfg
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
#Running 15s test @ http://localhost:8080/fortune
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 0.97ms 444.01us 7.95ms 66.95%
# Req/Sec 35.76k 4.13k 53.33k 62.05%
# Latency 5.97ms 2.42ms 16.39ms 94.85%
# Req/Sec 8.63k 2.15k 11.82k 92.32%
# Latency Distribution
# 50% 0.93ms
# 75% 1.26ms
# 90% 1.56ms
# 99% 2.16ms
# 2023409 requests in 15.00s, 2.53GB read
#Requests/sec: 134905.88
#Transfer/sec: 172.91MB
# 50% 5.21ms
# 75% 6.09ms
# 90% 6.47ms
# 99% 16.39ms
# 520090 requests in 16.00s, 674.06MB read
#Requests/sec: 32502.85
#Transfer/sec: 42.13MB
#
#Running 15s test @ http://localhost:8080/db
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 663.80us 318.91us 22.24ms 74.68%
# Req/Sec 51.90k 4.80k 69.00k 76.78%
# Latency 5.59ms 1.04ms 11.43ms 78.71%
# Req/Sec 9.25k 1.44k 12.09k 90.49%
# Latency Distribution
# 50% 631.00us
# 75% 839.00us
# 90% 1.04ms
# 99% 1.47ms
# 2917228 requests in 15.00s, 425.05MB read
#Requests/sec: 194484.25
#Transfer/sec: 28.34MB
# 50% 5.69ms
# 75% 6.05ms
# 90% 6.39ms
# 99% 11.05ms
# 539816 requests in 16.01s, 78.25MB read
#Requests/sec: 33720.45
#Transfer/sec: 4.89MB
#
#Running 15s test @ http://localhost:8080/query?queries=20
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 2.44ms 1.20ms 32.83ms 68.96%
# Req/Sec 14.40k 2.68k 24.89k 68.36%
# Latency 30.71ms 1.41ms 37.71ms 75.83%
# Req/Sec 1.34k 355.28 2.00k 62.54%
# Latency Distribution
# 50% 2.31ms
# 75% 3.16ms
# 90% 4.05ms
# 99% 5.66ms
# 817586 requests in 15.00s, 592.28MB read
#Requests/sec: 54503.98
#Transfer/sec: 39.48MB
# 50% 30.01ms
# 75% 31.05ms
# 90% 33.01ms
# 99% 34.28ms
# 59809 requests in 16.02s, 43.63MB read
#Requests/sec: 3734.19
#Transfer/sec: 2.72MB
#
#Running 15s test @ http://localhost:8080/update?queries=20
# 4 threads and 256 connections
# Thread Stats Avg Stdev Max +/- Stdev
# Latency 979.35ms 123.76ms 1.23s 74.15%
# Req/Sec 37.42 25.76 70.00 52.78%
# Latency Distribution
# 50% 954.28ms
# 75% 1.03s
# 90% 1.23s
# 99% 1.23s
# 1263 requests in 16.01s, 0.92MB read
#Requests/sec: 78.89
#Transfer/sec: 58.70KB
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
#export REDIS_HOST=localhost
#UMEMPOOL="1261,0,0,49,274,-14,-15,-24,40"
@ -143,7 +157,7 @@ export ORM_DRIVER ORM_OPTION UMEMPOOL
# ----------------------------------------------------------------------------------------------------------------------------------------------------------
DIR_CMD="../../examples/userver"
prepare_usp
#prepare_usp
mkdir -p $DOC_ROOT
@ -151,23 +165,27 @@ mkdir -p $DOC_ROOT
# ln -sf ../../../docroot/servlet; \
# ln -sf ../../../docroot/100.html; \
# ln -sf ../../../docroot/1000.html; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rdb.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mdb.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rupdate.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mupdate.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rquery.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mquery.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rfortune.so; \
# ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mfortune.so;
# make json.la plaintext.la
#AM_LDFLAGS="-lWorld" make db.la query.la update.la cached_worlds.la
#AM_LDFLAGS="-lFortune" make fortune.la
if [ "$TERM" != "cygwin" ]; then
( cd $DOC_ROOT; rm -f *; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/json.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/plaintext.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/db.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rdb.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mdb.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/update.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rupdate.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mupdate.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/query.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rquery.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mquery.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/fortune.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/rfortune.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/mfortune.so )
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/db.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/update.so; \
ln -sf ../../../../../../src/ulib/net/server/plugin/usp/.libs/fortune.so )
fi
# ----------------------------------------------------------------------------------------------------------------------------------------------------------

View File

@ -1 +1 @@
0230
023E

View File

@ -5,26 +5,33 @@ TechEmpower Web Framework Benchmarks
<!--#declaration
#include "world.h"
#ifdef U_STATIC_ORM_DRIVER_PGSQL
static void handlerResult(void* res, uint32_t num_result)
{
U_TRACE(5, "::handlerResult(%p,%u)", res, num_result)
U_INTERNAL_ASSERT_EQUALS(num_result, 1)
U_INTERNAL_ASSERT_EQUALS(PQnfields((PGresult*)res), 1)
U_INTERNAL_ASSERT_EQUALS(PQntuples((PGresult*)res), 1)
char* randomNumber = U_SYSCALL(PQgetvalue, "%p,%d,%d", (PGresult*)res, 0, 0);
World::handlerOneResult(ntohl(*(uint32_t*)randomNumber));
}
#endif
static void usp_init_db() { World::handlerInitSql(); }
static void usp_fork_db() { World::handlerForkSql(); }
-->
<!--#header
-->
<!--#code
World::initOneResult();
#ifdef U_STATIC_ORM_DRIVER_PGSQL
if (World::pdrv)
{
PGresult* res = World::execPrepared();
World::sendQueryPrepared();
U_INTERNAL_ASSERT_EQUALS(PQnfields(res), 1)
U_INTERNAL_ASSERT_EQUALS(PQntuples(res), 1)
char* randomNumber = U_SYSCALL(PQgetvalue, "%p,%d,%d", res, 0, 0);
World::handlerOneResult(World::rnumber[0], ntohl(*(uint32_t*)randomNumber));
U_SYSCALL_VOID(PQclear, "%p", res);
((UEventDB*)UServer_Base::handler_db1)->addClientImage(handlerResult);
}
else
#endif
@ -33,8 +40,6 @@ World::pworld_query->id = World::rnumber[0];
(void) World::pstmt_query->execute();
World::handlerOneResult(World::pworld_query->id, World::pworld_query->randomNumber);
World::handlerOneResult(World::pworld_query->randomNumber);
}
World::endOneResult();
-->

View File

@ -11,238 +11,347 @@
#include <ulib/net/server/client_image.h>
#ifdef U_STATIC_ORM_DRIVER_PGSQL
# include <ulib/event/event_db.h>
# include <ulib/orm/driver/orm_driver_pgsql.h>
#endif
class Fortune {
class U_EXPORT Fortune {
public:
uint32_t id;
UString message;
// Check for memory error
U_MEMORY_TEST
Fortune(uint32_t _id) : id(_id), message(101U)
{
U_TRACE_CTOR(5, Fortune, "%u", _id)
}
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
Fortune(uint32_t _id, const UString& _message) : id(_id), message(_message)
{
U_TRACE_CTOR(5, Fortune, "%u,%V", _id, _message.rep)
}
uint32_t id;
UString message;
Fortune(const Fortune& f) : id(f.id), message(f.message)
{
U_TRACE_CTOR(5, Fortune, "%p", &f)
Fortune(uint32_t _id) : id(_id), message(101U)
{
U_TRACE_CTOR(5, Fortune, "%u", _id)
}
U_MEMORY_TEST_COPY(f)
}
Fortune(uint32_t _id, const UString& _message) : id(_id), message(_message)
{
U_TRACE_CTOR(5, Fortune, "%u,%V", _id, _message.rep)
}
~Fortune()
{
U_TRACE_DTOR(5, Fortune)
}
Fortune(const Fortune& f) : id(f.id), message(f.message)
{
U_TRACE_CTOR(5, Fortune, "%p", &f)
// SERVICE
U_MEMORY_TEST_COPY(f)
}
bool operator<(const Fortune& other) const { return cmp_obj(&message, &other.message); }
~Fortune()
{
U_TRACE_DTOR(5, Fortune)
}
static int cmp_obj(const void* a, const void* b)
{
U_TRACE(5, "Fortune::cmp_obj(%p,%p)", a, b)
// SERVICE
# ifdef U_STDCPP_ENABLE
/**
* The comparison function must follow a strict-weak-ordering
*
* 1) For all x, it is not the case that x < x (irreflexivity)
* 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
* 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
* 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
*/
bool operator<(const Fortune& other) const { return cmp_obj(&message, &other.message); }
return (((const Fortune*)a)->message.compare(((const Fortune*)b)->message) < 0);
# else
return (*(const Fortune**)a)->message.compare((*(const Fortune**)b)->message);
# endif
}
static int cmp_obj(const void* a, const void* b)
{
U_TRACE(5, "Fortune::cmp_obj(%p,%p)", a, b)
// JSON
# ifdef U_STDCPP_ENABLE
/**
* The comparison function must follow a strict-weak-ordering
*
* 1) For all x, it is not the case that x < x (irreflexivity)
* 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
* 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
* 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
*/
void toJSON(UString& json)
{
U_TRACE(5, "Fortune::toJSON(%V)", json.rep)
return (((const Fortune*)a)->message.compare(((const Fortune*)b)->message) < 0);
# else
return (*(const Fortune**)a)->message.compare((*(const Fortune**)b)->message);
# endif
}
json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.toJSON(U_JSON_METHOD_HANDLER(message, UString));
}
// JSON
void fromJSON(UValue& json)
{
U_TRACE(5, "Fortune::fromJSON(%p)", &json)
void toJSON(UString& json)
{
U_TRACE(5, "Fortune::toJSON(%V)", json.rep)
json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.fromJSON(U_JSON_METHOD_HANDLER(message, UString));
}
json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.toJSON(U_JSON_METHOD_HANDLER(message, UString));
}
// ORM
void fromJSON(UValue& json)
{
U_TRACE(5, "Fortune::fromJSON(%p)", &json)
void bindParam(UOrmStatement* stmt)
{
U_TRACE(5, "Fortune::bindParam(%p)", stmt)
json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.fromJSON(U_JSON_METHOD_HANDLER(message, UString));
}
stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindParam(U_ORM_TYPE_HANDLER(message, UString));
}
// ORM
void bindResult(UOrmStatement* stmt)
{
U_TRACE(5, "Fortune::bindResult(%p)", stmt)
void bindParam(UOrmStatement* stmt)
{
U_TRACE(5, "Fortune::bindParam(%p)", stmt)
stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindResult(U_ORM_TYPE_HANDLER(message, UString));
}
stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindParam(U_ORM_TYPE_HANDLER(message, UString));
}
static uint32_t uid;
static UString* pmessage;
static UVector<Fortune*>* pvfortune;
void bindResult(UOrmStatement* stmt)
{
U_TRACE(5, "Fortune::bindResult(%p)", stmt)
static UOrmSession* psql_fortune;
static UOrmStatement* pstmt_fortune;
stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindResult(U_ORM_TYPE_HANDLER(message, UString));
}
static void replace(uint32_t i, uint32_t _id, const char* msg, uint32_t len)
{
U_TRACE(5, "Fortune::replace(%u,%u,%.*S,%u)", i, _id, len, msg, len)
static uint32_t uid;
static char* pwbuffer;
static UString* pmessage;
static UVector<Fortune*>* pvfortune;
U_INTERNAL_ASSERT_POINTER(pvfortune)
static UOrmSession* psql_fortune;
static UOrmStatement* pstmt_fortune;
Fortune* elem = pvfortune->at(i);
#ifdef U_STATIC_ORM_DRIVER_PGSQL
static PGconn* conn;
static UOrmDriverPgSql* pdrv;
static UPgSqlStatement* pstmt;
elem->id = _id;
static PGresult* execPrepared()
{
U_TRACE_NO_PARAM(5, "Fortune::execPrepared()")
UXMLEscape::encode(msg, len, elem->message);
}
PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 0, 0, 0, 0, 1);
static void replace(uint32_t i) { replace(i, uid, U_STRING_TO_PARAM(*pmessage)); }
static void replace(uint32_t i, uint32_t _id) { replace(i, _id, U_STRING_TO_PARAM(*pmessage)); }
static void replace(uint32_t i, const UString& message) { replace(i, i+1, U_STRING_TO_PARAM(message)); }
static void replace(uint32_t i, uint32_t _id, const UString& message) { replace(i, _id, U_STRING_TO_PARAM(message)); }
U_RETURN_POINTER(res, PGresult);
}
static void doQuery(vPF handlerQuery)
{
U_TRACE(5, "Fortune::doQuery(%p)", handlerQuery)
static void sendQueryPrepared()
{
U_TRACE_NO_PARAM(5, "Fortune::sendQueryPrepared()")
U_INTERNAL_ASSERT_POINTER(pvfortune)
(void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 0, 0, 0, 0, 1);
}
#endif
char* pwbuffer = UClientImage_Base::wbuffer->data();
static void replace(uint32_t i, uint32_t _id, const char* msg, uint32_t len)
{
U_TRACE(5, "Fortune::replace(%u,%u,%.*S,%u)", i, _id, len, msg, len)
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(pwbuffer+16, U_MULTICHAR_CONSTANT64('1','2','2','7','\r','\n','C','o'));
u_put_unalignedp64(pwbuffer+24, U_MULTICHAR_CONSTANT64('n','t','e','n','t','-','T','y'));
u_put_unalignedp64(pwbuffer+32, U_MULTICHAR_CONSTANT64('p','e',':',' ','t','e','x','t'));
u_put_unalignedp64(pwbuffer+40, U_MULTICHAR_CONSTANT64('/','h','t','m','l',';',' ','c'));
u_put_unalignedp64(pwbuffer+48, U_MULTICHAR_CONSTANT64('h','a','r','s','e','t','=','U'));
u_put_unalignedp64(pwbuffer+56, U_MULTICHAR_CONSTANT64('T','F','-','8','\r','\n','\r','\n'));
u_put_unalignedp64(pwbuffer+64, U_MULTICHAR_CONSTANT64('<','!','d','o','c','t','y','p'));
u_put_unalignedp64(pwbuffer+72, U_MULTICHAR_CONSTANT64('e',' ','h','t','m','l','>','<'));
u_put_unalignedp64(pwbuffer+80, U_MULTICHAR_CONSTANT64('h','t','m','l','>','<','h','e'));
u_put_unalignedp64(pwbuffer+88, U_MULTICHAR_CONSTANT64('a','d','>','<','t','i','t','l'));
u_put_unalignedp64(pwbuffer+96, U_MULTICHAR_CONSTANT64('e','>','F','o','r','t','u','n'));
u_put_unalignedp64(pwbuffer+104, U_MULTICHAR_CONSTANT64('e','s','<','/','t','i','t','l'));
u_put_unalignedp64(pwbuffer+112, U_MULTICHAR_CONSTANT64('e','>','<','/','h','e','a','d'));
u_put_unalignedp64(pwbuffer+120, U_MULTICHAR_CONSTANT64('>','<','b','o','d','y','>','<'));
u_put_unalignedp64(pwbuffer+128, U_MULTICHAR_CONSTANT64('t','a','b','l','e','>','<','t'));
u_put_unalignedp64(pwbuffer+136, U_MULTICHAR_CONSTANT64('r','>','<','t','h','>','i','d'));
u_put_unalignedp64(pwbuffer+144, U_MULTICHAR_CONSTANT64('<','/','t','h','>','<','t','h'));
u_put_unalignedp64(pwbuffer+152, U_MULTICHAR_CONSTANT64('>','m','e','s','s','a','g','e'));
u_put_unalignedp64(pwbuffer+160, U_MULTICHAR_CONSTANT64('<','/','t','h','>','<','/','t'));
u_put_unalignedp16(pwbuffer+168, U_MULTICHAR_CONSTANT16('r','>'));
U_INTERNAL_ASSERT_POINTER(pvfortune)
pwbuffer += U_CONSTANT_SIZE("Content-Length: 1227\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n"
"<!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");
Fortune* elem = pvfortune->at(i);
handlerQuery();
elem->id = _id;
Fortune* elem = pvfortune->last();
UXMLEscape::encode(msg, len, elem->message);
}
elem->id = 0;
elem->message.rep->replace(U_CONSTANT_TO_PARAM("Additional fortune added at request time."));
static void replace(uint32_t i) { replace(i, uid, U_STRING_TO_PARAM(*pmessage)); }
static void replace(uint32_t i, uint32_t _id) { replace(i, _id, U_STRING_TO_PARAM(*pmessage)); }
static void replace(uint32_t i, const UString& message) { replace(i, i+1, U_STRING_TO_PARAM(message)); }
static void replace(uint32_t i, uint32_t _id, const UString& message) { replace(i, _id, U_STRING_TO_PARAM(message)); }
pvfortune->sort(Fortune::cmp_obj);
static void initQuery()
{
U_TRACE_NO_PARAM(5, "::initQuery()")
for (uint32_t sz, i = 0, n = pvfortune->size(); i < n; ++i)
{
elem = pvfortune->at(i);
char* ptr = UClientImage_Base::wbuffer->data();
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('<','t','r','>','<','t','d','>'));
U_INTERNAL_DUMP("wbuffer(%u) = %#.10S", UClientImage_Base::wbuffer->size(), ptr)
pwbuffer = u_num2str32(elem->id, pwbuffer+8);
if (*ptr == '\0')
{
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('1','2','2','7','\r','\n','C','o'));
u_put_unalignedp64(ptr+24, U_MULTICHAR_CONSTANT64('n','t','e','n','t','-','T','y'));
u_put_unalignedp64(ptr+32, U_MULTICHAR_CONSTANT64('p','e',':',' ','t','e','x','t'));
u_put_unalignedp64(ptr+40, U_MULTICHAR_CONSTANT64('/','h','t','m','l',';',' ','c'));
u_put_unalignedp64(ptr+48, U_MULTICHAR_CONSTANT64('h','a','r','s','e','t','=','U'));
u_put_unalignedp64(ptr+56, U_MULTICHAR_CONSTANT64('T','F','-','8','\r','\n','\r','\n'));
u_put_unalignedp64(ptr+64, U_MULTICHAR_CONSTANT64('<','!','d','o','c','t','y','p'));
u_put_unalignedp64(ptr+72, U_MULTICHAR_CONSTANT64('e',' ','h','t','m','l','>','<'));
u_put_unalignedp64(ptr+80, U_MULTICHAR_CONSTANT64('h','t','m','l','>','<','h','e'));
u_put_unalignedp64(ptr+88, U_MULTICHAR_CONSTANT64('a','d','>','<','t','i','t','l'));
u_put_unalignedp64(ptr+96, U_MULTICHAR_CONSTANT64('e','>','F','o','r','t','u','n'));
u_put_unalignedp64(ptr+104, U_MULTICHAR_CONSTANT64('e','s','<','/','t','i','t','l'));
u_put_unalignedp64(ptr+112, U_MULTICHAR_CONSTANT64('e','>','<','/','h','e','a','d'));
u_put_unalignedp64(ptr+120, U_MULTICHAR_CONSTANT64('>','<','b','o','d','y','>','<'));
u_put_unalignedp64(ptr+128, U_MULTICHAR_CONSTANT64('t','a','b','l','e','>','<','t'));
u_put_unalignedp64(ptr+136, U_MULTICHAR_CONSTANT64('r','>','<','t','h','>','i','d'));
u_put_unalignedp64(ptr+144, U_MULTICHAR_CONSTANT64('<','/','t','h','>','<','t','h'));
u_put_unalignedp64(ptr+152, U_MULTICHAR_CONSTANT64('>','m','e','s','s','a','g','e'));
u_put_unalignedp64(ptr+160, U_MULTICHAR_CONSTANT64('<','/','t','h','>','<','/','t'));
u_put_unalignedp16(ptr+168, U_MULTICHAR_CONSTANT16('r','>'));
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('<','/','t','d','>','<','t','d'));
pwbuffer += 8;
pwbuffer = ptr + U_CONSTANT_SIZE("Content-Length: 1227\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n"
"<!doctype html><html><head><title>Fortunes</title></head><body><table><tr><th>id</th><th>message</th></tr>");
*pwbuffer++ = '>';
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 1227\r\nContent-Type: text/html; charset=UTF-8\r\n\r\n") + 1227);
}
(void) memcpy(pwbuffer, elem->message.data(), sz = elem->message.size());
pwbuffer += sz;
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->c_pointer(48)), U_MULTICHAR_CONSTANT64('h','a','r','s','e','t','=','U'))
}
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('<','/','t','d','>','<','/','t'));
u_put_unalignedp16(pwbuffer+8, U_MULTICHAR_CONSTANT16('r','>'));
pwbuffer += 8+2;
}
static void endQuery()
{
U_TRACE_NO_PARAM(5, "::endQuery()")
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('<','/','t','a','b','l','e','>'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('<','/','b','o','d','y','>','<'));
u_put_unalignedp64(pwbuffer+16, U_MULTICHAR_CONSTANT64('/','h','t','m','l','>','\0','\0'));
U_INTERNAL_ASSERT_POINTER(pvfortune)
UClientImage_Base::wbuffer->size_adjust_constant(pwbuffer + U_CONSTANT_SIZE("</table></body></html>"));
}
Fortune* elem = pvfortune->last();
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerFork()")
elem->id = 0;
elem->message.rep->replace(U_CONSTANT_TO_PARAM("Additional fortune added at request time."));
U_NEW_STRING(pmessage, UString(101U));
pvfortune->sort(Fortune::cmp_obj);
U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
char* ptr = pwbuffer;
Fortune* elem;
for (uint32_t sz, i = 0, n = pvfortune->size(); i < n; ++i)
{
elem = pvfortune->at(i);
for (uint32_t i = 0; i < 13; ++i)
{
U_NEW(Fortune, elem, Fortune(i+1));
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('<','t','r','>','<','t','d','>'));
pvfortune->push(elem);
}
}
ptr = u_num2str32(elem->id, ptr+8);
static void handlerForkSql()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerForkSql()")
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('<','/','t','d','>','<','t','d'));
ptr += 8;
if (psql_fortune == U_NULLPTR)
{
U_NEW(UOrmSession, psql_fortune, UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
*ptr++ = '>';
if (psql_fortune->isReady() == false)
{
U_WARNING("Fortune::handlerForkSql(): we cound't connect to db");
(void) memcpy(ptr, elem->message.data(), sz = elem->message.size());
ptr += sz;
U_DELETE(psql_fortune)
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('<','/','t','d','>','<','/','t'));
u_put_unalignedp16(ptr+8, U_MULTICHAR_CONSTANT16('r','>'));
ptr += 8+2;
}
psql_fortune = U_NULLPTR;
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64('<','/','t','a','b','l','e','>'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('<','/','b','o','d','y','>','<'));
u_put_unalignedp64(ptr+16, U_MULTICHAR_CONSTANT64('/','h','t','m','l','>','\0','\0'));
}
return;
}
static void doQuery(vPF handlerQuery)
{
U_TRACE(5, "Fortune::doQuery(%p)", handlerQuery)
U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
initQuery();
handlerQuery();
endQuery();
}
handlerFork();
static void handlerInitSql()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerInitSql()")
pstmt_fortune->into(uid, *pmessage);
}
}
# ifdef U_STATIC_ORM_DRIVER_PGSQL
U_INTERNAL_DUMP("UServer_Base::handler_db2 = %p", UServer_Base::handler_db2)
if (UServer_Base::handler_db2 == U_NULLPTR)
{
U_NEW_WITHOUT_CHECK_MEMORY(UEventDB, UServer_Base::handler_db2, UEventDB);
}
# endif
}
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerFork()")
U_NEW_STRING(pmessage, UString(101U));
U_NEW(UVector<Fortune*>, pvfortune, UVector<Fortune*>);
Fortune* elem;
for (uint32_t i = 0; i < 13; ++i)
{
U_NEW(Fortune, elem, Fortune(i+1));
pvfortune->push(elem);
}
}
static void handlerForkSql()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerForkSql()")
if (psql_fortune == U_NULLPTR)
{
U_NEW(UOrmSession, psql_fortune, UOrmSession(U_CONSTANT_TO_PARAM("fortune")));
if (psql_fortune->isReady() == false)
{
U_WARNING("Fortune::handlerForkSql(): we cound't connect to db");
U_DELETE(psql_fortune)
psql_fortune = U_NULLPTR;
return;
}
U_NEW(UOrmStatement, pstmt_fortune, UOrmStatement(*psql_fortune, U_CONSTANT_TO_PARAM("SELECT id, message FROM Fortune")));
handlerFork();
pstmt_fortune->into(uid, *pmessage);
# ifdef U_STATIC_ORM_DRIVER_PGSQL
if (UOrmDriver::isPGSQL())
{
conn = (PGconn*)(pdrv = (UOrmDriverPgSql*)psql_fortune->getDriver())->UOrmDriver::connection;
pstmt = (UPgSqlStatement*)pstmt_fortune->getStatement();
pstmt->prepareStatement(pdrv);
((UEventDB*)UServer_Base::handler_db2)->setConnection(conn);
}
# endif
}
}
#ifdef DEBUG
static void handlerEnd()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerEnd()")
U_INTERNAL_ASSERT_POINTER(pmessage)
U_INTERNAL_ASSERT_POINTER(pvfortune)
U_DELETE(pmessage)
U_DELETE(pvfortune)
}
static void handlerEndSql()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerEndSql()")
if (pstmt_fortune)
{
handlerEnd();
U_DELETE(psql_fortune)
U_DELETE(pstmt_fortune)
pstmt_fortune = U_NULLPTR;
}
}
const char* dump(bool breset) const;
#endif
private:
U_DISALLOW_ASSIGN(Fortune)
U_DISALLOW_ASSIGN(Fortune)
};
#endif

View File

@ -5,12 +5,6 @@ TechEmpower Web Framework Benchmarks
<!--#declaration
#include "fortune.h"
static vPF handle_query;
#ifdef U_STATIC_ORM_DRIVER_PGSQL
static UOrmDriverPgSql* pdrv;
static UPgSqlStatement* pstmt;
#endif
static void handlerQuery()
{
U_TRACE_NO_PARAM(5, "::handlerQuery()")
@ -25,53 +19,49 @@ static void handlerQuery()
while (Fortune::pstmt_fortune->nextRow());
}
static void handlerQueryPGSQL()
{
U_TRACE_NO_PARAM(5, "::handlerQueryPGSQL()")
#ifdef U_STATIC_ORM_DRIVER_PGSQL
static void handlerResult(void* res, uint32_t num_result)
{
U_TRACE(5, "::handlerResult(%p,%u)", res, num_result)
U_INTERNAL_ASSERT_EQUALS(num_result, 1)
U_INTERNAL_ASSERT_EQUALS(PQnfields((PGresult*)res), 2)
int sz;
char* id;
char* ptr;
PGresult* res = pdrv->execPrepared(pstmt);
U_INTERNAL_ASSERT_EQUALS(PQnfields(res), 2)
Fortune::initQuery();
for (uint32_t i = 0, n = U_SYSCALL(PQntuples, "%p", res); i < n; ++i)
for (uint32_t i = 0, n = U_SYSCALL(PQntuples, "%p", (PGresult*)res); i < n; ++i)
{
id = U_SYSCALL(PQgetvalue, "%p,%d,%d", res, i, 0);
ptr = U_SYSCALL(PQgetvalue, "%p,%d,%d", res, i, 1);
sz = U_SYSCALL(PQgetlength, "%p,%d,%d", res, i, 1);
id = U_SYSCALL(PQgetvalue, "%p,%d,%d", (PGresult*)res, i, 0);
ptr = U_SYSCALL(PQgetvalue, "%p,%d,%d", (PGresult*)res, i, 1);
sz = U_SYSCALL(PQgetlength, "%p,%d,%d", (PGresult*)res, i, 1);
Fortune::replace(i, ntohl(*(uint32_t*)id), ptr, sz);
}
U_SYSCALL_VOID(PQclear, "%p", res);
Fortune::endQuery();
}
#endif
}
static void usp_fork_fortune()
{
U_TRACE_NO_PARAM(5, "::usp_fork_fortune()")
Fortune::handlerForkSql();
if (UOrmDriver::isPGSQL() == false) handle_query = handlerQuery;
else
{
handle_query = handlerQueryPGSQL;
# ifdef U_STATIC_ORM_DRIVER_PGSQL
pdrv = (UOrmDriverPgSql*) Fortune::psql_fortune->getDriver();
pstmt = (UPgSqlStatement*) Fortune::pstmt_fortune->getStatement();
pstmt->prepareStatement(pdrv);
# endif
}
}
static void usp_init_fortune() { Fortune::handlerInitSql(); }
static void usp_fork_fortune() { Fortune::handlerForkSql(); }
-->
<!--#header
-->
<!--#code
Fortune::doQuery(handle_query);
#ifdef U_STATIC_ORM_DRIVER_PGSQL
if (Fortune::pdrv)
{
Fortune::sendQueryPrepared();
((UEventDB*)UServer_Base::handler_db2)->addClientImage(handlerResult);
}
else
#endif
{
Fortune::doQuery(handlerQuery);
}
-->

View File

@ -12,104 +12,136 @@
# include <ulib/net/client/mongodb.h>
#endif
class FortuneNoSql {
class U_EXPORT FortuneNoSql {
public:
#ifdef USE_MONGODB
static UMongoDBClient* mc;
static UMongoDBClient* mc;
#endif
static void handlerQueryMongoDB()
{
U_TRACE(5, "FortuneNoSql::handlerQueryMongoDB()")
static void handlerQueryMongoDB()
{
U_TRACE(5, "FortuneNoSql::handlerQueryMongoDB()")
U_INTERNAL_ASSERT_POINTER(Fortune::pmessage)
U_INTERNAL_ASSERT_POINTER(Fortune::pmessage)
# ifdef USE_MONGODB
(void) mc->findAll();
# ifdef USE_MONGODB
(void) mc->findAll();
for (uint32_t i = 0, n = mc->vitem.size(); i < n; ++i)
{
(void) U_JFIND(mc->vitem[i], "message", *Fortune::pmessage);
for (uint32_t i = 0, n = mc->vitem.size(); i < n; ++i)
{
(void) U_JFIND(mc->vitem[i], "message", *Fortune::pmessage);
Fortune::replace(i, i+1);
Fortune::replace(i, i+1);
Fortune::pmessage->clear();
}
# endif
}
Fortune::pmessage->clear();
}
# endif
}
static void handlerForkMongoDB()
{
U_TRACE_NO_PARAM(5, "FortuneNoSql::handlerForkMongoDB()")
static void handlerForkMongoDB()
{
U_TRACE_NO_PARAM(5, "FortuneNoSql::handlerForkMongoDB()")
# ifdef USE_MONGODB
if (mc == U_NULLPTR)
{
U_NEW(UMongoDBClient, mc, UMongoDBClient);
# ifdef USE_MONGODB
if (mc == U_NULLPTR)
{
U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect(U_NULLPTR, 0) == false)
{
U_WARNING("FortuneNoSql::handlerForkMongoDB(): connection failed");
if (mc->connect(U_NULLPTR, 0) == false)
{
U_WARNING("FortuneNoSql::handlerForkMongoDB(): connection failed");
U_DELETE(mc)
U_DELETE(mc)
mc = U_NULLPTR;
mc = U_NULLPTR;
return;
}
return;
}
if (mc->selectCollection("hello_world", "fortune") == false)
{
U_WARNING("FortuneNoSql::handlerForkMongoDB(): selectCollection() failed");
if (mc->selectCollection("hello_world", "fortune") == false)
{
U_WARNING("FortuneNoSql::handlerForkMongoDB(): selectCollection() failed");
U_DELETE(mc)
U_DELETE(mc)
mc = U_NULLPTR;
mc = U_NULLPTR;
return;
}
return;
}
Fortune::handlerFork();
}
# endif
}
Fortune::handlerFork();
}
# endif
}
static UREDISClient_Base* rc;
static UREDISClient_Base* rc;
static void handlerQueryREDIS()
{
U_TRACE(5, "FortuneNoSql::handlerQueryREDIS()")
static void handlerQueryREDIS()
{
U_TRACE(5, "FortuneNoSql::handlerQueryREDIS()")
(void) rc->lrange(U_CONSTANT_TO_PARAM("fortunes 0 -1"));
(void) rc->lrange(U_CONSTANT_TO_PARAM("fortunes 0 -1"));
for (uint32_t i = 0, n = rc->vitem.size(); i < n; ++i) Fortune::replace(i, rc->vitem[i]);
}
for (uint32_t i = 0, n = rc->vitem.size(); i < n; ++i) Fortune::replace(i, rc->vitem[i]);
}
static void handlerForkREDIS()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerForkREDIS()")
static void handlerForkREDIS()
{
U_TRACE_NO_PARAM(5, "Fortune::handlerForkREDIS()")
if (rc == U_NULLPTR)
{
U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
if (rc == U_NULLPTR)
{
U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
if (rc->connect() == false)
{
U_WARNING("FortuneNoSql::handlerForkREDIS(): %V", rc->UClient_Base::getResponse().rep);
if (rc->connect() == false)
{
U_WARNING("FortuneNoSql::handlerForkREDIS(): %V", rc->UClient_Base::getResponse().rep);
U_DELETE(rc)
U_DELETE(rc)
rc = U_NULLPTR;
rc = U_NULLPTR;
return;
}
return;
}
Fortune::handlerFork();
}
}
Fortune::handlerFork();
}
}
#ifdef DEBUG
static void handlerEndMongoDB()
{
U_TRACE_NO_PARAM(5, "FortuneNoSql::handlerEndMongoDB()")
# ifdef USE_MONGODB
if (mc)
{
Fortune::handlerEnd();
U_DELETE(mc)
mc = U_NULLPTR;
}
# endif
}
static void handlerEndREDIS()
{
U_TRACE_NO_PARAM(5, "FortuneNoSql::handlerEndREDIS()")
if (rc)
{
Fortune::handlerEnd();
U_DELETE(rc)
rc = U_NULLPTR;
}
}
#endif
private:
U_DISALLOW_ASSIGN(FortuneNoSql)
U_DISALLOW_ASSIGN(FortuneNoSql)
};
#endif

View File

@ -3,6 +3,7 @@ Test type 1: JSON serialization
TechEmpower Web Framework Benchmarks
-->
<!--#declaration
static char* ptr;
static UString* pkey;
static UString* pvalue;
@ -19,18 +20,28 @@ static void usp_init_json()
<!--#code
char* pwbuffer = UClientImage_Base::wbuffer->data();
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('2','7','\r','\n'));
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
u_put_unalignedp64(pwbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
u_put_unalignedp16(pwbuffer+52, U_MULTICHAR_CONSTANT16('\r','\n'));
U_INTERNAL_DUMP("pwbuffer = %#.10S", pwbuffer)
UValue::pstringify = pwbuffer + U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n");
if (*pwbuffer == '\0')
{
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('2','7','\r','\n'));
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
u_put_unalignedp64(pwbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
u_put_unalignedp16(pwbuffer+52, U_MULTICHAR_CONSTANT16('\r','\n'));
ptr = pwbuffer + U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n");
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 27\r\nContent-Type: application/json\r\n\r\n") + 27);
}
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->data()), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(UClientImage_Base::wbuffer->c_pointer(44)), U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'))
UValue::pstringify = ptr;
UValue(*pkey, *pvalue).stringify();
UClientImage_Base::wbuffer->size_adjust_constant(UValue::pstringify);
-->

View File

@ -2,8 +2,31 @@
#include "fortune.h"
uint32_t Fortune::uid;
UString* Fortune::pmessage;
UOrmSession* Fortune::psql_fortune;
UOrmStatement* Fortune::pstmt_fortune;
char* Fortune::pwbuffer;
uint32_t Fortune::uid;
UString* Fortune::pmessage;
UOrmSession* Fortune::psql_fortune;
UOrmStatement* Fortune::pstmt_fortune;
UVector<Fortune*>* Fortune::pvfortune;
#ifdef U_STATIC_ORM_DRIVER_PGSQL
PGconn* Fortune::conn;
UOrmDriverPgSql* Fortune::pdrv;
UPgSqlStatement* Fortune::pstmt;
#endif
#ifdef DEBUG
const char* Fortune::dump(bool breset) const
{
*UObjectIO::os << "id " << id << '\n'
<< "message (UString " << (void*)&message << ')';
if (breset)
{
UObjectIO::output();
return UObjectIO::buffer_output;
}
return U_NULLPTR;
}
#endif

View File

@ -3,6 +3,6 @@
#include "fortuneNoSql.h"
#ifdef USE_MONGODB
UMongoDBClient* FortuneNoSql::mc;
UMongoDBClient* FortuneNoSql::mc;
#endif
UREDISClient_Base* FortuneNoSql::rc;

View File

@ -2,16 +2,34 @@
#include "world.h"
char World::wbuffer[18000];
char* World::pwbuffer;
World* World::pworld_query;
uint32_t World::rnum;
uint32_t World::rnumber[500];
UOrmSession* World::psql_query;
UOrmStatement* World::pstmt_query;
char World::wbuffer[18000];
char* World::ptr;
char* World::pwbuffer;
World* World::pworld_query;
uint32_t World::rnum;
uint32_t World::rnumber[501];
UOrmSession* World::psql_query;
UOrmStatement* World::pstmt_query;
#ifdef U_STATIC_ORM_DRIVER_PGSQL
char World::num2str[sizeof(unsigned int)];
PGconn* World::conn;
char World::num2str[sizeof(unsigned int)];
PGconn* World::conn;
UOrmDriverPgSql* World::pdrv;
UPgSqlStatement* World::pstmt;
#endif
#ifdef DEBUG
const char* World::dump(bool breset) const
{
*UObjectIO::os << "id " << id << '\n'
<< "randomNumber " << randomNumber;
if (breset)
{
UObjectIO::output();
return UObjectIO::buffer_output;
}
return U_NULLPTR;
}
#endif

View File

@ -3,14 +3,14 @@
#include "worldNoSql.h"
#ifdef USE_MONGODB
bson_t* WorldNoSql::query;
UMongoDBClient* WorldNoSql::mc;
bson_t* WorldNoSql::query;
UMongoDBClient* WorldNoSql::mc;
#endif
char WorldNoSql::rc_buffer[128];
char WorldNoSql::es_buffer1[128];
char WorldNoSql::es_buffer2[128];
char* WorldNoSql::pbuffer1;
char* WorldNoSql::pbuffer2;
UString* WorldNoSql::str_rnumber;
UREDISClient_Base* WorldNoSql::rc;
char WorldNoSql::rc_buffer[128];
char WorldNoSql::es_buffer1[128];
char WorldNoSql::es_buffer2[128];
char* WorldNoSql::pbuffer1;
char* WorldNoSql::pbuffer2;
UString* WorldNoSql::str_rnumber;
UREDISClient_Base* WorldNoSql::rc;
UElasticSearchClient* WorldNoSql::es;

View File

@ -1 +1,18 @@
Hello, World!
<!--#header
-->
<!--#code
char* pwbuffer = UClientImage_Base::wbuffer->data();
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp32(pwbuffer+16, U_MULTICHAR_CONSTANT32('1','3','\r','\n'));
u_put_unalignedp64(pwbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(pwbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','t','e'));
u_put_unalignedp64(pwbuffer+36, U_MULTICHAR_CONSTANT64('x','t','/','p','l','a','i','n'));
u_put_unalignedp32(pwbuffer+44, U_MULTICHAR_CONSTANT32('\r','\n','\r','\n'));
UClientImage_Base::wbuffer->size_adjust_constant(U_CONSTANT_SIZE("Content-Length: 13\r\nContent-Type: text/plain\r\n\r\n") + 13);
u_put_unalignedp64(pwbuffer+48, U_MULTICHAR_CONSTANT64('H','e','l','l','o',',',' ','W'));
u_put_unalignedp64(pwbuffer+56, U_MULTICHAR_CONSTANT64('o','r','l','d','!','\0','\0','\0'));
-->

View File

@ -5,6 +5,7 @@ TechEmpower Web Framework Benchmarks
<!--#declaration
#include "world.h"
static void usp_init_query() { World::handlerInitSql(); }
static void usp_fork_query() { World::handlerForkSql(); }
-->
<!--#header
@ -29,7 +30,7 @@ if (World::pdrv)
randomNumber = U_SYSCALL(PQgetvalue, "%p,%d,%d", res, 0, 0);
World::handlerResult(World::rnumber[i], ntohl(*(uint32_t*)randomNumber));
World::handlerResult(i, ntohl(*(uint32_t*)randomNumber));
U_SYSCALL_VOID(PQclear, "%p", res);
}
@ -43,7 +44,7 @@ for (; i < num_queries; ++i)
World::pstmt_query->execute();
World::handlerResultSql(i);
World::handlerResult(i, World::pworld_query->randomNumber);
}
}

View File

@ -10,6 +10,7 @@ static char query[8192];
#endif
static UOrmStatement* pstmt_update;
static void usp_init_update() { World::handlerInitSql(); }
static void usp_fork_update()
{
U_TRACE(5, "::usp_fork_update()")
@ -63,7 +64,7 @@ if (World::pdrv)
u_put_unalignedp16(pquery, U_MULTICHAR_CONSTANT16(')',','));
pquery += 2;
World::handlerResult(World::rnumber[i], World::rnum);
World::handlerResult(i, World::rnum);
U_SYSCALL_VOID(PQclear, "%p", res);
}
@ -92,7 +93,7 @@ for (; i < num_queries; ++i)
pstmt_update->execute();
World::handlerResultSql(i);
World::handlerResult(i, World::pworld_query->randomNumber);
}
World::endResult();

View File

@ -10,351 +10,411 @@
#include <ulib/net/server/client_image.h>
#ifdef U_STATIC_ORM_DRIVER_PGSQL
# include <ulib/event/event_db.h>
# include <ulib/orm/driver/orm_driver_pgsql.h>
#endif
class World {
class U_EXPORT World {
public:
uint32_t id, randomNumber;
// Check for memory error
U_MEMORY_TEST
World()
{
U_TRACE_CTOR(5, World, "")
// Allocator e Deallocator
U_MEMORY_ALLOCATOR
U_MEMORY_DEALLOCATOR
// coverity[uninit_ctor]
# ifdef U_COVERITY_FALSE_POSITIVE
id = randomNumber = 0;
# endif
}
uint32_t id, randomNumber;
World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
{
U_TRACE_CTOR(5, World, "%u,%u", _id, _randomNumber)
}
World()
{
U_TRACE_CTOR(5, World, "")
World(const World& w) : id(w.id), randomNumber(w.randomNumber)
{
U_TRACE_CTOR(5, World, "%p", &w)
// coverity[uninit_ctor]
# ifdef U_COVERITY_FALSE_POSITIVE
id = randomNumber = 0;
# endif
}
U_MEMORY_TEST_COPY(w)
}
World(uint32_t _id, uint32_t _randomNumber) : id(_id), randomNumber(_randomNumber)
{
U_TRACE_CTOR(5, World, "%u,%u", _id, _randomNumber)
}
~World()
{
U_TRACE_DTOR(5, World)
}
World(const World& w) : id(w.id), randomNumber(w.randomNumber)
{
U_TRACE_CTOR(5, World, "%p", &w)
// JSON
U_MEMORY_TEST_COPY(w)
}
void toJSON(UString& json)
{
U_TRACE(5, "World::toJSON(%V)", json.rep)
~World()
{
U_TRACE_DTOR(5, World)
}
json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.toJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
}
// JSON
void fromJSON(UValue& json)
{
U_TRACE(5, "World::fromJSON(%p)", &json)
void toJSON(UString& json)
{
U_TRACE(5, "World::toJSON(%V)", json.rep)
json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
}
json.toJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.toJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
}
// ORM
void fromJSON(UValue& json)
{
U_TRACE(5, "World::fromJSON(%p)", &json)
void bindParam(UOrmStatement* stmt)
{
U_TRACE(5, "World::bindParam(%p)", stmt)
json.fromJSON(U_JSON_METHOD_HANDLER(id, unsigned int));
json.fromJSON(U_JSON_METHOD_HANDLER(randomNumber, unsigned int));
}
stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
}
// ORM
void bindResult(UOrmStatement* stmt)
{
U_TRACE(5, "World::bindResult(%p)", stmt)
void bindParam(UOrmStatement* stmt)
{
U_TRACE(5, "World::bindParam(%p)", stmt)
stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
}
stmt->bindParam(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindParam(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
}
// SERVICE
void bindResult(UOrmStatement* stmt)
{
U_TRACE(5, "World::bindResult(%p)", stmt)
bool operator<(const World& other) const { return cmp_obj(&id, &other.id); }
stmt->bindResult(U_ORM_TYPE_HANDLER(id, unsigned int));
stmt->bindResult(U_ORM_TYPE_HANDLER(randomNumber, unsigned int));
}
static int cmp_obj(const void* a, const void* b)
{
U_TRACE(5, "World::cmp_obj(%p,%p)", a, b)
// SERVICE
# ifdef U_STDCPP_ENABLE
/**
* The comparison function must follow a strict-weak-ordering
*
* 1) For all x, it is not the case that x < x (irreflexivity)
* 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
* 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
* 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
*/
bool operator<(const World& other) const { return cmp_obj(&id, &other.id); }
return (((const World*)a)->id < (((const World*)b)->id));
# else
return (*(const World**)a)->id < ((*(const World**)b)->id);
# endif
}
static int cmp_obj(const void* a, const void* b)
{
U_TRACE(5, "World::cmp_obj(%p,%p)", a, b)
static char* pwbuffer;
static char wbuffer[18000];
static uint32_t rnum, rnumber[500];
# ifdef U_STDCPP_ENABLE
/**
* The comparison function must follow a strict-weak-ordering
*
* 1) For all x, it is not the case that x < x (irreflexivity)
* 2) For all x, y, if x < y then it is not the case that y < x (asymmetry)
* 3) For all x, y, and z, if x < y and y < z then x < z (transitivity)
* 4) For all x, y, and z, if x is incomparable with y, and y is incomparable with z, then x is incomparable with z (transitivity of incomparability)
*/
static World* pworld_query;
static UOrmSession* psql_query;
static UOrmStatement* pstmt_query;
return (((const World*)a)->id < (((const World*)b)->id));
# else
return (*(const World**)a)->id < ((*(const World**)b)->id);
# endif
}
static char* ptr;
static char* pwbuffer;
static char wbuffer[18000];
static uint32_t rnum, rnumber[501];
static World* pworld_query;
static UOrmSession* psql_query;
static UOrmStatement* pstmt_query;
#ifdef U_STATIC_ORM_DRIVER_PGSQL
static PGconn* conn;
static UOrmDriverPgSql* pdrv;
static UPgSqlStatement* pstmt;
static char num2str[sizeof(unsigned int)];
static PGconn* conn;
static UOrmDriverPgSql* pdrv;
static UPgSqlStatement* pstmt;
static char num2str[sizeof(unsigned int)];
static bool initPipeline()
{
U_TRACE(5, "World::initPipeline()")
static PGresult* execPrepared()
{
U_TRACE_NO_PARAM(5, "World::execPrepared()")
if (pdrv)
{
(void) U_SYSCALL(PQsetnonblocking, "%p,%u", conn, 1);
(void) U_SYSCALL(PQenterBatchMode, "%p", conn);
U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
U_RETURN(true);
}
*(unsigned int*)num2str = htonl(rnumber[0]);
U_RETURN(false);
}
PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
static PGresult* execPrepared()
{
U_TRACE_NO_PARAM(5, "World::execPrepared()")
U_RETURN_POINTER(res, PGresult);
}
U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
static PGresult* execPrepared(uint32_t i)
{
U_TRACE(5, "World::execPrepared(%u)", i)
*(unsigned int*)num2str = htonl(rnumber[0]);
U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
*(unsigned int*)num2str = htonl(rnumber[i]);
U_RETURN_POINTER(res, PGresult);
}
PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
static PGresult* execPrepared(uint32_t i)
{
U_TRACE(5, "World::execPrepared(%u)", i)
U_RETURN_POINTER(res, PGresult);
}
U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
static void sendQueryPrepared()
{
U_TRACE_NO_PARAM(5, "World::sendQueryPrepared()")
*(unsigned int*)num2str = htonl(rnumber[i]);
U_INTERNAL_ASSERT_MAJOR(rnumber[0], 0)
PGresult* res = (PGresult*) U_SYSCALL(PQexecPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
*(unsigned int*)num2str = htonl(rnumber[0]);
U_RETURN_POINTER(res, PGresult);
}
(void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
}
static void sendQueryPrepared(uint32_t i)
{
U_TRACE(5, "World::sendQueryPrepared(%u)", i)
static void sendQueryPrepared(uint32_t i)
{
U_TRACE(5, "World::sendQueryPrepared(%u)", i)
U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
U_INTERNAL_ASSERT_MAJOR(rnumber[i], 0)
*(unsigned int*)num2str = htonl(rnumber[i]);
*(unsigned int*)num2str = htonl(rnumber[i]);
(void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
}
# ifdef DEBUG
if (U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1) == 0)
{
pdrv->printError(__PRETTY_FUNCTION__);
}
# else
(void) U_SYSCALL(PQsendQueryPrepared, "%p,%S,%u,%p,%p,%p,%u", conn, pstmt->stmtName, 1, pstmt->paramValues, pstmt->paramLengths, pstmt->paramFormats, 1);
# endif
}
#endif
static void initResult()
{
U_TRACE(5, "World::initResult()")
static void initOneResult()
{
U_TRACE_NO_PARAM(5, "World::initOneResult()")
u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(wbuffer+16, U_MULTICHAR_CONSTANT64('1','3','3','3','1','\r','\n','C'));
u_put_unalignedp64(wbuffer+24, U_MULTICHAR_CONSTANT64('o','n','t','e','n','t','-','T'));
u_put_unalignedp64(wbuffer+32, U_MULTICHAR_CONSTANT64('y','p','e',':',' ','a','p','p'));
u_put_unalignedp64(wbuffer+40, U_MULTICHAR_CONSTANT64('l','i','c','a','t','i','o','n'));
u_put_unalignedp64(wbuffer+48, U_MULTICHAR_CONSTANT64('/','j','s','o','n','\r','\n','\r'));
u_put_unalignedp16(wbuffer+56, U_MULTICHAR_CONSTANT16('\n','['));
U_INTERNAL_DUMP("wbuffer = %#.10S", wbuffer)
pwbuffer = wbuffer + U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n[");
}
if (*wbuffer == '\0')
{
u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp32(wbuffer+16, U_MULTICHAR_CONSTANT32('3','1','\r','\n'));
u_put_unalignedp64(wbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
u_put_unalignedp64(wbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
u_put_unalignedp64(wbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
u_put_unalignedp64(wbuffer+52, U_MULTICHAR_CONSTANT64('\r','\n','{','"','i','d','"',':'));
static void endResult()
{
U_TRACE_NO_PARAM(5, "World::endResult()")
pwbuffer = u_num2str32(rnumber[0], wbuffer + U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n{\"id\":"));
*(pwbuffer-1) = ']';
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
}
uint32_t len = pwbuffer-wbuffer,
body_len = len - U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n");
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer+52), U_MULTICHAR_CONSTANT64('\r','\n','{','"','i','d','"',':'))
}
pwbuffer = u_num2str32(body_len, wbuffer + U_CONSTANT_SIZE("Content-Length: "));
static void endOneResult()
{
U_TRACE_NO_PARAM(5, "World::endOneResult()")
while (*pwbuffer != '\r') *pwbuffer++ = ' ';
*ptr = '}';
UClientImage_Base::wbuffer->setConstant(wbuffer, len);
}
uint32_t len = ptr-wbuffer+1,
body_len = len - U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n");
static void initOneResult()
{
U_TRACE(5, "World::initOneResult()")
U_NUM2STR16(wbuffer+U_CONSTANT_SIZE("Content-Length: "), body_len);
u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp32(wbuffer+16, U_MULTICHAR_CONSTANT32('3','1','\r','\n'));
u_put_unalignedp64(wbuffer+20, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+28, U_MULTICHAR_CONSTANT64('T','y','p','e',':',' ','a','p'));
u_put_unalignedp64(wbuffer+36, U_MULTICHAR_CONSTANT64('p','l','i','c','a','t','i','o'));
u_put_unalignedp64(wbuffer+44, U_MULTICHAR_CONSTANT64('n','/','j','s','o','n','\r','\n'));
u_put_unalignedp32(wbuffer+52, U_MULTICHAR_CONSTANT32('\r','\n','{','\0'));
UClientImage_Base::wbuffer->setConstant(wbuffer, len);
}
pwbuffer = wbuffer + U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n{");
}
static void handlerOneResult(uint32_t random)
{
U_TRACE(5, "World::handlerOneResult(%u)", random)
static void endOneResult()
{
U_TRACE_NO_PARAM(5, "World::endOneResult()")
initOneResult();
*pwbuffer = '}';
ptr = u_num2str32(random, pwbuffer+16);
uint32_t len = pwbuffer-wbuffer+1,
body_len = len - U_CONSTANT_SIZE("Content-Length: 31\r\nContent-Type: application/json\r\n\r\n");
endOneResult();
}
(void) u_num2str32(body_len, wbuffer+U_CONSTANT_SIZE("Content-Length: "));
static void initResult()
{
U_TRACE_NO_PARAM(5, "World::initResult()")
UClientImage_Base::wbuffer->setConstant(wbuffer, len);
}
U_INTERNAL_DUMP("wbuffer = %#.10S", wbuffer)
static void handlerOneResult(uint32_t uid, uint32_t random)
{
U_TRACE(5, "World::handlerOneResult(%u,%u)", uid, random)
if (*wbuffer == '\0')
{
u_put_unalignedp64(wbuffer, U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'));
u_put_unalignedp64(wbuffer+8, U_MULTICHAR_CONSTANT64('L','e','n','g','t','h',':',' '));
u_put_unalignedp64(wbuffer+16, U_MULTICHAR_CONSTANT64('1','3','3','3','1','\r','\n','C'));
u_put_unalignedp64(wbuffer+24, U_MULTICHAR_CONSTANT64('o','n','t','e','n','t','-','T'));
u_put_unalignedp64(wbuffer+32, U_MULTICHAR_CONSTANT64('y','p','e',':',' ','a','p','p'));
u_put_unalignedp64(wbuffer+40, U_MULTICHAR_CONSTANT64('l','i','c','a','t','i','o','n'));
u_put_unalignedp64(wbuffer+48, U_MULTICHAR_CONSTANT64('/','j','s','o','n','\r','\n','\r'));
u_put_unalignedp64(wbuffer+56, U_MULTICHAR_CONSTANT64('\n','[','{','"','i','d','"',':'));
u_put_unalignedp32(pwbuffer, U_MULTICHAR_CONSTANT32('"','i','d','"'));
pwbuffer = u_num2str32(rnumber[0], wbuffer + U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n[{\"id\":"));
pwbuffer[4] = ':';
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
}
pwbuffer = u_num2str32(uid, pwbuffer+5);
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer), U_MULTICHAR_CONSTANT64('C','o','n','t','e','n','t','-'))
U_INTERNAL_ASSERT_EQUALS(u_get_unalignedp64(wbuffer+56), U_MULTICHAR_CONSTANT64('\n','[','{','"','i','d','"',':'))
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
ptr = pwbuffer;
}
pwbuffer = u_num2str32(random, pwbuffer+16);
}
static void endResult()
{
U_TRACE_NO_PARAM(5, "World::endResult()")
static void handlerResult(uint32_t uid, uint32_t random)
{
U_TRACE(5, "World::handlerResult(%u,%u)", uid, random)
*(ptr-1) = ']';
u_put_unalignedp32(pwbuffer, U_MULTICHAR_CONSTANT32('{','"','i','d'));
u_put_unalignedp16(pwbuffer+4, U_MULTICHAR_CONSTANT16('"',':'));
uint32_t len = ptr-wbuffer,
body_len = len - U_CONSTANT_SIZE("Content-Length: 13331\r\nContent-Type: application/json\r\n\r\n");
pwbuffer = u_num2str32(uid, pwbuffer+6);
ptr = u_num2str32(body_len, wbuffer + U_CONSTANT_SIZE("Content-Length: "));
u_put_unalignedp64(pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
while (*ptr != '\r') *ptr++ = ' ';
pwbuffer = u_num2str32(random, pwbuffer+16);
UClientImage_Base::wbuffer->setConstant(wbuffer, len);
}
u_put_unalignedp16(pwbuffer, U_MULTICHAR_CONSTANT16('}',','));
pwbuffer += 2;
}
static void addResult(uint32_t i)
{
U_TRACE(5, "World::addResult(%u)", i)
static void handlerResult(uint32_t i)
{
U_TRACE(5, "World::handlerResult(%u)", i)
U_INTERNAL_ASSERT_MAJOR(i, 0)
U_INTERNAL_ASSERT_POINTER(pworld_query)
u_put_unalignedp32(ptr, U_MULTICHAR_CONSTANT32('{','"','i','d'));
u_put_unalignedp16(ptr+4, U_MULTICHAR_CONSTANT16('"',':'));
U_INTERNAL_DUMP("pworld_query->randomNumber = %u", pworld_query->randomNumber)
}
ptr = u_num2str32(rnumber[i], ptr+6);
static void handlerResultSql(uint32_t i)
{
U_TRACE(5, "World::handlerResultSql(%u)", i)
u_put_unalignedp64(ptr, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(ptr+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
}
U_INTERNAL_ASSERT_POINTER(pworld_query)
static void addRandom(uint32_t random)
{
U_TRACE(5, "World::addRandom(%u)", random)
handlerResult(rnumber[i], pworld_query->randomNumber);
}
ptr = u_num2str32(random, ptr+16);
static void doUpdateNoSql(vPFu handlerUpdateNoSql)
{
U_TRACE(5, "World::doUpdateNoSql(%p)", handlerUpdateNoSql)
u_put_unalignedp16(ptr, U_MULTICHAR_CONSTANT16('}',','));
ptr += 2;
}
initResult();
static void handlerResult(uint32_t i, uint32_t random)
{
U_TRACE(5, "World::handlerResult(%u,%u)", i, random)
for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
{
handlerUpdateNoSql(i);
if (i) addResult(i);
handlerResult(rnumber[i], rnum);
}
addRandom(random);
}
endResult();
}
static void doUpdateNoSql(vPFu handlerUpdateNoSql)
{
U_TRACE(5, "World::doUpdateNoSql(%p)", handlerUpdateNoSql)
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "World::handlerFork()")
initResult();
if (rnumber[0] == 0) for (uint32_t i = 0; i < 500; ++i) rnumber[i] = u_get_num_random_range1(10000);
}
for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
{
handlerUpdateNoSql(i);
static void handlerForkSql()
{
U_TRACE_NO_PARAM(5, "World::handlerForkSql()")
handlerResult(i, rnum);
}
if (psql_query == U_NULLPTR)
{
U_NEW(UOrmSession, psql_query, UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
endResult();
}
if (psql_query->isReady() == false)
{
U_WARNING("World::handlerForkSql(): we cound't connect to db");
static void handlerInitSql()
{
U_TRACE_NO_PARAM(5, "World::handlerInitSql()")
U_DELETE(psql_query)
# ifdef U_STATIC_ORM_DRIVER_PGSQL
U_INTERNAL_DUMP("UServer_Base::handler_db1 = %p", UServer_Base::handler_db1)
psql_query = U_NULLPTR;
if (UServer_Base::handler_db1 == U_NULLPTR)
{
U_NEW_WITHOUT_CHECK_MEMORY(UEventDB, UServer_Base::handler_db1, UEventDB);
}
# endif
}
return;
}
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "World::handlerFork()")
U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
if (rnumber[0] == 0) for (uint32_t i = 0; i <= 500; ++i) rnumber[i] = u_get_num_random_range1(10000);
}
U_NEW(World, pworld_query, World);
static void handlerForkSql()
{
U_TRACE_NO_PARAM(5, "World::handlerForkSql()")
pstmt_query->use( pworld_query->id);
pstmt_query->into(pworld_query->randomNumber);
if (psql_query == U_NULLPTR)
{
U_NEW(UOrmSession, psql_query, UOrmSession(U_CONSTANT_TO_PARAM("hello_world")));
# ifdef U_STATIC_ORM_DRIVER_PGSQL
if (UOrmDriver::isPGSQL())
{
conn = (PGconn*)(pdrv = (UOrmDriverPgSql*)psql_query->getDriver())->UOrmDriver::connection;
pstmt = (UPgSqlStatement*)pstmt_query->getStatement();
if (psql_query->isReady() == false)
{
U_WARNING("World::handlerForkSql(): we cound't connect to db");
(void) pstmt->setBindParam(pdrv);
U_DELETE(psql_query)
pstmt->paramValues[0] = num2str;
pstmt->paramLengths[0] = sizeof(unsigned int);
}
# endif
psql_query = U_NULLPTR;
handlerFork();
}
}
return;
}
const char* dump(bool breset) const;
U_NEW(UOrmStatement, pstmt_query, UOrmStatement(*psql_query, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?")));
U_NEW(World, pworld_query, World);
pstmt_query->use( pworld_query->id);
pstmt_query->into(pworld_query->randomNumber);
# ifdef U_STATIC_ORM_DRIVER_PGSQL
if (UOrmDriver::isPGSQL())
{
conn = (PGconn*)(pdrv = (UOrmDriverPgSql*)psql_query->getDriver())->UOrmDriver::connection;
pstmt = (UPgSqlStatement*)pstmt_query->getStatement();
(void) pstmt->setBindParam(pdrv);
pstmt->paramValues[0] = num2str;
pstmt->paramLengths[0] = sizeof(unsigned int);
((UEventDB*)UServer_Base::handler_db1)->setConnection(conn);
}
# endif
handlerFork();
}
}
#ifdef DEBUG
static void handlerEndSql()
{
U_TRACE_NO_PARAM(5, "World::handlerEndSql()")
if (pstmt_query)
{
U_DELETE( pstmt_query)
U_DELETE(pworld_query)
U_DELETE( psql_query)
pstmt_query = U_NULLPTR;
}
}
const char* dump(bool breset) const;
#endif
private:
U_DISALLOW_ASSIGN(World)
U_DISALLOW_ASSIGN(World)
};
#endif

View File

@ -9,288 +9,322 @@
#include <ulib/net/client/elasticsearch.h>
#ifdef USE_MONGODB
# include <ulib/net/client/mongodb.h>
# include <ulib/net/client/mongodb.h>
#endif
class WorldNoSql {
class U_EXPORT WorldNoSql {
public:
static UString* str_rnumber;
static UString* str_rnumber;
static void handlerOneResult(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerOneResult(%u)", uid)
static void doOneQuery(vPFu handlerQuery)
{
U_TRACE(5, "WorldNoSql::doOneQuery(%p)", handlerQuery)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(World::pwbuffer)
handlerQuery(World::rnumber[0]);
u_put_unalignedp32(World::pwbuffer, U_MULTICHAR_CONSTANT32('"','i','d','"'));
uint32_t sz = str_rnumber->size();
World::pwbuffer[4] = ':';
World::initOneResult();
World::pwbuffer = u_num2str32(uid, World::pwbuffer+5);
(void) memcpy(World::pwbuffer+16, str_rnumber->data(), sz);
u_put_unalignedp64(World::pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(World::pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
World::pwbuffer += 16;
World::ptr = World::pwbuffer+16+sz;
uint32_t sz = str_rnumber->size();
World::endOneResult();
(void) memcpy(World::pwbuffer, str_rnumber->data(), sz);
World::pwbuffer += sz;
str_rnumber->clear();
}
str_rnumber->clear();
}
static void handlerResult(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerResult(%u)", i)
static void handlerResult(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerResult(%u)", uid)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(World::pwbuffer)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(World::pwbuffer)
if (i) World::addResult(i);
u_put_unalignedp32(World::pwbuffer, U_MULTICHAR_CONSTANT32('{','"','i','d'));
u_put_unalignedp16(World::pwbuffer+4, U_MULTICHAR_CONSTANT16('"',':'));
uint32_t sz = str_rnumber->size();
World::pwbuffer = u_num2str32(uid, World::pwbuffer+6);
(void) memcpy(World::ptr+16, str_rnumber->data(), sz);
World::ptr += 16+ sz;
u_put_unalignedp64(World::pwbuffer, U_MULTICHAR_CONSTANT64(',','"','r','a','n','d','o','m'));
u_put_unalignedp64(World::pwbuffer+8, U_MULTICHAR_CONSTANT64('N','u','m','b','e','r','"',':'));
World::pwbuffer += 16;
u_put_unalignedp16(World::ptr, U_MULTICHAR_CONSTANT16('}',','));
World::ptr += 2;
uint32_t sz = str_rnumber->size();
str_rnumber->clear();
}
(void) memcpy(World::pwbuffer, str_rnumber->data(), sz);
World::pwbuffer += sz;
static void doQuery(vPFu handlerQuery)
{
U_TRACE(5, "WorldNoSql::doQuery(%p)", handlerQuery)
str_rnumber->clear();
World::initResult();
u_put_unalignedp16(World::pwbuffer, U_MULTICHAR_CONSTANT16('}',','));
World::pwbuffer += 2;
}
for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
{
handlerQuery(World::rnumber[i]);
static void doOneQuery(vPFu handlerQuery)
{
U_TRACE(5, "WorldNoSql::doOneQuery(%p)", handlerQuery)
handlerResult(i);
}
World::initOneResult();
World::endResult();
}
handlerQuery(World::rnumber[0]);
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerFork()")
handlerOneResult(World::rnumber[0]);
if (str_rnumber == U_NULLPTR) U_NEW_STRING(str_rnumber, UString);
World::endOneResult();
}
World::handlerFork();
static void doQuery(vPFu handlerQuery)
{
U_TRACE(5, "WorldNoSql::doQuery(%p)", handlerQuery)
World::initResult();
for (uint32_t i = 0, n = UHTTP::getFormFirstNumericValue(1, 500); i < n; ++i)
{
handlerQuery(World::rnumber[i]);
handlerResult(World::rnumber[i]);
}
World::endResult();
}
static void handlerFork()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerFork()")
if (str_rnumber == U_NULLPTR) U_NEW_STRING(str_rnumber, UString);
World::handlerFork();
U_INTERNAL_ASSERT_POINTER(str_rnumber)
}
U_INTERNAL_ASSERT_POINTER(str_rnumber)
}
#ifdef USE_MONGODB
static bson_t* query;
static UMongoDBClient* mc;
static bson_t* query;
static UMongoDBClient* mc;
#endif
static void handlerQueryMongoDB(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryMongoDB(%u)", uid)
static void handlerQueryMongoDB(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryMongoDB(%u)", uid)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
# ifdef USE_MONGODB
(void) mc->findOne(uid, query);
(void) U_JFIND(mc->vitem[0], "randomNumber", *str_rnumber);
# ifdef USE_MONGODB
(void) mc->findOne(uid, query);
(void) U_JFIND(mc->vitem[0], "randomNumber", *str_rnumber);
uint32_t pos = str_rnumber->find_first_of('.');
uint32_t pos = str_rnumber->find_first_of('.');
if (pos != U_NOT_FOUND) str_rnumber->size_adjust_constant(pos);
# endif
}
if (pos != U_NOT_FOUND) str_rnumber->size_adjust_constant(pos);
# endif
}
static void handlerUpdateMongoDB(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateMongoDB(%u)", i)
static void handlerUpdateMongoDB(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateMongoDB(%u)", i)
# ifdef USE_MONGODB
(void) mc->findOne(World::rnumber[i], query);
(void) mc->update( World::rnumber[i], "randomNumber", World::rnum = u_get_num_random_range1(10000));
# endif
}
# ifdef USE_MONGODB
(void) mc->findOne(World::rnumber[i], query);
(void) mc->update( World::rnumber[i], "randomNumber", World::rnum = u_get_num_random_range1(10000));
# endif
}
static void handlerForkMongoDB()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkMongoDB()")
static void handlerForkMongoDB()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkMongoDB()")
# ifdef USE_MONGODB
if (mc == U_NULLPTR)
{
U_NEW(UMongoDBClient, mc, UMongoDBClient);
# ifdef USE_MONGODB
if (mc == U_NULLPTR)
{
U_NEW(UMongoDBClient, mc, UMongoDBClient);
if (mc->connect(U_NULLPTR, 0) == false)
{
U_WARNING("WorldNoSql::handlerForkMongoDB(): connection failed");
if (mc->connect(U_NULLPTR, 0) == false)
{
U_WARNING("WorldNoSql::handlerForkMongoDB(): connection failed");
U_DELETE(mc)
U_DELETE(mc)
mc = U_NULLPTR;
mc = U_NULLPTR;
return;
}
return;
}
if (mc->selectCollection("hello_world", "world") == false)
{
U_WARNING("WorldNoSql::handlerForkMongoDB(): selectCollection() failed");
if (mc->selectCollection("hello_world", "world") == false)
{
U_WARNING("WorldNoSql::handlerForkMongoDB(): selectCollection() failed");
U_DELETE(mc)
U_DELETE(mc)
mc = U_NULLPTR;
mc = U_NULLPTR;
return;
}
return;
}
query = (bson_t*) U_SYSCALL_NO_PARAM(bson_new);
query = (bson_t*) U_SYSCALL_NO_PARAM(bson_new);
handlerFork();
}
# endif
}
handlerFork();
}
# endif
}
static char rc_buffer[128];
static UREDISClient_Base* rc;
static char rc_buffer[128];
static UREDISClient_Base* rc;
static void handlerQueryREDIS(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryREDIS(%u)", uid)
static void handlerQueryREDIS(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryREDIS(%u)", uid)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
char* ptr = rc_buffer+U_CONSTANT_SIZE("world:");
char* ptr = rc_buffer+U_CONSTANT_SIZE("world:");
(void) rc->get(ptr, U_CONSTANT_SIZE("world:")+u_num2str32(uid, ptr)-ptr);
(void) rc->get(ptr, U_CONSTANT_SIZE("world:")+u_num2str32(uid, ptr)-ptr);
*str_rnumber = rc->vitem[0];
}
*str_rnumber = rc->vitem[0];
}
static void handlerUpdateREDIS(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateREDIS(%u)", i)
static void handlerUpdateREDIS(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateREDIS(%u)", i)
char* start = rc_buffer+U_CONSTANT_SIZE("world:");
char* ptr = u_num2str32(World::rnumber[i], start);
char* start = rc_buffer+U_CONSTANT_SIZE("world:");
char* ptr = u_num2str32(World::rnumber[i], start);
(void) rc->get(start, ptr-start);
(void) rc->get(start, ptr-start);
*ptr = ' ';
ptr = u_num2str32(World::rnum = u_get_num_random_range1(10000), ptr+1);
*ptr = ' ';
ptr = u_num2str32(World::rnum = u_get_num_random_range1(10000), ptr+1);
(void) rc->mset(start, ptr-start);
}
(void) rc->mset(start, ptr-start);
}
static void handlerForkREDIS()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkREDIS()")
static void handlerForkREDIS()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkREDIS()")
if (rc == U_NULLPTR)
{
U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
if (rc == U_NULLPTR)
{
U_NEW(UREDISClient<UTCPSocket>, rc, UREDISClient<UTCPSocket>);
if (rc->connect() == false)
{
U_WARNING("WorldNoSql::handlerForkREDIS(): %V", rc->UClient_Base::getResponse().rep);
if (rc->connect() == false)
{
U_WARNING("WorldNoSql::handlerForkREDIS(): %V", rc->UClient_Base::getResponse().rep);
U_DELETE(rc)
U_DELETE(rc)
rc = U_NULLPTR;
rc = U_NULLPTR;
return;
}
return;
}
U_MEMCPY(rc_buffer, "world:", U_CONSTANT_SIZE("world:"));
U_MEMCPY(rc_buffer, "world:", U_CONSTANT_SIZE("world:"));
handlerFork();
}
}
handlerFork();
}
}
static char* pbuffer1;
static char* pbuffer2;
static char es_buffer1[128];
static char es_buffer2[128];
static UElasticSearchClient* es;
static char* pbuffer1;
static char* pbuffer2;
static char es_buffer1[128];
static char es_buffer2[128];
static UElasticSearchClient* es;
# define U_QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
# define U_QLEN U_CONSTANT_SIZE("{\"query\":{\"match\":{\"_id\":\"")
static void handlerQueryElasticSearch(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryElasticSearch(%u)", uid)
static void handlerQueryElasticSearch(uint32_t uid)
{
U_TRACE(5, "WorldNoSql::handlerQueryElasticSearch(%u)", uid)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
U_INTERNAL_ASSERT_POINTER(str_rnumber)
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), es_buffer1, U_QLEN+
u__snprintf(es_buffer1+ U_QLEN,
sizeof(es_buffer1)-U_QLEN, U_CONSTANT_TO_PARAM("%u\"}}}"), uid));
(void) es->sendPOST(U_CONSTANT_TO_PARAM("/tfb/world/_search"), es_buffer1, U_QLEN+
u__snprintf(es_buffer1+ U_QLEN,
sizeof(es_buffer1)-U_QLEN, U_CONSTANT_TO_PARAM("%u\"}}}"), uid));
(void) U_JFIND(es->getContent(), "randomNumber", *str_rnumber);
}
(void) U_JFIND(es->getContent(), "randomNumber", *str_rnumber);
}
static void handlerUpdateElasticSearch(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateElasticSearch(%u)", i)
static void handlerUpdateElasticSearch(uint32_t i)
{
U_TRACE(5, "WorldNoSql::handlerUpdateElasticSearch(%u)", i)
uint32_t len1 = u__snprintf(pbuffer1, 100, U_CONSTANT_TO_PARAM("%u/_update"), World::rnumber[i]),
len2 = u__snprintf(pbuffer2, 100, U_CONSTANT_TO_PARAM("%u\"}}"), World::rnum = u_get_num_random_range1(10000));
uint32_t len1 = u__snprintf(pbuffer1, 100, U_CONSTANT_TO_PARAM("%u/_update"), World::rnumber[i]),
len2 = u__snprintf(pbuffer2, 100, U_CONSTANT_TO_PARAM("%u\"}}"), World::rnum = u_get_num_random_range1(10000));
(void) es->sendPOST(es_buffer1, len1+U_CONSTANT_SIZE("/tfb/world/"), es_buffer2, len2+U_CONSTANT_SIZE("{\"doc\":{\"_id\":\""));
}
(void) es->sendPOST(es_buffer1, len1+U_CONSTANT_SIZE("/tfb/world/"), es_buffer2, len2+U_CONSTANT_SIZE("{\"doc\":{\"_id\":\""));
}
static void handlerForkElasticSearch()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkElasticSearch()")
static void handlerForkElasticSearch()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerForkElasticSearch()")
if (es == U_NULLPTR)
{
U_NEW(UElasticSearchClient, es, UElasticSearchClient);
if (es == U_NULLPTR)
{
U_NEW(UElasticSearchClient, es, UElasticSearchClient);
if (es->connect() == false)
{
U_WARNING("WorldNoSql::handlerForkElasticSearch(): connection disabled or failed");
if (es->connect() == false)
{
U_WARNING("WorldNoSql::handlerForkElasticSearch(): connection disabled or failed");
U_DELETE(es)
U_DELETE(es)
es = U_NULLPTR;
es = U_NULLPTR;
return;
}
return;
}
U_MEMCPY(es_buffer1, "{\"query\":{\"match\":{\"_id\":\"", U_QLEN);
U_MEMCPY(es_buffer1, "{\"query\":{\"match\":{\"_id\":\"", U_QLEN);
handlerFork();
}
}
handlerFork();
}
}
#ifdef DEBUG
static void handlerEnd()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerEnd()")
if (str_rnumber)
{
U_DELETE(str_rnumber)
str_rnumber = U_NULLPTR;
}
}
static void handlerEndMongoDB()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerEndMongoDB()")
# ifdef USE_MONGODB
if (query)
{
U_DELETE(mc)
U_SYSCALL_VOID(bson_destroy, "%p", query);
query = U_NULLPTR;
handlerEnd();
}
# endif
}
static void handlerEndREDIS()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerEndREDIS()")
if (rc)
{
U_DELETE(rc)
rc = U_NULLPTR;
handlerEnd();
}
}
static void handlerEndElasticSearch()
{
U_TRACE_NO_PARAM(5, "WorldNoSql::handlerEndElasticSearch()")
if (es)
{
U_DELETE(es)
es = U_NULLPTR;
handlerEnd();
}
}
#endif
private:
U_DISALLOW_ASSIGN(WorldNoSql)
U_DISALLOW_ASSIGN(WorldNoSql)
};
#endif

View File

@ -2,12 +2,12 @@ userver {
PORT 8080
PREFORK_CHILD 4
TCP_LINGER_SET 0
TCP_LINGER_SET -2
LISTEN_BACKLOG 256
DOCUMENT_ROOT benchmark/FrameworkBenchmarks/ULib/www
PID_FILE ../userver_tcp.pid
ORM_DRIVER "sqlite"
ORM_DRIVER "sqlite mysql pgsql"
# LOG_FILE ../../benchmark.log
# LOG_FILE_SZ 50M