From d6807be5dee2162260c0dbda7545088b77dbf531 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Fri, 11 Jul 2014 15:52:33 +0200 Subject: [PATCH 1/4] New benchmark: ULib framework --- ULib/README.md | 107 ++++++++++++++++++++++++ ULib/__init__.py | 0 ULib/benchmark_config | 28 +++++++ ULib/install.sh | 50 +++++++++++ ULib/setup.py | 70 ++++++++++++++++ ULib/source_code | 8 ++ ULib/src/db.usp | 120 +++++++++++++++++++++++++++ ULib/src/fortune.h | 126 ++++++++++++++++++++++++++++ ULib/src/fortunes.usp | 152 ++++++++++++++++++++++++++++++++++ ULib/src/json.usp | 81 ++++++++++++++++++ ULib/src/plaintext.usp | 51 ++++++++++++ ULib/src/queries.usp | 161 ++++++++++++++++++++++++++++++++++++ ULib/src/updates.usp | 184 +++++++++++++++++++++++++++++++++++++++++ ULib/src/world.h | 109 ++++++++++++++++++++++++ 14 files changed, 1247 insertions(+) create mode 100644 ULib/README.md create mode 100644 ULib/__init__.py create mode 100644 ULib/benchmark_config create mode 100755 ULib/install.sh create mode 100755 ULib/setup.py create mode 100644 ULib/source_code create mode 100644 ULib/src/db.usp create mode 100644 ULib/src/fortune.h create mode 100644 ULib/src/fortunes.usp create mode 100644 ULib/src/json.usp create mode 100644 ULib/src/plaintext.usp create mode 100644 ULib/src/queries.usp create mode 100644 ULib/src/updates.usp create mode 100644 ULib/src/world.h diff --git a/ULib/README.md b/ULib/README.md new file mode 100644 index 00000000000..5827ffe91be --- /dev/null +++ b/ULib/README.md @@ -0,0 +1,107 @@ +#ULib Benchmarking Test + +This is the ULib portion of a [benchmarking test suite](https://github.com/TechEmpower/FrameworkBenchmarks) comparing a variety of web development platforms. + +### JSON Encoding Test + +* [JSON test source](src/json.usp) + +### Data-Store/Database Mapping Test + +* [Database test source](src/db.usp) + +### Variable Query Test + +* [Variable Query test source](src/queries.usp) + +### Fortune Query Test + +* [Fortune Query test source](src/fortunes.usp) + +### Variable Query (update) Test + +* [Variable Query (update) test source](src/updates.usp) + +### Plaintext Test + +* [Plaintext test source](src/plaintext.usp) + +## Infrastructure Software Versions +The tests were run with: + +* [ULib Version 1.4.1](https://github.com/stefanocasazza/ULib/archive/v1.4.1.tar.gz) + +Output +====== + +[/json](http://www.techempower.com/benchmarks/#section=json) +----- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:11:10 GMT +Server: ULib +Content-Length: 27 +Content-Type: application/json; charset=UTF-8 + +{"message":"Hello, World!"} +``` + +[/db](http://www.techempower.com/benchmarks/#section=db) +--- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:14:51 GMT +Server: ULib +Content-Length: 31 +Content-Type: application/json; charset=UTF-8 + +{"id":6227,"randomNumber":8489} +``` + +[/queries?queries=10](http://www.techempower.com/benchmarks/#section=query) +------------------- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:14:51 GMT +Server: ULib +Content-Length: 320 +Content-Type: application/json; charset=UTF-8 + +[{"id":6851,"randomNumber":7598},{"id":3968,"randomNumber":7325},{"id":8159,"randomNumber":348},{"id":9560,"randomNumber":7333},{"id":9938,"randomNumber":9080},{"id":1598,"randomNumber":1623},{"id":3280,"randomNumber":8707},{"id":4521,"randomNumber":6063},{"id":8173,"randomNumber":3690},{"id":3648,"randomNumber":8803}] +``` + +[/fortunes](http://www.techempower.com/benchmarks/#section=fortune) +--------- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:14:51 GMT +Server: ULib +Content-Type: text/html; charset=UTF-8 +Content-Length: 1111 + +Fortunes
idmessage
11<script>alert("This should not be displayed in a browser alert box.");</script>
4A bad random number generator: 1, 1, 1, 1, 1, 4.33e+67, 1, 1, 1
5A computer program does what you tell it to do, not what you want it to do.
2A computer scientist is someone who fixes things that aren't broken.
8A list is only as strong as its weakest link. ¿ Donald Knuth
3After enough decimal places, nobody gives a damn.
7Any program that runs right is obsolete.
10Computers make very fast, very accurate mistakes.
6Emacs is a nice operating system, but I prefer UNIX. ¿ Tom Christaensen
9Feature: A bug with seniority.
1fortune: No such file or directory
12¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?¿?
+``` + +[/updates?queries=10](http://www.techempower.com/benchmarks/#section=update) +------------------- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:14:51 GMT +Server: ULib +Content-Length: 319 +Content-Type: application/json; charset=UTF-8 + +[{"id":7171,"randomNumber":351},{"id":6019,"randomNumber":9725},{"id":8118,"randomNumber":4023},{"id":7965,"randomNumber":1388},{"id":7797,"randomNumber":2249},{"id":112,"randomNumber":1108},{"id":6127,"randomNumber":4323},{"id":2597,"randomNumber":7509},{"id":2978,"randomNumber":7883},{"id":1111,"randomNumber":2228}] +``` + +[/plaintext](http://www.techempower.com/benchmarks/#section=plaintext) +---------- +``` +HTTP/1.1 200 OK +Date: Thu, 03 Jul 2014 10:14:51 GMT +Server: ULib +Content-Type: text/plain; charset=UTF-8 +Content-Length: 13 + +Hello, World! +``` diff --git a/ULib/__init__.py b/ULib/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/ULib/benchmark_config b/ULib/benchmark_config new file mode 100644 index 00000000000..8449636f6e4 --- /dev/null +++ b/ULib/benchmark_config @@ -0,0 +1,28 @@ +{ + "framework": "ULib", + "tests": [{ + "default": { + "setup_file": "setup", + "json_url": "/json", + "db_url": "/db", + "query_url": "/queries?queries=", + "fortune_url": "/fortunes", + "update_url": "/updates?queries=", + "plaintext_url": "/plaintext", + "port": 8080, + "approach": "Realistic", + "classification": "Fullstack", + "database": "MySQL", + "framework": "ULib", + "language": "C++", + "orm": "Micro", + "platform": "ULib", + "webserver": "None", + "os": "Linux", + "database_os": "Linux", + "display_name": "ULib", + "notes": "", + "versus": "" + } + }] +} diff --git a/ULib/install.sh b/ULib/install.sh new file mode 100755 index 00000000000..2bcb21e0264 --- /dev/null +++ b/ULib/install.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +DIR=$HOME/FrameworkBenchmarks +PREFIX=$DIR/installs/ulib +DOCUMENT_ROOT=$DIR/ULib/www + +RET1=$(fw_exists $PREFIX/bin/userver_tcp) +RET2=$(fw_exists $DOCUMENT_ROOT/db.so) + +if [ "$RET1" == 0 ] && [ "$RET2" == 0 ]; then + return 0; +fi + +VERSION=1.4.1 +# 1. Download ULib +fw_get https://github.com/stefanocasazza/ULib/archive/v$VERSION.tar.gz +# 2. Compile application (userver_tcp) +fw_untar v$VERSION.tar.gz +cd ULib-$VERSION +# ====================================================================================================== +# TO AVOID configure: error: newly created file is older than distributed files! Check your system clock +# ====================================================================================================== +find . -exec touch {} \; +# ====================================================================================================== +if [ ! -d $PREFIX ]; then + mkdir -p $PREFIX +fi +DATE=`date '+%Y%m%d'` # 20140117 +BUILD_OUTPUT=$PREFIX/ULIB_BUILD_OUTPUT-$DATE.txt +LIBS="-lssl -lcrypto -lz" ./configure --prefix=$PREFIX --disable-static --without-libz --without-libuuid --without-magic --without-ssl --without-pcre --without-expat --with-mysql --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 +make -j1 install >>$BUILD_OUTPUT 2>&1 +cd src/ulib/net/server/plugin/usp +make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$BUILD_OUTPUT 2>&1 +if [ -e .libs/db.so ]; then + mkdir -p $DOCUMENT_ROOT + cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $DOCUMENT_ROOT +else + return 1; +fi +if [ ! -f $DIR/ULib/benchmark.cfg ]; then + cat <$DIR/ULib/benchmark.cfg +userver { + PORT 8080 + PREFORK_CHILD 8 + LISTEN_BACKLOG 16384 + MAX_KEEP_ALIVE 16384 + DOCUMENT_ROOT ~/FrameworkBenchmarks/ULib/www + PID_FILE ~/FrameworkBenchmarks/ULib/userver_tcp.pid +} +EOF diff --git a/ULib/setup.py b/ULib/setup.py new file mode 100755 index 00000000000..0e03d5dc146 --- /dev/null +++ b/ULib/setup.py @@ -0,0 +1,70 @@ +import subprocess +import sys +import os +import time +import setup_util + +from os.path import expanduser + +home = expanduser("~") + +############## +# start(args) +############## +def start(args, logfile, errfile): + + script = """ + DIR=$HOME/FrameworkBenchmarks + PREFIX=$DIR/installs/ulib + DOCUMENT_ROOT=$DIR/ULib/www + if [ -x "$PREFIX/bin/userver_tcp" ] && [ -d "$DOCUMENT_ROOT" ] && [ -e "$DOCUMENT_ROOT/db.so" ] && [ -f $DIR/ULib/benchmark.cfg ]; then + return 0; + fi + return 1; + """ + + p = subprocess.Popen(['sh'], stdin=subprocess.PIPE) + p.communicate(script) + if p.returncode != 0: + print("\nstart: ULib install script failed\n") + + # 3. Start ULib Server (userver_tcp) + try: + fconf = home + "/FrameworkBenchmarks/ULib/benchmark.cfg" + if not os.path.exists(fconf): + print("\nstart: ULib configuration file " + fconf + " not exist\n") + + threads = str(args.max_threads) + setup_util.replace_text(fconf, "PREFORK_CHILD *", "PREFORK_CHILD " + threads) + + fprg = home + "/FrameworkBenchmarks/installs/ulib/bin/userver_tcp" + if not os.path.exists(fprg): + print("\nstart: ULib server program " + fprg + " not exist\n") + + os.putenv("ORM_DRIVER","mysql") + os.putenv("ORM_OPTION","host=" + args.database_host + " user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world") + os.putenv("UMEMPOOL", "1583,1507,-19,45,16458,523,-27,-14,27") + + print("\nstart: trying to start ULib server " + fprg + " -c " + fconf + "\n") + + subprocess.check_call(fprg + " -c " + fconf + " >" + home + "/FrameworkBenchmarks/installs/ulib/ULIB_SERVER_OUTPUT.txt 2>&1", shell=True, stderr=errfile, stdout=logfile) + return 0 + except subprocess.CalledProcessError: + return 1 + +############## +# stop() +############## +def stop(logfile, errfile): + try: + subprocess.check_call("kill -TERM $( cat " + home + "/FrameworkBenchmarks/ULib/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile) + time.sleep(2); + p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) + out, err = p.communicate() + for line in out.splitlines(): + if 'userver_tcp' in line: + pid = int(line.split(None, 2)[1]) + os.kill(pid, 9) + return 0 + except subprocess.CalledProcessError: + return 1 diff --git a/ULib/source_code b/ULib/source_code new file mode 100644 index 00000000000..6a204e85618 --- /dev/null +++ b/ULib/source_code @@ -0,0 +1,8 @@ +./src/db.usp +./src/world.h +./src/json.usp +./src/fortune.h +./src/queries.usp +./src/updates.usp +./src/fortunes.usp +./src/plaintext.usp diff --git a/ULib/src/db.usp b/ULib/src/db.usp new file mode 100644 index 00000000000..a64565570dd --- /dev/null +++ b/ULib/src/db.usp @@ -0,0 +1,120 @@ + + + + diff --git a/ULib/src/fortune.h b/ULib/src/fortune.h new file mode 100644 index 00000000000..19dd480b1e0 --- /dev/null +++ b/ULib/src/fortune.h @@ -0,0 +1,126 @@ +// fortune.h + +#ifndef FORTUNE_H +#define FORTUNE_H 1 + +#include +#include + +class Fortune { +public: + // Check for memory error + U_MEMORY_TEST + + // Allocator e Deallocator + U_MEMORY_ALLOCATOR + U_MEMORY_DEALLOCATOR + + UString message; + int id; + + // CONSTRUCTOR + + Fortune() + { + U_TRACE_REGISTER_OBJECT(5, Fortune, "") + } + + Fortune(int _id, const UString& _message) : message(_message), id(_id) + { + U_TRACE_REGISTER_OBJECT(5, Fortune, "%d,%.*S", _id, U_STRING_TO_TRACE(_message)) + } + + Fortune(const Fortune& f) + { + U_TRACE_REGISTER_OBJECT(5, Fortune, "%p", &f) + + U_MEMORY_TEST_COPY(f) + + message = f.message; + id = f.id; + } + + ~Fortune() + { + U_TRACE_UNREGISTER_OBJECT(5, Fortune) + } + + // SERVICE + + bool operator<(const Fortune& other) const { return cmp_obj(&message, &other.message); } + + static int cmp_obj(const void* a, const void* b) + { + U_TRACE(5, "Fortune::cmp_obj(%p,%p)", a, b) + + return (*(const Fortune**)a)->message.compare((*(const Fortune**)b)->message); + } + +#ifdef DEBUG + const char* dump(bool breset) const + { + *UObjectIO::os << "id " << id << '\n' + << "message (UString " << (void*)&message << ')'; + + if (breset) + { + UObjectIO::output(); + + return UObjectIO::buffer_output; + } + + return 0; + } +#endif + +private: + Fortune& operator=(const Fortune&) { return *this; } +}; + +// ORM TEMPLATE SPECIALIZATIONS + +template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { +public: + explicit UOrmTypeHandler(Fortune& val) : UOrmTypeHandler_Base(&val) {} + + void bindParam(UOrmStatement* stmt) const + { + U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString)); + stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, id, int)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString)); + stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, id, int)); + } +}; + +// JSON TEMPLATE SPECIALIZATIONS + +template <> class U_EXPORT UJsonTypeHandler : public UJsonTypeHandler_Base { +public: + explicit UJsonTypeHandler(Fortune& val) : UJsonTypeHandler_Base(&val) {} + + void toJSON(UValue& json) + { + U_TRACE(0, "UJsonTypeHandler::toJSON(%p)", &json) + + json.toJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); + json.toJSON(U_JSON_TYPE_HANDLER(Fortune, id, int)); + } + + void fromJSON(UValue& json) + { + U_TRACE(0, "UJsonTypeHandler::fromJSON(%p)", &json) + + json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); + json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, id, int)); + } +}; + +#endif diff --git a/ULib/src/fortunes.usp b/ULib/src/fortunes.usp new file mode 100644 index 00000000000..811a5aad084 --- /dev/null +++ b/ULib/src/fortunes.usp @@ -0,0 +1,152 @@ + + +Fortunes
idmessage
diff --git a/ULib/src/json.usp b/ULib/src/json.usp new file mode 100644 index 00000000000..a7acca22b65 --- /dev/null +++ b/ULib/src/json.usp @@ -0,0 +1,81 @@ + + + + diff --git a/ULib/src/plaintext.usp b/ULib/src/plaintext.usp new file mode 100644 index 00000000000..abb0d69fe69 --- /dev/null +++ b/ULib/src/plaintext.usp @@ -0,0 +1,51 @@ + +Hello, World! diff --git a/ULib/src/queries.usp b/ULib/src/queries.usp new file mode 100644 index 00000000000..3260cc537e8 --- /dev/null +++ b/ULib/src/queries.usp @@ -0,0 +1,161 @@ + + + + + diff --git a/ULib/src/updates.usp b/ULib/src/updates.usp new file mode 100644 index 00000000000..e86842c1727 --- /dev/null +++ b/ULib/src/updates.usp @@ -0,0 +1,184 @@ + + + + + diff --git a/ULib/src/world.h b/ULib/src/world.h new file mode 100644 index 00000000000..82c7dfb8edd --- /dev/null +++ b/ULib/src/world.h @@ -0,0 +1,109 @@ +// world.h + +#ifndef WORLD_H +#define WORLD_H 1 + +#include +#include + +class World { +public: + // Check for memory error + U_MEMORY_TEST + + // Allocator e Deallocator + U_MEMORY_ALLOCATOR + U_MEMORY_DEALLOCATOR + + int id, randomNumber; + + // CONSTRUCTOR + + World() + { + U_TRACE_REGISTER_OBJECT(5, World, "") + } + + World(const World& w) + { + U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) + + U_MEMORY_TEST_COPY(w) + + id = w.id; + randomNumber = w.randomNumber; + } + + ~World() + { + U_TRACE_UNREGISTER_OBJECT(5, World) + } + +#ifdef DEBUG + const char* dump(bool breset) const + { + *UObjectIO::os << "id " << id << '\n' + << "randomNumber " << randomNumber; + + if (breset) + { + UObjectIO::output(); + + return UObjectIO::buffer_output; + } + + return 0; + } +#endif + +private: + World& operator=(const World&) { return *this; } +}; + +// ORM TEMPLATE SPECIALIZATIONS + +template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Base { +public: + explicit UOrmTypeHandler(World& val) : UOrmTypeHandler_Base(&val) {} + + void bindParam(UOrmStatement* stmt) const + { + U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) + + stmt->bindParam(U_ORM_TYPE_HANDLER(World, id, int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(World, randomNumber, int)); + } + + void bindResult(UOrmStatement* stmt) + { + U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) + + stmt->bindResult(U_ORM_TYPE_HANDLER(World, id, int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(World, randomNumber, int)); + } +}; + +// JSON TEMPLATE SPECIALIZATIONS + +template <> class U_EXPORT UJsonTypeHandler : public UJsonTypeHandler_Base { +public: + explicit UJsonTypeHandler(World& val) : UJsonTypeHandler_Base(&val) {} + + void toJSON(UValue& json) + { + U_TRACE(0, "UJsonTypeHandler::toJSON(%p)", &json) + + json.toJSON(U_JSON_TYPE_HANDLER(World, id, int)); + json.toJSON(U_JSON_TYPE_HANDLER(World, randomNumber, int)); + } + + void fromJSON(UValue& json) + { + U_TRACE(0, "UJsonTypeHandler::fromJSON(%p)", &json) + + json.fromJSON(U_JSON_TYPE_HANDLER(World, id, int)); + json.fromJSON(U_JSON_TYPE_HANDLER(World, randomNumber, int)); + } +}; + +#endif From 5fbcdfc1decc7bc792b0ae6075f86b342343dcc8 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Mon, 14 Jul 2014 19:54:58 +0200 Subject: [PATCH 2/4] aligned to the great work of hamiltont --- ULib/install.sh | 21 +++++++++++---------- ULib/setup.py | 9 +++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/ULib/install.sh b/ULib/install.sh index 2bcb21e0264..dcf7b5e61ad 100755 --- a/ULib/install.sh +++ b/ULib/install.sh @@ -1,10 +1,11 @@ #!/bin/bash -DIR=$HOME/FrameworkBenchmarks -PREFIX=$DIR/installs/ulib -DOCUMENT_ROOT=$DIR/ULib/www +# FWROOT=${HOME}/FrameworkBenchmarks +# IROOT=${FWROOT}/ulib/installs -RET1=$(fw_exists $PREFIX/bin/userver_tcp) +DOCUMENT_ROOT=$FWROOT/ULib/www + +RET1=$(fw_exists $IROOT/bin/userver_tcp) RET2=$(fw_exists $DOCUMENT_ROOT/db.so) if [ "$RET1" == 0 ] && [ "$RET2" == 0 ]; then @@ -22,12 +23,12 @@ cd ULib-$VERSION # ====================================================================================================== find . -exec touch {} \; # ====================================================================================================== -if [ ! -d $PREFIX ]; then - mkdir -p $PREFIX +if [ ! -d $IROOT ]; then + mkdir -p $IROOT fi DATE=`date '+%Y%m%d'` # 20140117 -BUILD_OUTPUT=$PREFIX/ULIB_BUILD_OUTPUT-$DATE.txt -LIBS="-lssl -lcrypto -lz" ./configure --prefix=$PREFIX --disable-static --without-libz --without-libuuid --without-magic --without-ssl --without-pcre --without-expat --with-mysql --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 +BUILD_OUTPUT=$IROOT/ULIB_BUILD_OUTPUT-$DATE.txt +LIBS="-lssl -lcrypto -lz" ./configure --prefix=$IROOT --disable-static --without-libz --without-libuuid --without-magic --without-ssl --without-pcre --without-expat --with-mysql --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 make -j1 install >>$BUILD_OUTPUT 2>&1 cd src/ulib/net/server/plugin/usp make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$BUILD_OUTPUT 2>&1 @@ -37,8 +38,8 @@ if [ -e .libs/db.so ]; then else return 1; fi -if [ ! -f $DIR/ULib/benchmark.cfg ]; then - cat <$DIR/ULib/benchmark.cfg +if [ ! -f $FWROOT/ULib/benchmark.cfg ]; then + cat <$FWROOT/ULib/benchmark.cfg userver { PORT 8080 PREFORK_CHILD 8 diff --git a/ULib/setup.py b/ULib/setup.py index 0e03d5dc146..067445d03f9 100755 --- a/ULib/setup.py +++ b/ULib/setup.py @@ -13,11 +13,12 @@ ############## def start(args, logfile, errfile): +# FWROOT=${HOME}/FrameworkBenchmarks +# IROOT=${FWROOT}/ulib/installs + script = """ - DIR=$HOME/FrameworkBenchmarks - PREFIX=$DIR/installs/ulib - DOCUMENT_ROOT=$DIR/ULib/www - if [ -x "$PREFIX/bin/userver_tcp" ] && [ -d "$DOCUMENT_ROOT" ] && [ -e "$DOCUMENT_ROOT/db.so" ] && [ -f $DIR/ULib/benchmark.cfg ]; then + DOCUMENT_ROOT=$FWROOT/ULib/www + if [ -x "$IROOT/ulib/bin/userver_tcp" ] && [ -d "$DOCUMENT_ROOT" ] && [ -e "$DOCUMENT_ROOT/db.so" ] && [ -f $FWROOT/ULib/benchmark.cfg ]; then return 0; fi return 1; From 5fec09e985a60c47a536ad4f4ea1d8d576c36ce5 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Tue, 15 Jul 2014 20:00:27 +0200 Subject: [PATCH 3/4] ligned to the great work of hamiltont --- ULib/install.sh | 70 ++++++++++++++++--------- ULib/setup.py | 57 ++++++++++++++------- ULib/src/db.usp | 46 ++++++++--------- ULib/src/fortune.h | 17 +++---- ULib/src/fortunes.usp | 72 +++++++++++++------------- ULib/src/json.usp | 16 +++--- ULib/src/queries.usp | 72 +++++++++++++------------- ULib/src/updates.usp | 90 ++++++++++++++++----------------- ULib/src/world.h | 5 +- WeberFramework/__init__.py | 0 evhttp-sharp/__init__.py | 0 nawak/__init__.py | 0 php-yii2/__init__.py | 0 play-activate-mysql/__init__.py | 0 pyramid/__init__.py | 0 15 files changed, 240 insertions(+), 205 deletions(-) create mode 100644 WeberFramework/__init__.py create mode 100644 evhttp-sharp/__init__.py create mode 100644 nawak/__init__.py create mode 100644 php-yii2/__init__.py create mode 100644 play-activate-mysql/__init__.py create mode 100644 pyramid/__init__.py diff --git a/ULib/install.sh b/ULib/install.sh index dcf7b5e61ad..8d6e9b73dec 100755 --- a/ULib/install.sh +++ b/ULib/install.sh @@ -1,12 +1,16 @@ #!/bin/bash -# FWROOT=${HOME}/FrameworkBenchmarks -# IROOT=${FWROOT}/ulib/installs +#------------------------------------------------------------ ------------------------------------------------------- +# toolset/run-tests.py --install server --install-strategy pertest --max-threads 1 --name ULib --test ULib --type all +#------------------------------------------------------------ ------------------------------------------------------- +# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/) +# TROOT - Path of this test's directory +#------------------------------------------------------------ ------------------------------------------------------- -DOCUMENT_ROOT=$FWROOT/ULib/www +DOCUMENT_ROOT=${TROOT}/www -RET1=$(fw_exists $IROOT/bin/userver_tcp) -RET2=$(fw_exists $DOCUMENT_ROOT/db.so) +RET1=$(fw_exists ${IROOT}/bin/userver_tcp) +RET2=$(fw_exists ${DOCUMENT_ROOT}/db.so) if [ "$RET1" == 0 ] && [ "$RET2" == 0 ]; then return 0; @@ -14,38 +18,54 @@ fi VERSION=1.4.1 # 1. Download ULib -fw_get https://github.com/stefanocasazza/ULib/archive/v$VERSION.tar.gz +#fw_get "https://github.com/stefanocasazza/ULib/archive/v${VERSION}.tar.gz" +wget -nc --no-check-certificate --trust-server-names "https://github.com/stefanocasazza/ULib/archive/v${VERSION}.tar.gz" + +# 1a. Check for Location: https://codeload.github.com/stefanocasazza/ULib/tar.gz/v1.4.1 +if [ -e v${VERSION} ]; then + mv v${VERSION} v${VERSION}.tar.gz +fi + # 2. Compile application (userver_tcp) -fw_untar v$VERSION.tar.gz +fw_untar v${VERSION}.tar.gz + cd ULib-$VERSION # ====================================================================================================== # TO AVOID configure: error: newly created file is older than distributed files! Check your system clock # ====================================================================================================== find . -exec touch {} \; # ====================================================================================================== -if [ ! -d $IROOT ]; then - mkdir -p $IROOT -fi -DATE=`date '+%Y%m%d'` # 20140117 -BUILD_OUTPUT=$IROOT/ULIB_BUILD_OUTPUT-$DATE.txt -LIBS="-lssl -lcrypto -lz" ./configure --prefix=$IROOT --disable-static --without-libz --without-libuuid --without-magic --without-ssl --without-pcre --without-expat --with-mysql --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 + +BUILD_OUTPUT=${IROOT}/ULIB_BUILD_OUTPUT.txt + +LIBS="-lssl -lcrypto -lz" \ +./configure --prefix=$IROOT \ + --disable-static \ + --with-mysql \ + --without-ssl --without-pcre --without-expat \ + --without-libz --without-libuuid --without-magic \ + --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 + make -j1 install >>$BUILD_OUTPUT 2>&1 + +# 3. Compile usp pages for benchmark cd src/ulib/net/server/plugin/usp make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$BUILD_OUTPUT 2>&1 -if [ -e .libs/db.so ]; then - mkdir -p $DOCUMENT_ROOT - cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $DOCUMENT_ROOT -else + +if [ ! -e .libs/db.so ]; then return 1; fi -if [ ! -f $FWROOT/ULib/benchmark.cfg ]; then - cat <$FWROOT/ULib/benchmark.cfg + +mkdir -p $DOCUMENT_ROOT +cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $DOCUMENT_ROOT + +cat <${TROOT}/benchmark.cfg userver { - PORT 8080 - PREFORK_CHILD 8 - LISTEN_BACKLOG 16384 - MAX_KEEP_ALIVE 16384 - DOCUMENT_ROOT ~/FrameworkBenchmarks/ULib/www - PID_FILE ~/FrameworkBenchmarks/ULib/userver_tcp.pid + PORT 8080 + PREFORK_CHILD 8 + LISTEN_BACKLOG 16384 + MAX_KEEP_ALIVE 16384 + DOCUMENT_ROOT ${DOCUMENT_ROOT} + PID_FILE ${IROOT}/userver_tcp.pid } EOF diff --git a/ULib/setup.py b/ULib/setup.py index 067445d03f9..06b50118163 100755 --- a/ULib/setup.py +++ b/ULib/setup.py @@ -1,24 +1,47 @@ +# ------------------------------------------------------- +# toolset/run-tests.py --name ULib --test ULib --type all +# ------------------------------------------------------- +# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/) +# TROOT - Path of this test's directory +# ------------------------------------------------------- + import subprocess import sys import os import time import setup_util -from os.path import expanduser +script = """ +if [ -n "${IROOT}" ] && [ -n "${TROOT}" ]; then + return 0; +fi +return 1; +""" + +p = subprocess.Popen(['sh'], stdin=subprocess.PIPE) +p.communicate(script) +if p.returncode != 0: + froot = setup_util.get_fwroot() + iroot = froot + "/installs" + troot = froot + "/ULib" +else: + iroot = subprocess.check_output('printf $IROOT 2>/dev/null', shell=True, executable='/bin/bash') + troot = subprocess.check_output('printf $TROOT 2>/dev/null', shell=True, executable='/bin/bash') -home = expanduser("~") +fprg = iroot + "/bin/userver_tcp" +fusp = troot + "/www/db.so" +fconf = troot + "/benchmark.cfg" ############## # start(args) ############## def start(args, logfile, errfile): -# FWROOT=${HOME}/FrameworkBenchmarks -# IROOT=${FWROOT}/ulib/installs - script = """ - DOCUMENT_ROOT=$FWROOT/ULib/www - if [ -x "$IROOT/ulib/bin/userver_tcp" ] && [ -d "$DOCUMENT_ROOT" ] && [ -e "$DOCUMENT_ROOT/db.so" ] && [ -f $FWROOT/ULib/benchmark.cfg ]; then + if [ -z "${IROOT}" ] || [ -z "${TROOT}" ]; then + return 0; + fi + if [ -x "${IROOT}/bin/userver_tcp" ] && [ -e "${TROOT}/www/db.so" ] && [ -f "${TROOT}/benchmark.cfg" ]; then return 0; fi return 1; @@ -28,27 +51,25 @@ def start(args, logfile, errfile): p.communicate(script) if p.returncode != 0: print("\nstart: ULib install script failed\n") - - # 3. Start ULib Server (userver_tcp) - try: - fconf = home + "/FrameworkBenchmarks/ULib/benchmark.cfg" + if not os.path.exists(fprg): + print("\nstart: ULib server program " + fprg + " not exist\n") + if not os.path.exists(fusp): + print("\nstart: ULib usp page " + fusp + " not exist\n") if not os.path.exists(fconf): print("\nstart: ULib configuration file " + fconf + " not exist\n") + # 3. Start ULib Server (userver_tcp) + try: threads = str(args.max_threads) setup_util.replace_text(fconf, "PREFORK_CHILD *", "PREFORK_CHILD " + threads) - fprg = home + "/FrameworkBenchmarks/installs/ulib/bin/userver_tcp" - if not os.path.exists(fprg): - print("\nstart: ULib server program " + fprg + " not exist\n") + print("\nstart: trying to start ULib server " + fprg + " -c " + fconf + "\n") os.putenv("ORM_DRIVER","mysql") os.putenv("ORM_OPTION","host=" + args.database_host + " user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world") os.putenv("UMEMPOOL", "1583,1507,-19,45,16458,523,-27,-14,27") - print("\nstart: trying to start ULib server " + fprg + " -c " + fconf + "\n") - - subprocess.check_call(fprg + " -c " + fconf + " >" + home + "/FrameworkBenchmarks/installs/ulib/ULIB_SERVER_OUTPUT.txt 2>&1", shell=True, stderr=errfile, stdout=logfile) + subprocess.check_call(fprg + " -c " + fconf + " >" + iroot + "/ULIB_SERVER_OUTPUT.txt 2>&1", shell=True, stderr=errfile, stdout=logfile) return 0 except subprocess.CalledProcessError: return 1 @@ -58,7 +79,7 @@ def start(args, logfile, errfile): ############## def stop(logfile, errfile): try: - subprocess.check_call("kill -TERM $( cat " + home + "/FrameworkBenchmarks/ULib/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile) + subprocess.check_call("kill -TERM $( cat " + iroot + "/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile) time.sleep(2); p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) out, err = p.communicate() diff --git a/ULib/src/db.usp b/ULib/src/db.usp index a64565570dd..9e0475a3513 100644 --- a/ULib/src/db.usp +++ b/ULib/src/db.usp @@ -67,40 +67,40 @@ Date: Wed, 17 Apr 2013 12:00:00 GMT #define AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO -static UValue* pvalue; +static UValue* pvalue; #endif -static World* pworld; -static UOrmSession* psql; -static UOrmStatement* pstmt; +static World* pworld_db; +static UOrmSession* psql_db; +static UOrmStatement* pstmt_db; -static void usp_init() +static void usp_init_db() { - U_TRACE(5, "::usp_init()") + U_TRACE(5, "::usp_init_db()") - psql = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world"))); - pstmt = U_NEW(UOrmStatement(*psql, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); + psql_db = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world"))); + pstmt_db = U_NEW(UOrmStatement(*psql_db, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); - if (pstmt == 0) U_ERROR("usp_init(): we cound't connect to db, exiting..."); + if (pstmt_db == 0) U_ERROR("usp_init_db(): we cound't connect to db, exiting..."); - pworld = U_NEW(World); + pworld_db = U_NEW(World); - pstmt->use( pworld->id); - pstmt->into(pworld->randomNumber); + pstmt_db->use( pworld_db->id); + pstmt_db->into(pworld_db->randomNumber); #ifndef AS_cpoll_cppsp_DO - pvalue = U_NEW(UValue(OBJECT_VALUE)); + pvalue = U_NEW(UValue(OBJECT_VALUE)); #endif } -static void usp_end() +static void usp_end_db() { - U_TRACE(5, "::usp_end()") + U_TRACE(5, "::usp_end_db()") - delete pstmt; - delete psql; - delete pworld; + delete pstmt_db; + delete psql_db; + delete pworld_db; #ifndef AS_cpoll_cppsp_DO - delete pvalue; + delete pvalue; #endif } --> @@ -108,13 +108,13 @@ static void usp_end() Content-Type: application/json; charset=UTF-8 --> diff --git a/ULib/src/fortune.h b/ULib/src/fortune.h index 19dd480b1e0..cf51aa896ad 100644 --- a/ULib/src/fortune.h +++ b/ULib/src/fortune.h @@ -15,8 +15,8 @@ class Fortune { U_MEMORY_ALLOCATOR U_MEMORY_DEALLOCATOR - UString message; int id; + UString message; // CONSTRUCTOR @@ -25,19 +25,16 @@ class Fortune { U_TRACE_REGISTER_OBJECT(5, Fortune, "") } - Fortune(int _id, const UString& _message) : message(_message), id(_id) + Fortune(int _id, const UString& _message) : id(_id), message(_message) { U_TRACE_REGISTER_OBJECT(5, Fortune, "%d,%.*S", _id, U_STRING_TO_TRACE(_message)) } - Fortune(const Fortune& f) + Fortune(const Fortune& f) : id(f.id), message((void*)U_STRING_TO_PARAM(f.message)) { U_TRACE_REGISTER_OBJECT(5, Fortune, "%p", &f) U_MEMORY_TEST_COPY(f) - - message = f.message; - id = f.id; } ~Fortune() @@ -87,16 +84,16 @@ template <> class U_EXPORT UOrmTypeHandler : public UOrmTypeHandler_Bas { U_TRACE(0, "UOrmTypeHandler::bindParam(%p)", stmt) - stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString)); stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, id, int)); + stmt->bindParam(U_ORM_TYPE_HANDLER(Fortune, message, UString)); } void bindResult(UOrmStatement* stmt) { U_TRACE(0, "UOrmTypeHandler::bindResult(%p)", stmt) - stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString)); stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, id, int)); + stmt->bindResult(U_ORM_TYPE_HANDLER(Fortune, message, UString)); } }; @@ -110,16 +107,16 @@ template <> class U_EXPORT UJsonTypeHandler : public UJsonTypeHandler_B { U_TRACE(0, "UJsonTypeHandler::toJSON(%p)", &json) - json.toJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); json.toJSON(U_JSON_TYPE_HANDLER(Fortune, id, int)); + json.toJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); } void fromJSON(UValue& json) { U_TRACE(0, "UJsonTypeHandler::fromJSON(%p)", &json) - json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, id, int)); + json.fromJSON(U_JSON_TYPE_HANDLER(Fortune, message, UString)); } }; diff --git a/ULib/src/fortunes.usp b/ULib/src/fortunes.usp index 811a5aad084..7c0cb31963e 100644 --- a/ULib/src/fortunes.usp +++ b/ULib/src/fortunes.usp @@ -25,7 +25,7 @@ Requirements 8. The list of Fortune objects must be sorted by the order of the message field. No ORDER BY clause is permitted in the database query (ordering within the query would be of negligible value anyway since a newly instantiated Fortune is - added to the list prior to sorting). + added to the list prior to sorting). 9. The sorted list must be provided to a server-side template and rendered to simple HTML (see below for minimum template). The resulting HTML table displays each Fortune's id number and message text. @@ -46,7 +46,7 @@ Requirements 17. The implementation is encouraged to use best practices for templates such as layout inheritence, separate header and footer files, and so on. However, this is not required. We request that implementations do not manage assets (JavaScript, - CSS, images). We are deferring asset management until we can craft a more suitable test. + CSS, images). We are deferring asset management until we can craft a more suitable test. 18. The response content type must be set to text/html. @@ -91,62 +91,62 @@ Date: Wed, 17 Apr 2013 12:00:00 GMT Fortunes
idmessage
diff --git a/ULib/src/json.usp b/ULib/src/json.usp index a7acca22b65..98c1d49ba37 100644 --- a/ULib/src/json.usp +++ b/ULib/src/json.usp @@ -55,20 +55,20 @@ Date: Wed, 17 Apr 2013 12:00:00 GMT static UString* pkey; static UString* pvalue; -static void usp_init() +static void usp_init_json() { - U_TRACE(5, "::usp_init()") + U_TRACE(5, "::usp_init_json()") - pkey = U_NEW(U_STRING_FROM_CONSTANT("message")); - pvalue = U_NEW(U_STRING_FROM_CONSTANT("Hello, World!")); + pkey = U_NEW(U_STRING_FROM_CONSTANT("message")); + pvalue = U_NEW(U_STRING_FROM_CONSTANT("Hello, World!")); } -static void usp_end() +static void usp_end_json() { - U_TRACE(5, "::usp_end()") + U_TRACE(5, "::usp_end_json()") - delete pkey; - delete pvalue; + delete pkey; + delete pvalue; } --> @@ -125,7 +125,7 @@ Content-Type: application/json; charset=UTF-8 diff --git a/ULib/src/updates.usp b/ULib/src/updates.usp index e86842c1727..7dcf9160d7e 100644 --- a/ULib/src/updates.usp +++ b/ULib/src/updates.usp @@ -12,7 +12,7 @@ Requirements The parameter specifies the number of rows to fetch and update in preparing the HTTP response (see below). 3. The queries parameter must be bounded to between 1 and 500. If the parameter is missing, is not an integer, - or is an integer less than 1, the value should be interpreted as 1; if greater than 500, the value should be interpreted as 500. + or is an integer less than 1, the value should be interpreted as 1; if greater than 500, the value should be interpreted as 500. 3. The schema for World is id (int, primary key) and randomNumber (int). @@ -85,51 +85,51 @@ Date: Wed, 17 Apr 2013 12:00:00 GMT #define AS_cpoll_cppsp_DO #ifndef AS_cpoll_cppsp_DO -static UValue* pvalue; +static UValue* pvalue; #endif -static UOrmSession* psql; -static UOrmStatement* pstmt1; -static UOrmStatement* pstmt2; -static World* pworld; -static UVector* pvworld; +static UOrmSession* psql_updates; +static UOrmStatement* pstmt1; +static UOrmStatement* pstmt2; +static World* pworld_updates; +static UVector* pvworld_updates; -static void usp_init() +static void usp_init_updates() { - U_TRACE(5, "::usp_init()") + U_TRACE(5, "::usp_init_updates()") - psql = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world"))); - pstmt1 = U_NEW(UOrmStatement(*psql, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); - pstmt2 = U_NEW(UOrmStatement(*psql, U_CONSTANT_TO_PARAM("UPDATE World SET randomNumber = ? WHERE id = ?"))); + psql_updates = U_NEW(UOrmSession(U_CONSTANT_TO_PARAM("hello_world"))); + pstmt1 = U_NEW(UOrmStatement(*psql_updates, U_CONSTANT_TO_PARAM("SELECT randomNumber FROM World WHERE id = ?"))); + pstmt2 = U_NEW(UOrmStatement(*psql_updates, U_CONSTANT_TO_PARAM("UPDATE World SET randomNumber = ? WHERE id = ?"))); - if (pstmt1 == 0 || - pstmt2 == 0) - { - U_ERROR("usp_init(): we cound't connect to db, exiting..."); - } + if (pstmt1 == 0 || + pstmt2 == 0) + { + U_ERROR("usp_init_updates(): we cound't connect to db, exiting..."); + } - pworld = U_NEW(World); - pvworld = U_NEW(UVector(500)); + pworld_updates = U_NEW(World); + pvworld_updates = U_NEW(UVector(500)); - pstmt1->use( pworld->id); - pstmt1->into(pworld->randomNumber); - pstmt2->use( pworld->randomNumber, pworld->id); + pstmt1->use( pworld_updates->id); + pstmt1->into(pworld_updates->randomNumber); + pstmt2->use( pworld_updates->randomNumber, pworld_updates->id); #ifndef AS_cpoll_cppsp_DO - pvalue = U_NEW(UValue(ARRAY_VALUE)); + pvalue = U_NEW(UValue(ARRAY_VALUE)); #endif } -static void usp_end() +static void usp_end_updates() { - U_TRACE(5, "::usp_end()") + U_TRACE(5, "::usp_end_updates()") - delete pstmt1; - delete pstmt2; - delete psql; - delete pvworld; - delete pworld; + delete pstmt1; + delete pstmt2; + delete psql_updates; + delete pvworld_updates; + delete pworld_updates; #ifndef AS_cpoll_cppsp_DO - delete pvalue; + delete pvalue; #endif } --> @@ -142,7 +142,7 @@ Content-Type: application/json; charset=UTF-8 diff --git a/ULib/src/world.h b/ULib/src/world.h index 82c7dfb8edd..895f5eaf8ad 100644 --- a/ULib/src/world.h +++ b/ULib/src/world.h @@ -24,14 +24,11 @@ class World { U_TRACE_REGISTER_OBJECT(5, World, "") } - World(const World& w) + World(const World& w) : id(w.id), randomNumber(w.randomNumber) { U_TRACE_REGISTER_OBJECT(5, World, "%p", &w) U_MEMORY_TEST_COPY(w) - - id = w.id; - randomNumber = w.randomNumber; } ~World() diff --git a/WeberFramework/__init__.py b/WeberFramework/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/evhttp-sharp/__init__.py b/evhttp-sharp/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/nawak/__init__.py b/nawak/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/php-yii2/__init__.py b/php-yii2/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/play-activate-mysql/__init__.py b/play-activate-mysql/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/pyramid/__init__.py b/pyramid/__init__.py new file mode 100644 index 00000000000..e69de29bb2d From b5ba6cc7ebf284be42a8e2314a622f8195d23599 Mon Sep 17 00:00:00 2001 From: stefanocasazza Date: Tue, 22 Jul 2014 20:29:24 +0200 Subject: [PATCH 4/4] various change for better understanding of problem on installation --- ULib/bash_profile.sh | 20 ++++++++ ULib/install.sh | 74 ++++++++++++---------------- ULib/setup.py | 84 +++++++++++++++----------------- toolset/benchmark/benchmarker.py | 64 ++++++++++++++++++++++-- 4 files changed, 152 insertions(+), 90 deletions(-) create mode 100644 ULib/bash_profile.sh mode change 100755 => 100644 ULib/setup.py diff --git a/ULib/bash_profile.sh b/ULib/bash_profile.sh new file mode 100644 index 00000000000..5d23199a8d9 --- /dev/null +++ b/ULib/bash_profile.sh @@ -0,0 +1,20 @@ +if [ -z "${FWROOT}" ]; then + export FWROOT=${HOME}/FrameworkBenchmarks +fi +#------------------------------------------------------------ -------------------------------------------- +# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/) +#------------------------------------------------------------ -------------------------------------------- +if [ -z "${IROOT}" ]; then + export IROOT=${FWROOT}/installs +fi + +# Set the root of our ULib installation +export ULIB_ROOT=${IROOT}/ULib + +# Where to find the userver_tcp executable +export PATH="${ULIB_ROOT}/bin:$PATH" + +export ULIB_VERSION=1.4.1 +export ULIB_DOCUMENT_ROOT=${ULIB_ROOT}/ULIB_DOCUMENT_ROOT +export ULIB_BUILD_OUTPUT=${ULIB_ROOT}/ULIB_BUILD_OUTPUT.txt +export ULIB_SERVER_OUTPUT=${ULIB_ROOT}/ULIB_SERVER_OUTPUT.txt diff --git a/ULib/install.sh b/ULib/install.sh index 8d6e9b73dec..46572800905 100755 --- a/ULib/install.sh +++ b/ULib/install.sh @@ -1,71 +1,59 @@ #!/bin/bash -#------------------------------------------------------------ ------------------------------------------------------- -# toolset/run-tests.py --install server --install-strategy pertest --max-threads 1 --name ULib --test ULib --type all -#------------------------------------------------------------ ------------------------------------------------------- -# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/) -# TROOT - Path of this test's directory -#------------------------------------------------------------ ------------------------------------------------------- +#---------------------------------------------------------------------------------------------------- +# toolset/run-tests.py --install server --install-strategy pertest --name ULib --test ULib --type all +#---------------------------------------------------------------------------------------------------- -DOCUMENT_ROOT=${TROOT}/www +source ${HOME}/FrameworkBenchmarks/ULib/bash_profile.sh -RET1=$(fw_exists ${IROOT}/bin/userver_tcp) -RET2=$(fw_exists ${DOCUMENT_ROOT}/db.so) +cat <${ULIB_ROOT}/benchmark.cfg +userver { + PORT 8080 + PREFORK_CHILD 8 + LISTEN_BACKLOG 16384 + MAX_KEEP_ALIVE 16384 + DOCUMENT_ROOT ${ULIB_DOCUMENT_ROOT} + PID_FILE ${ULIB_ROOT}/userver_tcp.pid +} +EOF + +RET1=$(fw_exists ${ULIB_ROOT}/bin/userver_tcp) +RET2=$(fw_exists ${ULIB_DOCUMENT_ROOT}/db.so) if [ "$RET1" == 0 ] && [ "$RET2" == 0 ]; then return 0; fi -VERSION=1.4.1 # 1. Download ULib -#fw_get "https://github.com/stefanocasazza/ULib/archive/v${VERSION}.tar.gz" -wget -nc --no-check-certificate --trust-server-names "https://github.com/stefanocasazza/ULib/archive/v${VERSION}.tar.gz" - -# 1a. Check for Location: https://codeload.github.com/stefanocasazza/ULib/tar.gz/v1.4.1 -if [ -e v${VERSION} ]; then - mv v${VERSION} v${VERSION}.tar.gz -fi +wget -nc --no-check-certificate --trust-server-names -O v${ULIB_VERSION}.tar.gz https://github.com/stefanocasazza/ULib/archive/v${ULIB_VERSION}.tar.gz # 2. Compile application (userver_tcp) -fw_untar v${VERSION}.tar.gz +fw_untar v${ULIB_VERSION}.tar.gz -cd ULib-$VERSION +cd ULib-$ULIB_VERSION # ====================================================================================================== # TO AVOID configure: error: newly created file is older than distributed files! Check your system clock # ====================================================================================================== find . -exec touch {} \; # ====================================================================================================== -BUILD_OUTPUT=${IROOT}/ULIB_BUILD_OUTPUT.txt - LIBS="-lssl -lcrypto -lz" \ -./configure --prefix=$IROOT \ - --disable-static \ - --with-mysql \ - --without-ssl --without-pcre --without-expat \ - --without-libz --without-libuuid --without-magic \ - --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$BUILD_OUTPUT 2>&1 +./configure --prefix=$ULIB_ROOT \ + --disable-static \ + --with-mysql \ + --without-ssl --without-pcre --without-expat \ + --without-libz --without-libuuid --without-magic \ + --enable-static-orm-driver=mysql --enable-static-server-plugin=http >$ULIB_BUILD_OUTPUT 2>&1 -make -j1 install >>$BUILD_OUTPUT 2>&1 +make -j1 install >>$ULIB_BUILD_OUTPUT 2>&1 # 3. Compile usp pages for benchmark cd src/ulib/net/server/plugin/usp -make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$BUILD_OUTPUT 2>&1 +make -j1 db.la fortunes.la json.la plaintext.la queries.la updates.la >>$ULIB_BUILD_OUTPUT 2>&1 if [ ! -e .libs/db.so ]; then - return 1; + return 1; fi -mkdir -p $DOCUMENT_ROOT -cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $DOCUMENT_ROOT - -cat <${TROOT}/benchmark.cfg -userver { - PORT 8080 - PREFORK_CHILD 8 - LISTEN_BACKLOG 16384 - MAX_KEEP_ALIVE 16384 - DOCUMENT_ROOT ${DOCUMENT_ROOT} - PID_FILE ${IROOT}/userver_tcp.pid -} -EOF +mkdir -p $ULIB_DOCUMENT_ROOT +cp .libs/db.so .libs/fortunes.so .libs/json.so .libs/plaintext.so .libs/queries.so .libs/updates.so $ULIB_DOCUMENT_ROOT diff --git a/ULib/setup.py b/ULib/setup.py old mode 100755 new mode 100644 index 06b50118163..3a9c959a969 --- a/ULib/setup.py +++ b/ULib/setup.py @@ -1,18 +1,27 @@ # ------------------------------------------------------- # toolset/run-tests.py --name ULib --test ULib --type all # ------------------------------------------------------- -# IROOT - Path of this test's install directory ($FWROOT/installs or $FWROOT/installs/pertest/) -# TROOT - Path of this test's directory -# ------------------------------------------------------- - -import subprocess -import sys import os +import sys import time +#import logging import setup_util +import subprocess +import multiprocessing + +#log = logging.getLogger('framework_test') + +subprocess.call("source ${HOME}/FrameworkBenchmarks/ULib/bash_profile.sh", shell=True, executable='/bin/bash') + +ulib_root = subprocess.check_output('printf "$ULIB_ROOT" 2>/dev/null', shell=True, executable='/bin/bash') +ulib_document_root = subprocess.check_output('printf "$ULIB_DOCUMENT_ROOT" 2>/dev/null', shell=True, executable='/bin/bash') + +fcfg = ulib_root + "/benchmark.cfg" +fprg = ulib_root + "/bin/userver_tcp" +fusp = ulib_document_root + "/db.so" script = """ -if [ -n "${IROOT}" ] && [ -n "${TROOT}" ]; then +if [ -x "${ULIB_ROOT}/bin/userver_tcp" ] && [ -e "${ULIB_DOCUMENT_ROOT}/db.so" ] && [ -f "${ULIB_ROOT}/benchmark.cfg" ]; then return 0; fi return 1; @@ -21,55 +30,41 @@ p = subprocess.Popen(['sh'], stdin=subprocess.PIPE) p.communicate(script) if p.returncode != 0: - froot = setup_util.get_fwroot() - iroot = froot + "/installs" - troot = froot + "/ULib" -else: - iroot = subprocess.check_output('printf $IROOT 2>/dev/null', shell=True, executable='/bin/bash') - troot = subprocess.check_output('printf $TROOT 2>/dev/null', shell=True, executable='/bin/bash') - -fprg = iroot + "/bin/userver_tcp" -fusp = troot + "/www/db.so" -fconf = troot + "/benchmark.cfg" +# log.critical('ULib install script FAILED') + print('ULib install script FAILED') + if not os.path.exists(fprg): +# log.critical("ULib server program " + fprg + " NOT EXIST") + print("ULib server program " + fprg + " NOT EXIST") + if not os.path.exists(fusp): +# log.critical("ULib usp page " + fusp + " NOT EXIST") + print("ULib usp page " + fusp + " NOT EXIST") + if not os.path.exists(fcfg): +# log.critical("ULib configuration file " + fcfg + " NOT EXIST") + print("ULib configuration file " + fcfg + " NOT EXIST") +# log.critical('Aborting') + print('Aborting') + exit(1) ############## # start(args) ############## def start(args, logfile, errfile): - - script = """ - if [ -z "${IROOT}" ] || [ -z "${TROOT}" ]; then - return 0; - fi - if [ -x "${IROOT}/bin/userver_tcp" ] && [ -e "${TROOT}/www/db.so" ] && [ -f "${TROOT}/benchmark.cfg" ]; then - return 0; - fi - return 1; - """ - - p = subprocess.Popen(['sh'], stdin=subprocess.PIPE) - p.communicate(script) - if p.returncode != 0: - print("\nstart: ULib install script failed\n") - if not os.path.exists(fprg): - print("\nstart: ULib server program " + fprg + " not exist\n") - if not os.path.exists(fusp): - print("\nstart: ULib usp page " + fusp + " not exist\n") - if not os.path.exists(fconf): - print("\nstart: ULib configuration file " + fconf + " not exist\n") - - # 3. Start ULib Server (userver_tcp) try: - threads = str(args.max_threads) - setup_util.replace_text(fconf, "PREFORK_CHILD *", "PREFORK_CHILD " + threads) + # 1. Change ULib Server configuration + #threads = str(args.max_threads) + PROCS = str(multiprocessing.cpu_count()) + setup_util.replace_text(fcfg, "PREFORK_CHILD *", "PREFORK_CHILD " + PROCS) - print("\nstart: trying to start ULib server " + fprg + " -c " + fconf + "\n") + # 2. Start ULib Server (userver_tcp) +# log.info("trying to start ULib server " + fprg + " -c " + fcfg) + print("trying to start ULib server " + fprg + " -c " + fcfg) os.putenv("ORM_DRIVER","mysql") os.putenv("ORM_OPTION","host=" + args.database_host + " user=benchmarkdbuser password=benchmarkdbpass dbname=hello_world") os.putenv("UMEMPOOL", "1583,1507,-19,45,16458,523,-27,-14,27") - subprocess.check_call(fprg + " -c " + fconf + " >" + iroot + "/ULIB_SERVER_OUTPUT.txt 2>&1", shell=True, stderr=errfile, stdout=logfile) + # Run in the background, but keep stdout/stderr for easy debugging + subprocess.Popen(fprg + " -c " + fcfg + " >$ULIB_SERVER_OUTPUT 2>&1", shell=True, stdout=logfile, stderr=errfile) return 0 except subprocess.CalledProcessError: return 1 @@ -79,6 +74,7 @@ def start(args, logfile, errfile): ############## def stop(logfile, errfile): try: + # Stop ULib Server (userver_tcp) subprocess.check_call("kill -TERM $( cat " + iroot + "/userver_tcp.pid )", shell=True, stderr=errfile, stdout=logfile) time.sleep(2); p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) diff --git a/toolset/benchmark/benchmarker.py b/toolset/benchmark/benchmarker.py index 95949a2246e..96302ed82cc 100644 --- a/toolset/benchmark/benchmarker.py +++ b/toolset/benchmark/benchmarker.py @@ -1,4 +1,6 @@ from setup.linux.installer import Installer +from setup.linux import setup_util + from benchmark import framework_test import os @@ -238,6 +240,35 @@ def warning_file(self, test_name, test_type): # End warning_file ############################################################ + ############################################################ + # get_stats_file(test_name, test_type) + # returns the stats file name for this test_name and + # test_type timestamp/test_type/test_name/raw + ############################################################ + def get_stats_file(self, test_name, test_type): + return os.path.join(self.result_directory, self.timestamp, test_type, test_name, "stats") + ############################################################ + # End get_stats_file + ############################################################ + + + ############################################################ + # stats_file(test_name, test_type) + # returns the stats file for this test_name and test_type + # timestamp/test_type/test_name/raw + ############################################################ + def stats_file(self, test_name, test_type): + path = self.get_stats_file(test_name, test_type) + try: + os.makedirs(os.path.dirname(path)) + except OSError: + pass + return path + ############################################################ + # End stats_file + ############################################################ + + ############################################################ # full_results_directory ############################################################ @@ -347,6 +378,16 @@ def __gather_tests(self): tests.append(atest) tests.sort(key=lambda x: x.name) + + # If the tests have been interrupted somehow, then we want to resume them where we left + # off, rather than starting from the beginning + if os.path.isfile('current_benchmark.txt'): + with open('current_benchmark.txt', 'r') as interrupted_benchmark: + interrupt_bench = interrupted_benchmark.read() + for index, atest in enumerate(tests): + if atest.name == interrupt_bench: + tests = tests[index:] + break return tests ############################################################ # End __gather_tests @@ -476,6 +517,8 @@ def __run_tests(self, tests): if self.os.lower() == 'windows': logging.debug("Executing __run_tests on Windows") for test in tests: + with open('current_benchmark.txt', 'w') as benchmark_resume_file: + benchmark_resume_file.write(test.name) self.__run_test(test) else: logging.debug("Executing __run_tests on Linux") @@ -487,13 +530,17 @@ def __run_tests(self, tests): Running Test: {name} ... ----------------------------------------------------- """.format(name=test.name)) + with open('current_benchmark.txt', 'w') as benchmark_resume_file: + benchmark_resume_file.write(test.name) test_process = Process(target=self.__run_test, args=(test,)) test_process.start() test_process.join(self.run_test_timeout_seconds) + self.__load_results() # Load intermediate result from child process if(test_process.is_alive()): logging.debug("Child process for {name} is still alive. Terminating.".format(name=test.name)) self.__write_intermediate_results(test.name,"__run_test timeout (="+ str(self.run_test_timeout_seconds) + " seconds)") test_process.terminate() + os.remove('current_benchmark.txt') logging.debug("End __run_tests.") ############################################################ @@ -571,7 +618,8 @@ def __run_test(self, test): p.communicate(""" sudo restart mysql sudo restart mongodb - sudo /etc/init.d/postgresql restart + sudo service redis-server restart + sudo /etc/init.d/postgresql restart """) time.sleep(10) @@ -828,6 +876,13 @@ def __write_intermediate_results(self,test_name,status_message): # End __write_intermediate_results ############################################################ + def __load_results(self): + try: + with open(os.path.join(self.latest_results_directory, 'results.json')) as f: + self.results = json.load(f) + except (ValueError, IOError): + pass + ############################################################ # __finish ############################################################ @@ -861,6 +916,9 @@ def __init__(self, args): if self.database_host == None: self.database_host = self.client_host if self.database_identity_file == None: self.database_identity_file = self.client_identity_file + # Remember root directory + self.fwroot = setup_util.get_fwroot() + # setup results and latest_results directories self.result_directory = os.path.join("results", self.name) self.latest_results_directory = self.latest_results_directory() @@ -968,8 +1026,8 @@ def __init__(self, args): if self.client_identity_file != None: self.client_ssh_string = self.client_ssh_string + " -i " + self.client_identity_file - if self.install_software: - install = Installer(self) + if self.install is not None: + install = Installer(self, self.install_strategy) install.install_software() ############################################################