Browse Source

added cpoll_cppsp benchmark module

xaxaxa 12 years ago
parent
commit
bdfcb9ccac

+ 12 - 0
cpoll_cppsp/Makefile

@@ -0,0 +1,12 @@
+all: cppsp_0.2
+
+clean:
+	rm -rf cppsp_0.2-rc3 cppsp_0.2
+cppsp_0.2: cppsp_0.2-rc3.tar.xz
+	tar xf cppsp_0.2-rc3.tar.xz
+	ln -s cppsp_0.2-rc3 cppsp_0.2
+	$(MAKE) CXX=g++-4.8 -C cppsp_0.2 all
+
+cppsp_0.2-rc3.tar.xz:
+	wget -c https://downloads.sourceforge.net/project/cpollcppsp/CPPSP%200.2%20%28unstable%29/cppsp_0.2-rc3.tar.xz
+

+ 12 - 0
cpoll_cppsp/README

@@ -0,0 +1,12 @@
+note: this benchmark module has only been tested on ubuntu 12.04, and it requires the following PPA to be installed:
+
+ppa:ubuntu-toolchain-r/test
+
+(run: add-apt-repository ppa:ubuntu-toolchain-r/test)
+and the following packages to be installed:
+
+gcc-4.8 g++-4.8
+
+(this will not replace the system default gcc; it adds a "gcc-4.8" and "g++-4.8" command)
+gcc/g++ 4.7 should work too.
+

+ 0 - 0
cpoll_cppsp/__init__.py


+ 14 - 0
cpoll_cppsp/benchmark_config

@@ -0,0 +1,14 @@
+{
+  "framework": "cpoll_cppsp",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "db_url": "/db",
+      "query_url": "/db?queries=",
+      "fortune_url": "/fortune",
+      "port": 16969,
+      "sort": 43
+    }
+  }]
+}

+ 4 - 0
cpoll_cppsp/run_application

@@ -0,0 +1,4 @@
+#!/bin/bash
+cd cppsp_0.2
+exec ./run_application "$@"
+

+ 18 - 0
cpoll_cppsp/setup.py

@@ -0,0 +1,18 @@
+import subprocess
+import sys
+import os
+import setup_util 
+
+def start(args):
+  setup_util.replace_text("cpoll_cppsp/www/connectioninfo.H", "\\#define BENCHMARK_DB_HOST \".*\"", "#define BENCHMARK_DB_HOST \"" + args.database_host + "\"")
+  subprocess.Popen("make && ./run_application \"$(pwd)\"/www -g g++-4.8 -m /forcedynamic.cppsm", shell=True, cwd="cpoll_cppsp");
+  return 0
+
+def stop():
+  p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
+  out, err = p.communicate()
+  for line in out.splitlines():
+    if 'cppsp_standalone' in line:
+      pid = int(line.split(None, 2)[1])
+      os.kill(pid, 9)
+  return 0

+ 20 - 0
cpoll_cppsp/www/connectioninfo.H

@@ -0,0 +1,20 @@
+#define BENCHMARK_DB_HOST "localhost"
+
+#include <stdexcept>
+using namespace std;
+
+MYSQL* doConnect(void*) {
+	printf("doConnect()\n");
+	MYSQL* tmp=mysql_init(NULL);
+	if(tmp==NULL) throw bad_alloc();
+	if (mysql_real_connect(tmp, BENCHMARK_DB_HOST, 
+					"benchmarkdbuser", "benchmarkdbpass", "hello_world", 0, NULL, 0) == NULL) {
+		string s(mysql_error(tmp));
+		mysql_close(tmp);
+		throw runtime_error(s);
+	}
+	return tmp;
+}
+void doDisconnect(void*,MYSQL* conn) {
+	mysql_close(conn);
+}

+ 63 - 0
cpoll_cppsp/www/db

