diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-12-26 03:25:16 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2009-12-26 03:25:16 +0000 |
commit | f453584ae0a3ec04f1781fc35b7abe5d139c6679 (patch) | |
tree | 6724b533ec950e6dbdd4a6dcd6fafe665aec11e1 /sca-cpp/trunk/modules | |
parent | 6f0a80fbc621b205f4e1e222a453087006cce668 (diff) |
Added timing functions to measure performance, removed unused cache support, refactored and removed some obsolete tests and adjusted build.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@893937 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/http/curl-test.cpp | 40 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/Makefile.am | 9 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/server/client-test.cpp | 205 |
3 files changed, 128 insertions, 126 deletions
diff --git a/sca-cpp/trunk/modules/http/curl-test.cpp b/sca-cpp/trunk/modules/http/curl-test.cpp index 59944546a1..01355dd429 100644 --- a/sca-cpp/trunk/modules/http/curl-test.cpp +++ b/sca-cpp/trunk/modules/http/curl-test.cpp @@ -24,12 +24,11 @@ */ #include <assert.h> -#include <sys/time.h> -#include <time.h> #include <iostream> #include <sstream> #include <string> #include "slist.hpp" +#include "perf.hpp" #include "curl.hpp" namespace tuscany { @@ -39,11 +38,6 @@ const bool contains(const std::string& str, const std::string& pattern) { return str.find(pattern) != str.npos; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) { (*os) << s; return os; @@ -66,30 +60,22 @@ const bool testGet() { return true; } -const bool testGetLoop(const int count, CURLSession& ch) { - if (count == 0) +struct getLoop { + CURLSession& ch; + getLoop(CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const failable<value, std::string> r = get("http://localhost:8090", ch); + assert(hasContent(r)); + assert(contains(content(r), "It works")); return true; - const failable<value, std::string> r = get("http://localhost:8090", ch); - assert(hasContent(r)); - assert(contains(content(r), "It works")); - return testGetLoop(count - 1, ch); -} + } +}; const bool testGetPerf() { - const int count = 50; CURLSession ch; - struct timeval start; - struct timeval end; - { - testGetLoop(5, ch); - - gettimeofday(&start, NULL); - - testGetLoop(count, ch); - - gettimeofday(&end, NULL); - std::cout << "Static GET test " << duration(start, end, count) << " ms" << std::endl; - } + lambda<bool()> gl = getLoop(ch); + std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl; return true; } diff --git a/sca-cpp/trunk/modules/server/Makefile.am b/sca-cpp/trunk/modules/server/Makefile.am index 0740790ad1..9e28d8602e 100644 --- a/sca-cpp/trunk/modules/server/Makefile.am +++ b/sca-cpp/trunk/modules/server/Makefile.am @@ -23,19 +23,16 @@ lib_LTLIBRARIES = libmod_tuscany_eval.la libmod_tuscany_wiring.la INCLUDES = -I. -I$(top_builddir)/kernel -I${LIBXML2_INCLUDE} -I${HTTPD_INCLUDE} -I${APR_INCLUDE} -I${JS_INCLUDE} -I${CURL_INCLUDE} libmod_tuscany_eval_la_SOURCES = mod-eval.cpp -libmod_tuscany_eval_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libmod_tuscany_eval_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs +libmod_tuscany_eval_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs libmod_tuscany_wiring_la_SOURCES = mod-wiring.cpp -libmod_tuscany_wiring_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libmod_tuscany_wiring_la_LIBADD = -lpthread -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs +libmod_tuscany_wiring_la_LIBADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs testdir=$(prefix)/test test_LTLIBRARIES = libimpl-test.la libimpl_test_la_SOURCES = impl-test.cpp -libimpl_test_la_CXXFLAGS = $(CXXFLAGS) -D_REENTRANT -libimpl_test_la_LIBADD = -lpthread -L${APR_LIB} -lapr-1 -laprutil-1 +libimpl_test_la_LIBADD = -L${APR_LIB} -lapr-1 -laprutil-1 client_test_SOURCES = client-test.cpp client_test_LDADD = -L${LIBXML2_LIB} -lxml2 -L${APR_LIB} -lapr-1 -laprutil-1 -L${CURL_LIB} -lcurl -L${JS_LIB} -lmozjs diff --git a/sca-cpp/trunk/modules/server/client-test.cpp b/sca-cpp/trunk/modules/server/client-test.cpp index 5888c481e3..496d67f59c 100644 --- a/sca-cpp/trunk/modules/server/client-test.cpp +++ b/sca-cpp/trunk/modules/server/client-test.cpp @@ -24,12 +24,12 @@ */ #include <assert.h> -#include <sys/time.h> -#include <time.h> #include <iostream> #include <sstream> #include <string> #include "slist.hpp" +#include "parallel.hpp" +#include "perf.hpp" #include "../http/curl.hpp" namespace tuscany { @@ -39,11 +39,6 @@ const bool contains(const std::string& str, const std::string& pattern) { return str.find(pattern) != str.npos; } -const double duration(struct timeval start, struct timeval end, int count) { - long t = (end.tv_sec * 1000 + end.tv_usec / 1000) - (start.tv_sec * 1000 + start.tv_usec / 1000); - return (double)t / (double)count; -} - std::ostringstream* curlWriter(const std::string& s, std::ostringstream* os) { (*os) << s; return os; @@ -66,27 +61,22 @@ const bool testGet() { return true; } -const bool testGetLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct getLoop { + http::CURLSession ch; + getLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const failable<value, std::string> r = get("http://localhost:8090", ch); + assert(hasContent(r)); + assert(contains(content(r), "It works")); return true; - const failable<value, std::string> r = get("http://localhost:8090", ch); - assert(hasContent(r)); - assert(contains(content(r), "It works")); - return testGetLoop(count - 1, ch); -} + } +}; const bool testGetPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testGetLoop(5, ch); - gettimeofday(&start, NULL); - testGetLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "Static GET test " << duration(start, end, count) << " ms" << std::endl; - } + const lambda<bool()> gl = getLoop(ch); + std::cout << "Static GET test " << time(gl, 5, 200) << " ms" << std::endl; return true; } @@ -97,48 +87,37 @@ const bool testEval() { return true; } -const bool testEvalLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct evalLoop { + http::CURLSession ch; + evalLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); + assert(val == std::string("Hello")); return true; - const value val = content(http::evalExpr(mklist<value>(std::string("echo"), std::string("Hello")), "http://localhost:8090/test", ch)); - assert(val == std::string("Hello")); - return testEvalLoop(count - 1, ch); -} + } +}; const value blob(std::string(3000, 'A')); const list<value> blobs = mklist(blob, blob, blob, blob, blob); -const bool testBlobEvalLoop(const int count, http::CURLSession& ch) { - if (count == 0) - return true; - const value val = content(http::evalExpr(mklist<value>(std::string("echo"), blobs), "http://localhost:8090/test", ch)); - assert(val == blobs); - return testBlobEvalLoop(count - 1, ch); -} - -const bool testEvalPerf() { - const int count = 50; +struct blobEvalLoop { http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testEvalLoop(5, ch); - gettimeofday(&start, NULL); - testEvalLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC eval echo test " << duration(start, end, count) << " ms" << std::endl; + blobEvalLoop(http::CURLSession& ch) : ch(ch) { } - { - testBlobEvalLoop(5, ch); - gettimeofday(&start, NULL); - testBlobEvalLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC eval blob test " << duration(start, end, count) << " ms" << std::endl; + const bool operator()() const { + const value val = content(http::evalExpr(mklist<value>(std::string("echo"), blobs), "http://localhost:8090/test", ch)); + assert(val == blobs); + return true; } - return true; -} +}; -const bool testFeed() { +const bool testEvalPerf() { + http::CURLSession ch; + const lambda<bool()> el = evalLoop(ch); + std::cout << "JSON-RPC eval echo test " << time(el, 5, 200) << " ms" << std::endl; + const lambda<bool()> bel = blobEvalLoop(ch); + std::cout << "JSON-RPC eval blob test " << time(bel, 5, 200) << " ms" << std::endl; return true; } @@ -153,29 +132,27 @@ bool testPost() { return true; } -const bool testPostLoop(const int count, const value& val, http::CURLSession& ch) { - if (count == 0) +struct postLoop { + const value val; + http::CURLSession ch; + postLoop(const value& val, http::CURLSession& ch) : val(val), ch(ch) { + } + const bool operator()() const { + const failable<value, std::string> id = http::post(val, "http://localhost:8090/test", ch); + assert(hasContent(id)); return true; - const failable<value, std::string> id = http::post(val, "http://localhost:8090/test", ch); - assert(hasContent(id)); - return testPostLoop(count - 1, val, ch); -} + } +}; const bool testPostPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; { const list<value> i = list<value>() << (list<value>() << "name" << std::string("Apple")) << (list<value>() << "price" << std::string("$2.99")); const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); - std::cout << "ATOMPub POST small test " << duration(start, end, count) << " ms" << std::endl; + const lambda<bool()> pl = postLoop(val, ch); + std::cout << "ATOMPub POST small test " << time(pl, 5, 200) << " ms" << std::endl; } { const list<value> i = list<value>() @@ -187,12 +164,59 @@ const bool testPostPerf() { << (list<value>() << "blob5" << blob) << (list<value>() << "price" << std::string("$2.99")); const list<value> val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); - testPostLoop(5, val, ch); - gettimeofday(&start, NULL); - testPostLoop(count, val, ch); - gettimeofday(&end, NULL); - std::cout << "ATOMPub POST blob test " << duration(start, end, count) << " ms" << std::endl; + const lambda<bool()> pl = postLoop(val, ch); + std::cout << "ATOMPub POST blob test " << time(pl, 5, 200) << " ms" << std::endl; + } + return true; +} + +const bool postThread(const int count, const value& val) { + http::CURLSession ch; + const lambda<bool()> pl = postLoop(val, ch); + time(pl, 0, count); + return true; +} + +const list<future<bool> > startPost(worker& w, const int threads, const lambda<bool()>& l) { + if (threads == 0) + return list<future<bool> >(); + return cons(submit(w, l), startPost(w, threads - 1, l)); +} + +const bool checkPost(const list<future<bool> >& r) { + if (isNil(r)) + return true; + assert(car(r) == true); + return checkPost(cdr(r)); +} + +struct postThreadLoop { + const lambda<bool()> l; + const int threads; + const gc_ptr<worker> w; + postThreadLoop(const lambda<bool()>& l, const int threads) : l(l), threads(threads), w(new worker(threads)) { + } + const bool operator()() const { + list<future<bool> > r = startPost(*w, threads, l); + checkPost(r); + return true; } +}; + +const bool testPostThreadPerf() { + const int count = 50; + const int threads = 10; + + const list<value> i = list<value>() + << (list<value>() << "name" << std::string("Apple")) + << (list<value>() << "price" << std::string("$2.99")); + const value val = mklist<value>(std::string("item"), std::string("cart-53d67a61-aa5e-4e5e-8401-39edeba8b83b"), i); + + const lambda<bool()> pl= curry(lambda<bool(const int, const value)>(postThread), count, val); + const lambda<bool()> ptl = postThreadLoop(pl, threads); + double t = time(ptl, 0, 1) / (threads * count); + std::cout << "ATOMPub POST thread test " << t << " ms" << std::endl; + return true; } @@ -221,26 +245,21 @@ const bool testEvalCpp() { return true; } -const bool testEvalCppLoop(const int count, http::CURLSession& ch) { - if (count == 0) +struct evalCppLoop { + http::CURLSession ch; + evalCppLoop(http::CURLSession& ch) : ch(ch) { + } + const bool operator()() const { + const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); + assert(val == std::string("hello world")); return true; - const value val = content(http::evalExpr(mklist<value>(std::string("hello"), std::string("world")), "http://localhost:8090/cpp", ch)); - assert(val == std::string("hello world")); - return testEvalCppLoop(count - 1, ch); -} + } +}; const bool testEvalCppPerf() { - const int count = 50; http::CURLSession ch; - struct timeval start; - struct timeval end; - { - testEvalCppLoop(5, ch); - gettimeofday(&start, NULL); - testEvalCppLoop(count, ch); - gettimeofday(&end, NULL); - std::cout << "JSON-RPC C++ eval test " << duration(start, end, count) << " ms" << std::endl; - } + const lambda<bool()> el = evalCppLoop(ch); + std::cout << "JSON-RPC C++ eval test " << time(el, 5, 200) << " ms" << std::endl; return true; } @@ -254,9 +273,9 @@ int main() { tuscany::server::testGetPerf(); tuscany::server::testPost(); tuscany::server::testPostPerf(); + tuscany::server::testPostThreadPerf(); tuscany::server::testEval(); tuscany::server::testEvalPerf(); - tuscany::server::testFeed(); tuscany::server::testPut(); tuscany::server::testDel(); tuscany::server::testEvalCpp(); |