From c7bac19b004d7796be38db919c777c1da2b1fcf1 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sun, 14 Aug 2011 21:53:15 +0000 Subject: Switch from the HTTPD prefork MPM to the multi-threaded event MPM where possible. Fix multi-threading issues in the SpiderMonkey integration. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1157676 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/INSTALL | 3 ++- sca-cpp/trunk/components/cache/Makefile.am | 3 +-- sca-cpp/trunk/components/cache/memcached-ssl-test | 1 + sca-cpp/trunk/components/cache/server-test | 1 + sca-cpp/trunk/components/chat/server-test | 1 + sca-cpp/trunk/components/filedb/filedb.hpp | 33 ++++++++++------------- sca-cpp/trunk/components/filedb/server-test | 1 + sca-cpp/trunk/components/log/server-test | 1 + sca-cpp/trunk/components/nosqldb/server-test | 1 + sca-cpp/trunk/components/queue/server-test | 1 + sca-cpp/trunk/components/sqldb/server-test | 1 + sca-cpp/trunk/components/sqldb/standby-test | 1 + sca-cpp/trunk/components/webservice/server-test | 1 + sca-cpp/trunk/macos/macos-install | 20 +++++++++++--- sca-cpp/trunk/modules/http/http-test | 1 + sca-cpp/trunk/modules/http/httpd-test | 1 + sca-cpp/trunk/modules/http/proxy-test | 2 ++ sca-cpp/trunk/modules/js/eval.hpp | 21 ++++++++++++--- sca-cpp/trunk/modules/server/httpd-test | 1 + sca-cpp/trunk/modules/server/server-test | 1 + sca-cpp/trunk/modules/server/wiring-test | 1 + sca-cpp/trunk/samples/store-cpp/start | 1 + sca-cpp/trunk/samples/store-nosql/start | 1 + sca-cpp/trunk/samples/store-scheme/start | 1 + sca-cpp/trunk/samples/store-sql/start | 1 + sca-cpp/trunk/ubuntu/ubuntu-install | 18 ++++++++++--- sca-cpp/trunk/ubuntu/ubuntu-install-all | 20 +++++++++++--- 27 files changed, 102 insertions(+), 37 deletions(-) (limited to 'sca-cpp') diff --git a/sca-cpp/trunk/INSTALL b/sca-cpp/trunk/INSTALL index d41342ec25..5e2cb83eab 100644 --- a/sca-cpp/trunk/INSTALL +++ b/sca-cpp/trunk/INSTALL @@ -106,8 +106,9 @@ curl-7-19-5 libcurl4-openssl-7.19.5 JSON: -Mozilla SpiderMonkey libmozjs 1.8.5 +Mozilla SpiderMonkey libmozjs 1.8.5 and (https://developer.mozilla.org/en/SpiderMonkey) +built with Mozilla nspr-4.8.8 Key/value store: tinycdb-0.77 (http://www.corpit.ru/mjt/tinycdb.html) diff --git a/sca-cpp/trunk/components/cache/Makefile.am b/sca-cpp/trunk/components/cache/Makefile.am index b1ad26a246..159a941947 100644 --- a/sca-cpp/trunk/components/cache/Makefile.am +++ b/sca-cpp/trunk/components/cache/Makefile.am @@ -50,5 +50,4 @@ client_test_LDFLAGS = -lxml2 -lcurl -lmozjs dist_noinst_SCRIPTS = memcached-test memcached-ssl-test server-test noinst_PROGRAMS = memcache-test client-test -#TESTS = memcached-test memcached-ssl-test server-test -TESTS = memcached-test server-test +TESTS = memcached-test memcached-ssl-test server-test diff --git a/sca-cpp/trunk/components/cache/memcached-ssl-test b/sca-cpp/trunk/components/cache/memcached-ssl-test index a99a5a9144..ffd1cd0e8e 100755 --- a/sca-cpp/trunk/components/cache/memcached-ssl-test +++ b/sca-cpp/trunk/components/cache/memcached-ssl-test @@ -35,6 +35,7 @@ tar -C tmp/ssl -c `../../modules/http/ssl-cert-find tmp/ssl` | tar -C tmp/tunnel ../../modules/http/httpd-start tmp/tunnel ../../modules/http/httpd-conf tmp/server localhost 8090 htdocs +../../modules/http/httpd-event-conf tmp/server tar -C tmp/ssl -c `../../modules/http/ssl-cert-find tmp/ssl` | tar -C tmp/server -x ../../modules/http/httpd-ssl-conf tmp/server 8453 ../../modules/http/cert-auth-conf tmp/server diff --git a/sca-cpp/trunk/components/cache/server-test b/sca-cpp/trunk/components/cache/server-test index 1fea285100..d9176f37ac 100755 --- a/sca-cpp/trunk/components/cache/server-test +++ b/sca-cpp/trunk/components/cache/server-test @@ -19,6 +19,7 @@ # Setup ../../modules/http/httpd-conf tmp localhost 8090 ../../modules/http/htdocs +../../modules/http/httpd-event-conf tmp ../../modules/server/server-conf tmp ../../modules/server/scheme-conf tmp cat >>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <()) js::JSContext(); - } - - friend const failable write(const value& v, ostream& os, const string& format, FileDB& db); - friend const failable read(istream& is, const string& format, FileDB& db); + friend const failable write(const value& v, ostream& os, const string& format); + friend const failable read(istream& is, const string& format); friend const failable post(const value& key, const value& val, FileDB& db); friend const failable put(const value& key, const value& val, FileDB& db); friend const failable get(const value& key, FileDB& db); @@ -111,7 +104,7 @@ const failable mkdirs(const list& path, const string& root) { /** * Write a value to a database file. */ -const failable write(const value& v, ostream& os, const string& format, FileDB& db) { +const failable write(const value& v, ostream& os, const string& format) { if (format == "scheme") { const string vs(scheme::writeValue(v)); os << vs; @@ -125,7 +118,8 @@ const failable write(const value& v, ostream& os, const string& format, Fi return true; } if (format == "json") { - failable > s = json::writeJSON(valuesToElements(v), db.jscx); + js::JSContext jscx; + failable > s = json::writeJSON(valuesToElements(v), jscx); if (!hasContent(s)) return mkfailure(reason(s)); write(content(s), os); @@ -137,7 +131,7 @@ const failable write(const value& v, ostream& os, const string& format, Fi /** * Read a value from a database file. */ -const failable read(istream& is, const string& format, FileDB& db) { +const failable read(istream& is, const string& format) { if (format == "scheme") { return scheme::readValue(is); } @@ -146,7 +140,8 @@ const failable read(istream& is, const string& format, FileDB& db) { return v; } if (format == "json") { - const failable > fv = json::readJSON(streamList(is), db.jscx); + js::JSContext jscx; + const failable > fv = json::readJSON(streamList(is), jscx); if (!hasContent(fv)) return mkfailure(reason(fv)); const value v = elementsToValues(content(fv)); @@ -170,7 +165,7 @@ const failable post(const value& key, const value& val, FileDB& db) { ofstream os(fn); if (os.fail()) return mkfailure("Couldn't post file database entry."); - const failable r = write(val, os, db.format, db); + const failable r = write(val, os, db.format); debug(r, "filedb::post::result"); return r; @@ -191,7 +186,7 @@ const failable put(const value& key, const value& val, FileDB& db) { ofstream os(fn); if (os.fail()) return mkfailure("Couldn't put file database entry."); - const failable r = write(val, os, db.format, db); + const failable r = write(val, os, db.format); debug(r, "filedb::put::result"); return r; @@ -209,7 +204,7 @@ const failable get(const value& key, FileDB& db) { ifstream is(fn); if (is.fail()) return mkfailure("Couldn't get file database entry."); - const failable val = read(is, db.format, db); + const failable val = read(is, db.format); debug(val, "filedb::get::result"); return val; diff --git a/sca-cpp/trunk/components/filedb/server-test b/sca-cpp/trunk/components/filedb/server-test index f49ba8e80a..edd5386b08 100755 --- a/sca-cpp/trunk/components/filedb/server-test +++ b/sca-cpp/trunk/components/filedb/server-test @@ -19,6 +19,7 @@ # Setup ../../modules/http/httpd-conf tmp localhost 8090 ../../modules/http/htdocs +../../modules/http/httpd-event-conf tmp ../../modules/server/server-conf tmp ../../modules/server/scheme-conf tmp cat >>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf </dev/null 2>&1 diff --git a/sca-cpp/trunk/components/sqldb/standby-test b/sca-cpp/trunk/components/sqldb/standby-test index 89bf8242da..fbb27b5bc3 100755 --- a/sca-cpp/trunk/components/sqldb/standby-test +++ b/sca-cpp/trunk/components/sqldb/standby-test @@ -19,6 +19,7 @@ # Setup ../../modules/http/httpd-conf tmp/master localhost 8090 tmp/master/htdocs +../../modules/http/httpd-event-conf tmp ./pgsql-conf tmp/master 5432 ./pgsql-start tmp/master ./pgsql localhost 5432 "drop table test;" 1>/dev/null 2>&1 diff --git a/sca-cpp/trunk/components/webservice/server-test b/sca-cpp/trunk/components/webservice/server-test index 6d3cd7f7fd..35cca9f7ad 100755 --- a/sca-cpp/trunk/components/webservice/server-test +++ b/sca-cpp/trunk/components/webservice/server-test @@ -19,6 +19,7 @@ # Setup ../../modules/http/httpd-conf tmp localhost 8090 ../../modules/http/htdocs +../../modules/http/httpd-event-conf tmp ../../modules/server/server-conf tmp ../../modules/server/scheme-conf tmp ./axis2-conf tmp diff --git a/sca-cpp/trunk/macos/macos-install b/sca-cpp/trunk/macos/macos-install index c9b929dafe..87b99b051f 100755 --- a/sca-cpp/trunk/macos/macos-install +++ b/sca-cpp/trunk/macos/macos-install @@ -149,11 +149,23 @@ if [ "$?" != "0" ]; then fi cd $build +# Build Mozilla Portable Runtime +curl -OL http://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.8.8/src/nspr-4.8.8.tar.gz +tar xzf nspr-4.8.8.tar.gz +cd nspr-4.8.8/mozilla/nsprpub +./configure --prefix=$build/nspr-4.8.8-bin --enable-64bit +make +make install +if [ "$?" != "0" ]; then + exit $? +fi +cd $build + # Build SpiderMonkey curl -OL http://ftp.mozilla.org/pub/mozilla.org/js/js-1.8.5.tar.gz tar xzf js185-1.0.0.tar.gz cd js-1.8.5/js/src -./configure --prefix=$build/js-1.8.5-bin +./configure --prefix=$build/js-1.8.5-bin --enable-threadsafe --with-system-nspr --with-nspr-prefix=$build/nspr-4.8.8-bin make make install ln -s $build/js-1.8.5-bin/lib/libmozjs185.dylib $build/js-1.8.5-bin/lib/libmozjs.dylib @@ -268,7 +280,7 @@ cd $build git clone git://git.apache.org/tuscany-sca-cpp.git cd tuscany-sca-cpp ./bootstrap -./configure CC=/usr/local/bin/gcc CXX=/usr/local/bin/g++ --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.19.5-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.10-bin --with-memcached=$build/memcached-1.4.5-bin --with-tinycdb=$build/tinycdb-bin --with-js-include=$build/tracemonkey-bin/include/js --with-js-lib=$build/tracemonkey-bin/lib --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.0-bin +./configure CC=/usr/local/bin/gcc CXX=/usr/local/bin/g++ --prefix=$build/tuscany-sca-cpp-bin --with-curl=$build/curl-7.19.5-bin --with-apr=$build/apr-1.4.x-bin --with-httpd=$build/httpd-2.3.10-bin --with-memcached=$build/memcached-1.4.5-bin --with-tinycdb=$build/tinycdb-bin --with-js-include=$build/js-1.8.5-bin/include/js --with-js-lib=$build/js-1.8.5-bin/lib --with-libcloud=$build/libcloud-0.4.2-bin --enable-threads --enable-python --with-libxml2=$build/libxml2-2.7.7-bin --enable-chat --with-libstrophe=$build/libstrophe-bin --enable-openid --with-mod-auth-openid=$build/mod-auth-openid-bin --enable-oauth --with-liboauth=$build/liboauth-0.9.1-bin --enable-mod-security --with-mod-security=$build/modsecurity-apache-2.6.0-bin make make install if [ "$?" != "0" ]; then @@ -277,8 +289,8 @@ fi cd $build # Create src archive -tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin autoconf-2.13 autoconf-2.13-bin autoconf-2.13.tar.gz curl-7.19.5 curl-7.19.5-bin curl-7.19.5.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.10 httpd-2.3.10-alpha.tar.gz httpd-2.3.10-bin libcloud-0.4.2-bin libevent-2.0.12-stable libevent-2.0.12-stable-bin libevent-2.0.12-stable.tar.gz liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.5 memcached-1.4.5-bin memcached-1.4.5.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.0 modsecurity-apache-2.6.0-bin modsecurity-apache_2.6.0.tar.gz modsecurity-crs_2.2.0 modsecurity-crs_2.2.0.tar.gz nuvem pcre-8.12 pcre-8.12-bin pcre-8.12.zip pkg-config-0.25 pkg-config-0.25-bin pkg-config-0.25.tar.gz tidy tinycdb tinycdb-bin tracemonkey-bin tracemonkey-e4364736e170 tracemonkey-e4364736e170.tar.gz tuscany-sca-cpp tuscany-sca-cpp-bin +tar czf tuscany-sca-cpp-1.0-src.tar.gz apache-libcloud-incubating-0.4.2 apache-libcloud-incubating-0.4.2.tar.bz2 apr-1.4.x apr-1.4.x-bin autoconf-2.13 autoconf-2.13-bin autoconf-2.13.tar.gz curl-7.19.5 curl-7.19.5-bin curl-7.19.5.tar.gz expat-2.0.1 expat-2.0.1-bin expat-2.0.1.tar.gz htmltidy-bin httpd-2.3.10 httpd-2.3.10-alpha.tar.gz httpd-2.3.10-bin js-1.8.5-bin js-1.8.5 js185-1.0.0.tar.gz libcloud-0.4.2-bin libevent-2.0.12-stable libevent-2.0.12-stable-bin libevent-2.0.12-stable.tar.gz liboauth-0.9.1 liboauth-0.9.1-bin liboauth-0.9.1.tar.gz libopkele libopkele-bin libstrophe libstrophe-bin libxml2-2.7.7 libxml2-2.7.7-bin libxml2-sources-2.7.7.tar.gz memcached-1.4.5 memcached-1.4.5-bin memcached-1.4.5.tar.gz mod_auth_openid mod-auth-openid-bin modsecurity-apache_2.6.0 modsecurity-apache-2.6.0-bin modsecurity-apache_2.6.0.tar.gz modsecurity-crs_2.2.0 modsecurity-crs_2.2.0.tar.gz nspr-4.8.8-bin nspr-4.8.8 nspr-4.8.8.tar.gz nuvem pcre-8.12 pcre-8.12-bin pcre-8.12.zip pkg-config-0.25 pkg-config-0.25-bin pkg-config-0.25.tar.gz tidy tinycdb tinycdb-bin tuscany-sca-cpp tuscany-sca-cpp-bin # Create bin archive -tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.19.5-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.10-bin libcloud-0.4.2-bin libevent-2.0.12-stable-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.5-bin mod-auth-openid-bin modsecurity-apache-2.6.0-bin nuvem/nuvem-parallel pcre-8.12-bin tinycdb-bin tracemonkey-bin tuscany-sca-cpp tuscany-sca-cpp-bin +tar czf tuscany-sca-cpp-1.0.tar.gz apr-1.4.x-bin curl-7.19.5-bin expat-2.0.1-bin htmltidy-bin httpd-2.3.10-bin js-1.8.5-bin libcloud-0.4.2-bin libevent-2.0.12-stable-bin liboauth-0.9.1-bin libopkele-bin libstrophe-bin libxml2-2.7.7-bin memcached-1.4.5-bin mod-auth-openid-bin modsecurity-apache-2.6.0-bin nspr-4.8.8-bin nuvem/nuvem-parallel pcre-8.12-bin tinycdb-bin tuscany-sca-cpp tuscany-sca-cpp-bin diff --git a/sca-cpp/trunk/modules/http/http-test b/sca-cpp/trunk/modules/http/http-test index e9ce572994..7874a1037f 100755 --- a/sca-cpp/trunk/modules/http/http-test +++ b/sca-cpp/trunk/modules/http/http-test @@ -19,6 +19,7 @@ # Setup ./httpd-conf tmp localhost 8090 htdocs +./httpd-event-conf tmp ./httpd-start tmp sleep 2 diff --git a/sca-cpp/trunk/modules/http/httpd-test b/sca-cpp/trunk/modules/http/httpd-test index 909bfa29f1..2b151d0e12 100755 --- a/sca-cpp/trunk/modules/http/httpd-test +++ b/sca-cpp/trunk/modules/http/httpd-test @@ -23,6 +23,7 @@ curl_prefix=`cat $here/../http/curl.prefix` # Setup ./httpd-conf tmp localhost 8090 htdocs +./httpd-event-conf tmp ./httpd-start tmp sleep 2 diff --git a/sca-cpp/trunk/modules/http/proxy-test b/sca-cpp/trunk/modules/http/proxy-test index d67d39aa1f..bf4e2bf460 100755 --- a/sca-cpp/trunk/modules/http/proxy-test +++ b/sca-cpp/trunk/modules/http/proxy-test @@ -19,8 +19,10 @@ # Setup ./httpd-conf tmp localhost 8091/8090 htdocs +./httpd-event-conf tmp ./httpd-start tmp ./httpd-conf tmp/proxy localhost 8090 tmp/proxy/htdocs +./httpd-event-conf tmp/proxy ./proxy-conf tmp/proxy ./proxy-member-conf tmp/proxy localhost 8091 ./httpd-start tmp/proxy diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp index b36c9e6119..f18c3e41c9 100644 --- a/sca-cpp/trunk/modules/js/eval.hpp +++ b/sca-cpp/trunk/modules/js/eval.hpp @@ -103,14 +103,23 @@ JSClass jsGlobalClass = { "global", JSCLASS_GLOBAL_FLAGS, JSCLASS_NO_OPTIONAL_MEMBERS }; /** - * Represents a JavaScript context. Create one per thread. + * Represents a JavaScript context. Maintains one context per thread. */ +#ifdef WANT_THREADS +__thread +#endif +::JSContext* jsContext = NULL; + class JSContext { public: JSContext() { - // Create JS context + // Create JS context if necessary debug("js::jscontext"); - cx = JS_NewContext(jsRuntime, 8192); + if (jsContext != NULL) { + cx = jsContext; + return; + } + cx = JS_NewContext(jsRuntime, 32768); if(cx == NULL) return; JS_SetOptions(cx, JSOPTION_VAROBJFIX | JSOPTION_JIT | JSOPTION_METHODJIT); @@ -129,10 +138,13 @@ public: cleanup(); return; } + jsContext = cx; } ~JSContext() { debug("js::~jscontext"); + if (cx != NULL) + JS_GC(cx); cleanup(); } @@ -147,7 +159,8 @@ public: private: bool cleanup() { if(cx != NULL) { - JS_DestroyContext(cx); + if (cx != jsContext) + JS_DestroyContext(cx); cx = NULL; } return true; diff --git a/sca-cpp/trunk/modules/server/httpd-test b/sca-cpp/trunk/modules/server/httpd-test index c56f0e0981..d541c145e9 100755 --- a/sca-cpp/trunk/modules/server/httpd-test +++ b/sca-cpp/trunk/modules/server/httpd-test @@ -23,6 +23,7 @@ curl_prefix=`cat $here/../http/curl.prefix` # Setup ../http/httpd-conf tmp localhost 8090 htdocs +../http/httpd-event-conf tmp ./server-conf tmp ./scheme-conf tmp cat >>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <>tmp/conf/httpd.conf <