@@ -0,0 +1,63 @@
+<%!-lmysqlclient%><%#
+#include <mysql/mysql.h>
+#include <json/json.h>
+#include "connectioninfo.H"
+using namespace CP;
+using namespace cppsp;
+
+MYSQL* db=NULL;
+int rn;
+int r;
+long unsigned int len1;
+MYSQL_STMT* stmt;
+MYSQL_BIND param[1], results[1];
+%>
+{ "json": [ <%
+int queries=1;
+auto it=request->queryString.find("queries");
+if(it!=request->queryString.end()) {
+	queries=atoi((*it).second);
+}
+if(queries<1)queries=1;
+if(queries>500)queries=500;
+int i;
+char query[256];
+
+if(db==NULL) {
+	db=doConnect(NULL);
+	stmt=mysql_stmt_init(db);
+	const char* sql="SELECT randomNumber FROM World WHERE id = ?";
+	mysql_stmt_prepare(stmt,sql,strlen(sql));
+	memset(param, 0, sizeof(param));
+	memset(results, 0, sizeof(results));
+	param[0].buffer_type = MYSQL_TYPE_LONG;
+	param[0].buffer = (char *)&rn;
+	param[0].buffer_length = sizeof(rn);
+	param[0].is_null = 0;
+	param[0].length = NULL;
+	results[0].buffer_type= MYSQL_TYPE_LONG;
+	results[0].buffer = &r;
+	results[0].buffer_length = sizeof(r);
+	results[0].is_null = 0;
+	results[0].length = &len1;
+	if(mysql_stmt_bind_param(stmt,param)) throw runtime_error(mysql_stmt_error(stmt));
+	if(mysql_stmt_bind_result(stmt, results)) throw runtime_error(mysql_stmt_error(stmt));
+}
+int items[queries];
+for (int i=0;i<queries;i++){
+	rn=rand()%10000;
+	if(mysql_stmt_execute(stmt)) throw runtime_error(mysql_stmt_error(stmt));
+	if(mysql_stmt_fetch(stmt)==0) {
+		items[i]=r;
+	} else {
+		items[i]=0;
+	}
+}
+for (int i=0;i<queries;i++){
+	if(i>0) {%>, <%}
+	%>{ "randomNumber": <%=items[i]%> }<%
+}
+
+response->headers["Content-Type"]="application/json";
+response->headers["Server"]="cppsp/0.2";
+%> ] }

+ 14 - 0
cpoll_cppsp/www/forcedynamic.cppsm

@@ -0,0 +1,14 @@
+<%#
+DelegateChain<void(Request&, Response&, Delegate<void()>)>::item* it;
+Server* server;
+void handleRequest(void*, Request& req, Response& resp, Delegate<void()> cb) {
+	server->handleDynamicRequest(req.path,req,resp,cb);
+}
+extern "C" void initModule(Server* s) {
+	server=s;
+	it=s->handleRequest.attach(&handleRequest);
+}
+extern "C" void deinitModule() {
+	server->handleRequest.detach(it);
+}
+%>

+ 63 - 0
cpoll_cppsp/www/fortune

@@ -0,0 +1,63 @@
+<%!-lmysqlclient%><%#
+#include <mysql/mysql.h>
+#include <json/json.h>
+#include "connectioninfo.H"
+using namespace CP;
+using namespace cppsp;
+
+
+MYSQL* db=NULL;
+
+
+bool comp_string(const String& x, const String& y) {
+	if (x.len == 0 || y.len == 0) return x.len < y.len;
+	int complen = x.len < y.len ? x.len : y.len;
+	int tmp = memcmp(x.d, y.d, complen);
+	if (tmp == 0) return x.len < y.len;
+	else return tmp < 0;
+}
+
+%><%
+if(db==NULL) {
+	db=doConnect(NULL);
+	mysql_set_character_set(db, "utf8");
+	mysql_options(db, MYSQL_SET_CHARSET_NAME, "utf8");
+}
+mysql_query(db, "SELECT id, message FROM Fortune;");
+MYSQL_RES *sqlres = mysql_store_result(db);
+if (sqlres==NULL) throw runtime_error(mysql_error(db));
+MYSQL_ROW row;
+struct fortune
+{
+	String message;
+	int id;
+	bool operator<(const fortune& other) const {
+		return comp_string(message,other.message);
+	}
+};
+vector<fortune> fortunes;
+while( (row=mysql_fetch_row(sqlres)) ){
+	fortunes.push_back({sp->addString(row[1]),atoi(row[0])});
+}
+mysql_free_result(sqlres);
+
+fortunes.push_back({"fgjdhskgsdhgjfksd",12345});
+sort(fortunes.begin(),fortunes.end());
+
+response->headers["Server"]="cppsp/0.2";
+%>
+<!DOCTYPE html>
+<html>
+<head><title>Fortunes</title></head>
+<body>
+<table>
+<tr><th>id</th><th>message</th></tr>
+<%
+for(int i=0;i<fortunes.size();i++) {
+	%>
+	<tr><td><%=fortunes[i].id%></td><td><%htmlEscape(fortunes[i].message,output);%></td></tr><%
+}
+%>
+</table>
+</body>
+</html>

+ 16 - 0
cpoll_cppsp/www/json

@@ -0,0 +1,16 @@
+<%!-ljson%><%#
+#include <string.h>
+#include <json/json.h>
+%><%
+
+json_object *hello=json_object_new_object();
+json_object_object_add(hello, "message", json_object_new_string("Hello, world"));
+
+const char *hello_str=json_object_to_json_string(hello);
+
+response->headers["Content-Type"]="application/json";
+response->headers["Server"]="cppsp/0.2";
+output.write(hello_str);
+json_object_put(hello);
+
+%>