From b21ec94832ad4592407ae7eee1e0c2a2ff7c8a15 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 14:18:50 +0900 Subject: [PATCH 01/21] Update Python to 2.7.4 --- installer.py | 17 +++++++++-------- tornado/setup.py | 1 - 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/installer.py b/installer.py index 187f213166f..d6a38fb9c08 100644 --- a/installer.py +++ b/installer.py @@ -46,13 +46,13 @@ def __install_server_software(self): # Python # - self.__run_command("curl http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz | tar xvz") - self.__run_command("./configure", cwd="Python-2.7.3") - self.__run_command("sudo make install", cwd="Python-2.7.3") - self.__run_command("curl http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz | tar xvz") - self.__run_command("sudo python setup.py install", cwd="setuptools-0.6c11") - self.__run_command("curl http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz | tar xvz") - self.__run_command("sudo python setup.py install", cwd="pip-1.1") + self.__run_command("curl http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz | tar xvz") + self.__run_command("./configure", cwd="Python-2.7.4") + self.__run_command("sudo make install", cwd="Python-2.7.4") + self.__run_command("curl https://pypi.python.org/packages/source/d/distribute/distribute-0.6.38.tar.gz | tar xvz") + self.__run_command("sudo python setup.py install", cwd="distribute-0.6.38") + self.__run_command("curl https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz | tar xvz") + self.__run_command("sudo python setup.py install", cwd="pip-1.3.1") self.__run_command("sudo pip install MySQL-python==1.2.4") self.__run_command("sudo pip install simplejson==3.0.7") self.__run_command("curl http://initd.org/psycopg/tarballs/PSYCOPG-2-5/psycopg2-2.5.tar.gz | tar xvz") @@ -60,6 +60,7 @@ def __install_server_software(self): self.__run_command("git clone https://github.com/iiilx/django-psycopg2-pool.git") self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool") self.__run_command("sudo pip install --upgrade numpy==1.7.1") + self.__run_command("sudo pip install --upgrade tornado motor") # # nodejs @@ -396,7 +397,7 @@ def __install_client_software(self): ############################## # MongoDB ############################## - sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 + sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10 sudo cp 10gen.list /etc/apt/sources.list.d/10gen.list sudo apt-get update yes | sudo apt-get install mongodb-10gen diff --git a/tornado/setup.py b/tornado/setup.py index eb9a563430c..f1b6b29ef91 100644 --- a/tornado/setup.py +++ b/tornado/setup.py @@ -12,7 +12,6 @@ def start(args): setup_util.replace_text( cwd + "/server.py", "localhost", args.database_host) - subprocess.check_call("sudo pip install -r requirements.txt", cwd=cwd, shell=True) subprocess.Popen("python %s/FrameworkBenchmarks/tornado/server.py --port=8080 --logging=error" % home, shell=True, cwd=cwd) return 0 From fda78a5c41ffc13cb47fc8270894f8dd9c128750 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 14:26:10 +0900 Subject: [PATCH 02/21] s/clinet/client/ --- run-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-tests.py b/run-tests.py index 7d8b12f13a9..470b17daf2f 100755 --- a/run-tests.py +++ b/run-tests.py @@ -17,7 +17,7 @@ parser.add_argument('-i', dest='identity_file', help='ssh key to ssh from the server instance to the client instance.') parser.add_argument('-p', dest='password_prompt', action='store_true') parser.add_argument('--install-software', action='store_true', help='runs the installation script before running the rest of the commands') -parser.add_argument('--install', choices=['clinet', 'server', 'all'], default='all', help='Allows you to only install the server or client software') +parser.add_argument('--install', choices=['client', 'server', 'all'], default='all', help='Allows you to only install the server or client software') parser.add_argument('--test', nargs='+', help='names of tests to run') parser.add_argument('--exclude', nargs='+', help='names of tests to exclude') parser.add_argument('--type', choices=['all', 'json', 'db', 'query', 'fortune', 'update'], default='all', help='which type of test to run') From ab74169ca3811bf36a81b25f373054876590870e Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 16:37:45 +0900 Subject: [PATCH 03/21] Add flask-pypy --- flask/app.py | 9 ++++++++- flask/benchmark_config | 8 ++++++++ flask/run_pypy.py | 14 ++++++++++++++ flask/setup_pypy.py | 21 +++++++++++++++++++++ installer.py | 5 +++++ 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 flask/run_pypy.py create mode 100644 flask/setup_pypy.py diff --git a/flask/app.py b/flask/app.py index d688d6f1057..107f10670e6 100644 --- a/flask/app.py +++ b/flask/app.py @@ -3,8 +3,15 @@ from sqlalchemy import create_engine from random import randint +try: + import MySQLdb + mysql_schema = "mysql:" +except ImportError: + mysql_schema = "mysql+pymysql:" + + app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world' +app.config['SQLALCHEMY_DATABASE_URI'] = mysql_schema + '//benchmarkdbuser:benchmarkdbpass@localhost:3306/hello_world' db = SQLAlchemy(app) dbraw_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI']) diff --git a/flask/benchmark_config b/flask/benchmark_config index 1573a361dde..93f13b1f4f0 100644 --- a/flask/benchmark_config +++ b/flask/benchmark_config @@ -15,6 +15,14 @@ "query_url": "/dbraw?queries=", "port": 8080, "sort": 84 + }, + "pypy": { + "setup_file": "setup_pypy", + "json_url": "/json", + "db_url": "/dbs", + "query_url": "/db?queries=", + "port": 8080, + "sort": 107 } }] } diff --git a/flask/run_pypy.py b/flask/run_pypy.py new file mode 100644 index 00000000000..f904ea560ff --- /dev/null +++ b/flask/run_pypy.py @@ -0,0 +1,14 @@ +import tornado.options +import tornado.wsgi +import tornado.httpserver +from tornado.options import options + +tornado.options.define('port', default=8080, type=int, help=("Server port")) +tornado.options.parse_command_line() + +import app +container = tornado.wsgi.WSGIContainer(app.app) +server = tornado.httpserver.HTTPServer(container) +server.bind(options.port) +server.start(16) +tornado.ioloop.IOLoop.instance().start() diff --git a/flask/setup_pypy.py b/flask/setup_pypy.py new file mode 100644 index 00000000000..f751e2e3d1d --- /dev/null +++ b/flask/setup_pypy.py @@ -0,0 +1,21 @@ +import subprocess +import sys +import setup_util +import os + +def start(args): + setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host) + subprocess.Popen("~/FrameworkBenchmarks/installs/pypy-2.0/bin/pypy run_pypy.py --port=8080 --logging=error", shell=True, cwd="flask") + return 0 + +def stop(): + p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) + out, err = p.communicate() + for line in out.splitlines(): + if 'pypy' in line: + try: + pid = int(line.split(None, 2)[1]) + os.kill(pid, 9) + except OSError: + pass + return 0 diff --git a/installer.py b/installer.py index d6a38fb9c08..0008af7542f 100644 --- a/installer.py +++ b/installer.py @@ -46,12 +46,17 @@ def __install_server_software(self): # Python # + self.__run_command("curl https://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvz") self.__run_command("curl http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz | tar xvz") self.__run_command("./configure", cwd="Python-2.7.4") + self.__run_command("make -j", cwd="Python-2.7.4") self.__run_command("sudo make install", cwd="Python-2.7.4") self.__run_command("curl https://pypi.python.org/packages/source/d/distribute/distribute-0.6.38.tar.gz | tar xvz") + # run pypy before python. (`setup.py install` fails after `sudo setup.py install`) + self.__run_command("../pypy-2.0/bin/pypy setup.py install", cwd="distribute-0.6.38") self.__run_command("sudo python setup.py install", cwd="distribute-0.6.38") self.__run_command("curl https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz | tar xvz") + self.__run_command("../pypy-2.0/bin/pypy setup.py install", cwd="pip-1.3.1") self.__run_command("sudo python setup.py install", cwd="pip-1.3.1") self.__run_command("sudo pip install MySQL-python==1.2.4") self.__run_command("sudo pip install simplejson==3.0.7") From 21d4334cec4f38a45d41d0a746ab68ba92841957 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 16:59:01 +0900 Subject: [PATCH 04/21] Add description to README.md --- flask/README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/flask/README.md b/flask/README.md index 5e7d1881fd7..4e5b1a45efc 100644 --- a/flask/README.md +++ b/flask/README.md @@ -2,6 +2,24 @@ Single file test, [app.py](app.py) +## Description + +Flask + Flask-SQLAlchemy + +### Interpreter + +* CPython 2.7.4 +* PyPy 2.0 + +### Database + +MySQL (MySQL-python on CPython, PyMySQL on PyPy) + +### Server + +* gunicorn+meinheld on CPython +* Tornado on PyPy + ## Test URLs ### JSON Encoding @@ -22,4 +40,4 @@ With ORM: http://localhost:8080/db?queries=2 Without ORM (raw): - http://localhost:8080/dbraw?queries=2 \ No newline at end of file + http://localhost:8080/dbraw?queries=2 From 226e51f20e796f18d04ad9ccc3c0ce0548936fe4 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 17:05:42 +0900 Subject: [PATCH 05/21] Add missed libraries to pypy --- installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer.py b/installer.py index 0008af7542f..5a34a973c14 100644 --- a/installer.py +++ b/installer.py @@ -65,7 +65,7 @@ def __install_server_software(self): self.__run_command("git clone https://github.com/iiilx/django-psycopg2-pool.git") self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool") self.__run_command("sudo pip install --upgrade numpy==1.7.1") - self.__run_command("sudo pip install --upgrade tornado motor") + self.__run_command("sudo pip install --upgrade tornado motor Flask Flask-SQLAlchemy") # # nodejs From 50c3fca5576237a1757574b6b24b259567c1bee1 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 17:14:19 +0900 Subject: [PATCH 06/21] Fix committed real DBHOSTNAME. --- flask/app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask/app.py b/flask/app.py index 107f10670e6..8914ee72c07 100644 --- a/flask/app.py +++ b/flask/app.py @@ -11,7 +11,7 @@ app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = mysql_schema + '//benchmarkdbuser:benchmarkdbpass@localhost:3306/hello_world' +app.config['SQLALCHEMY_DATABASE_URI'] = mysql_schema + '//benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world' db = SQLAlchemy(app) dbraw_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI']) From badff29eb501573c79632edd505c47091477dfbc Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 18:23:07 +0900 Subject: [PATCH 07/21] Add missing libraries. --- installer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/installer.py b/installer.py index 5a34a973c14..5cb1bd9cd7e 100644 --- a/installer.py +++ b/installer.py @@ -65,7 +65,8 @@ def __install_server_software(self): self.__run_command("git clone https://github.com/iiilx/django-psycopg2-pool.git") self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool") self.__run_command("sudo pip install --upgrade numpy==1.7.1") - self.__run_command("sudo pip install --upgrade tornado motor Flask Flask-SQLAlchemy") + self.__run_command("sudo pip install --upgrade tornado motor Flask Flask-SQLAlchemy meinheld gunicorn") + self.__run_command("pypy-2.0/bin/pip install --upgrade tornado motor Flask Flask-SQLAlchemy") # # nodejs From 874e38d5efe3a9fbbe7f4ebb95a25a223b5d4f61 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 19:04:00 +0900 Subject: [PATCH 08/21] Fix pypy installation --- installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer.py b/installer.py index 5cb1bd9cd7e..32f0976d12c 100644 --- a/installer.py +++ b/installer.py @@ -46,7 +46,7 @@ def __install_server_software(self): # Python # - self.__run_command("curl https://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvz") + self.__run_command("curl -L https://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvz") self.__run_command("curl http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz | tar xvz") self.__run_command("./configure", cwd="Python-2.7.4") self.__run_command("make -j", cwd="Python-2.7.4") From 6014cbb4bdc244824ad0ab48513b493c85b46fe2 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 19:09:16 +0900 Subject: [PATCH 09/21] Fix pypy install --- installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer.py b/installer.py index 32f0976d12c..91a103e34fc 100644 --- a/installer.py +++ b/installer.py @@ -46,7 +46,7 @@ def __install_server_software(self): # Python # - self.__run_command("curl -L https://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvz") + self.__run_command("curl -L http://bitbucket.org/pypy/pypy/downloads/pypy-2.0-linux64.tar.bz2 | tar xvj") self.__run_command("curl http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz | tar xvz") self.__run_command("./configure", cwd="Python-2.7.4") self.__run_command("make -j", cwd="Python-2.7.4") From eabc7b5c44c6ffa877452fdb0902941e2a16014b Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 19:40:16 +0900 Subject: [PATCH 10/21] Add PyMySQL to PyPy. --- installer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer.py b/installer.py index 91a103e34fc..aab9b2596ab 100644 --- a/installer.py +++ b/installer.py @@ -66,7 +66,7 @@ def __install_server_software(self): self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool") self.__run_command("sudo pip install --upgrade numpy==1.7.1") self.__run_command("sudo pip install --upgrade tornado motor Flask Flask-SQLAlchemy meinheld gunicorn") - self.__run_command("pypy-2.0/bin/pip install --upgrade tornado motor Flask Flask-SQLAlchemy") + self.__run_command("pypy-2.0/bin/pip install --upgrade tornado motor Flask Flask-SQLAlchemy PyMySQL") # # nodejs From df76f8220764735a52bbb47078cc876a2f2b59fd Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 20:16:11 +0900 Subject: [PATCH 11/21] Flask-pypy: reduce processes. Avoids OOM Killer on small memory machine (< 2.0GB) --- flask/run_pypy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask/run_pypy.py b/flask/run_pypy.py index f904ea560ff..11a3a6a7218 100644 --- a/flask/run_pypy.py +++ b/flask/run_pypy.py @@ -10,5 +10,5 @@ container = tornado.wsgi.WSGIContainer(app.app) server = tornado.httpserver.HTTPServer(container) server.bind(options.port) -server.start(16) +server.start(8) tornado.ioloop.IOLoop.instance().start() From fe85244e1efad735ed84a4b789e45c32cb925018 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 21:27:05 +0900 Subject: [PATCH 12/21] Fix "BENCHMARKING..." is not shown until complete. --- framework_test.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/framework_test.py b/framework_test.py index e75d54e21d7..b6a7e6a161c 100644 --- a/framework_test.py +++ b/framework_test.py @@ -201,6 +201,7 @@ def benchmark(self): try: if self.json_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "json"): sys.stdout.write("BENCHMARKING JSON ... ") + sys.stdout.flush() remote_script = self.__generate_concurrency_script(self.json_url, self.port) self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'json')) results = self.__parse_test('json') @@ -214,6 +215,7 @@ def benchmark(self): try: if self.db_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "db"): sys.stdout.write("BENCHMARKING DB ... ") + sys.stdout.flush() remote_script = self.__generate_concurrency_script(self.db_url, self.port) self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'db')) results = self.__parse_test('db') @@ -227,6 +229,7 @@ def benchmark(self): try: if self.query_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "query"): sys.stdout.write("BENCHMARKING Query ... ") + sys.stdout.flush() remote_script = self.__generate_query_script(self.query_url, self.port) self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'query')) results = self.__parse_test('query') @@ -239,6 +242,7 @@ def benchmark(self): try: if self.fortune_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "fortune"): sys.stdout.write("BENCHMARKING Fortune ... ") + sys.stdout.flush() remote_script = self.__generate_concurrency_script(self.fortune_url, self.port) self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'fortune')) results = self.__parse_test('fortune') @@ -251,6 +255,7 @@ def benchmark(self): try: if self.update_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "update"): sys.stdout.write("BENCHMARKING Update ... ") + sys.stdout.flush() remote_script = self.__generate_query_script(self.update_url, self.port) self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'update')) results = self.__parse_test('update') From 690606691213a27f0fcf42618408503fccaf6353 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Fri, 10 May 2013 22:37:22 +0900 Subject: [PATCH 13/21] Fix setup_pypy kills itself. --- flask/setup_pypy.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/flask/setup_pypy.py b/flask/setup_pypy.py index f751e2e3d1d..045dfb50c64 100644 --- a/flask/setup_pypy.py +++ b/flask/setup_pypy.py @@ -3,19 +3,19 @@ import setup_util import os +proc = None + def start(args): + global proc setup_util.replace_text("flask/app.py", "DBHOSTNAME", args.database_host) - subprocess.Popen("~/FrameworkBenchmarks/installs/pypy-2.0/bin/pypy run_pypy.py --port=8080 --logging=error", shell=True, cwd="flask") + proc = subprocess.Popen("~/FrameworkBenchmarks/installs/pypy-2.0/bin/pypy run_pypy.py --port=8080 --logging=error", shell=True, cwd="flask") return 0 def stop(): - p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) - out, err = p.communicate() - for line in out.splitlines(): - if 'pypy' in line: - try: - pid = int(line.split(None, 2)[1]) - os.kill(pid, 9) - except OSError: - pass - return 0 + global proc + if not proc: + return 0 + proc.terminate() + ret = proc.wait() + proc = None + return ret From 8b2fa967f61eed37ef90372d5e063cf10f7e3c15 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 11 May 2013 02:41:20 +0900 Subject: [PATCH 14/21] Specify package versions. --- installer.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/installer.py b/installer.py index aab9b2596ab..02301e00546 100644 --- a/installer.py +++ b/installer.py @@ -65,8 +65,7 @@ def __install_server_software(self): self.__run_command("git clone https://github.com/iiilx/django-psycopg2-pool.git") self.__run_command("sudo python setup.py install", cwd="django-psycopg2-pool") self.__run_command("sudo pip install --upgrade numpy==1.7.1") - self.__run_command("sudo pip install --upgrade tornado motor Flask Flask-SQLAlchemy meinheld gunicorn") - self.__run_command("pypy-2.0/bin/pip install --upgrade tornado motor Flask Flask-SQLAlchemy PyMySQL") + self.__run_command("pypy-2.0/bin/pip install PyMySQL==0.5") # # nodejs @@ -260,6 +259,13 @@ def __install_server_software(self): # ############################################################## + ############################## + # Tornado + ############################## + packages = "tornado==3.0.1 motor==0.1 pymongo==2.5" + self.__run_command("sudo pip install " + packages) + self.__run_command("pypy-2.0/bin/pip install " + packages) + ############################## # Django ############################## @@ -279,7 +285,9 @@ def __install_server_software(self): ############################## # Flask ############################## - self.__run_command("sudo pip install flask flask-sqlalchemy") + packages = "flask==0.9 flask-sqlalchemy==0.16 sqlalchemy==0.8.1 jinja2==2.6 werkzeug==0.8.3" + self.__run_command("sudo pip install " + packages) + self.__run_command("pypy-2.0/bin/pip install " + packages) ############################## # Bottle From 320882bce31811f5e0a2e8d9a419f594b6c2b3c3 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 11 May 2013 02:56:28 +0900 Subject: [PATCH 15/21] small style cleanup --- setup_util.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/setup_util.py b/setup_util.py index 0b0c1c2bce9..c90e1e76d63 100644 --- a/setup_util.py +++ b/setup_util.py @@ -4,7 +4,6 @@ def replace_text(file, to_replace, replacement): with open(file, "r") as conf: contents = conf.read() - replaced_text = re.sub(to_replace, replacement, contents) - f = open(file, "w") - f.write(replaced_text) - f.close() \ No newline at end of file + replaced_text = re.sub(to_replace, replacement, contents) + with open(file, "w") as f: + f.write(replaced_text) From cfaaf421bb9627f1741a9ef4074517fd5daaec86 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 11 May 2013 03:01:26 +0900 Subject: [PATCH 16/21] wsgi: Use meinheld worker (same as other Python Frameworks) --- wsgi/setup.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wsgi/setup.py b/wsgi/setup.py index 71f177d0fad..e88cce56f87 100755 --- a/wsgi/setup.py +++ b/wsgi/setup.py @@ -5,7 +5,8 @@ import os def start(args): - subprocess.Popen("gunicorn hello:app -b 0.0.0.0:8080 -w " + str((args.max_threads * 2)) + " --log-level=critical", shell=True, cwd="wsgi") + subprocess.Popen('gunicorn hello:app --worker-class="egg:meinheld#gunicorn_worker" -b 0.0.0.0:8080 -w ' + + str((args.max_threads * 2)) + " --log-level=critical", shell=True, cwd="wsgi") return 0 def stop(): p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE) @@ -18,4 +19,4 @@ def stop(): except OSError: pass - return 0 \ No newline at end of file + return 0 From 20753dfe9493b1c34ace72f12071b67f4a65769f Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 11 May 2013 09:20:42 +0900 Subject: [PATCH 17/21] Flask: Add fortunes --- flask/app.py | 32 +++++++++++++++++++++++++++++--- flask/benchmark_config | 13 ++++++++++++- 2 files changed, 41 insertions(+), 4 deletions(-) mode change 100644 => 100755 flask/app.py diff --git a/flask/app.py b/flask/app.py old mode 100644 new mode 100755 index 8914ee72c07..1f5e8602266 --- a/flask/app.py +++ b/flask/app.py @@ -1,7 +1,9 @@ -from flask import Flask, jsonify, request +#!/usr/bin/env python +from flask import Flask, jsonify, request, render_template from flask.ext.sqlalchemy import SQLAlchemy from sqlalchemy import create_engine from random import randint +from operator import attrgetter try: import MySQLdb @@ -9,12 +11,15 @@ except ImportError: mysql_schema = "mysql+pymysql:" +# setup app = Flask(__name__) -app.config['SQLALCHEMY_DATABASE_URI'] = mysql_schema + '//benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world' +app.config['SQLALCHEMY_DATABASE_URI'] = mysql_schema + '//benchmarkdbuser:benchmarkdbpass@DBHOSTNAME:3306/hello_world?charset=utf8' db = SQLAlchemy(app) dbraw_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI']) +# models + class World(db.Model): __tablename__ = "World" id = db.Column(db.Integer, primary_key=True) @@ -29,6 +34,14 @@ def serialize(self): 'randomNumber': self.randomNumber } +class Fortune(db.Model): + __tablename__ = "Fortune" + id = db.Column(db.Integer, primary_key=True) + message = db.Column(db.String) + + +# views + @app.route("/json") def hello(): resp = {"message": "Hello, World!"} @@ -70,5 +83,18 @@ def get_random_world_single_raw(): connection.close() return jsonify(worlds=worlds) +@app.route("/fortunes") +def get_fortunes(): + fortunes = list(Fortune.query.all()) + fortunes.sort(key=attrgetter('message')) + return render_template('fortunes.html', fortunes=fortunes) + +@app.route("/fortunesraw") +def get_forutens_raw(): + fortunes = list(dbraw_engine.execute("SELECT * FROM Fortune")) + fortunes.sort(key=attrgetter('message')) + return render_template('fortunes.html', fortunes=fortunes) + +# entry point for debugging if __name__ == "__main__": - app.run() + app.run(debug=True) diff --git a/flask/benchmark_config b/flask/benchmark_config index 93f13b1f4f0..e4d6765beca 100644 --- a/flask/benchmark_config +++ b/flask/benchmark_config @@ -6,6 +6,7 @@ "json_url": "/json", "db_url": "/dbs", "query_url": "/db?queries=", + "fortune_url": "/fortunes", "port": 8080, "sort": 31 }, @@ -13,6 +14,7 @@ "setup_file": "setup", "db_url": "/dbsraw", "query_url": "/dbraw?queries=", + "fortune_url": "/fortunesraw", "port": 8080, "sort": 84 }, @@ -21,8 +23,17 @@ "json_url": "/json", "db_url": "/dbs", "query_url": "/db?queries=", + "fortune_url": "/fortunes", "port": 8080, "sort": 107 - } + }, + "pypy-mysql-raw": { + "setup_file": "setup_pypy", + "db_url": "/dbsraw", + "query_url": "/dbraw?queries=", + "fortune_url": "/fortunesraw", + "port": 8080, + "sort": 108 + }, }] } From 77dda2ac66f415857ca8f9cf7792503ba5829ed2 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 13 May 2013 15:35:36 +0800 Subject: [PATCH 18/21] Flask-raw: Instantiate Fortune class. --- flask/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flask/app.py b/flask/app.py index 1f5e8602266..ec7d0adfbbc 100755 --- a/flask/app.py +++ b/flask/app.py @@ -91,7 +91,9 @@ def get_fortunes(): @app.route("/fortunesraw") def get_forutens_raw(): - fortunes = list(dbraw_engine.execute("SELECT * FROM Fortune")) + fortunes = [] + for row in dbraw_engine.execute("SELECT * FROM Fortune"): + fortunes.append(Fortune(id=row.id, message=row.message)) fortunes.sort(key=attrgetter('message')) return render_template('fortunes.html', fortunes=fortunes) From df7a663cf20c5a90c470e3a961afcfcd9afe04a1 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 13 May 2013 15:43:22 +0800 Subject: [PATCH 19/21] Add additional in-memory data. --- flask/app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flask/app.py b/flask/app.py index ec7d0adfbbc..110d68a8818 100755 --- a/flask/app.py +++ b/flask/app.py @@ -86,6 +86,7 @@ def get_random_world_single_raw(): @app.route("/fortunes") def get_fortunes(): fortunes = list(Fortune.query.all()) + fortunes.append(Fortune(id=0, message="Additional fortune added at request time.")) fortunes.sort(key=attrgetter('message')) return render_template('fortunes.html', fortunes=fortunes) @@ -94,6 +95,7 @@ def get_forutens_raw(): fortunes = [] for row in dbraw_engine.execute("SELECT * FROM Fortune"): fortunes.append(Fortune(id=row.id, message=row.message)) + fortunes.append(Fortune(id=0, message="Additional fortune added at request time.")) fortunes.sort(key=attrgetter('message')) return render_template('fortunes.html', fortunes=fortunes) From 543c7f2e75dafa4143677bb5ee04a7fa03dda018 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 13 May 2013 18:44:41 +0800 Subject: [PATCH 20/21] Flask-raw: optimize to not instantiate Fortune. --- flask/app.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flask/app.py b/flask/app.py index 110d68a8818..b23d8f07791 100755 --- a/flask/app.py +++ b/flask/app.py @@ -92,9 +92,7 @@ def get_fortunes(): @app.route("/fortunesraw") def get_forutens_raw(): - fortunes = [] - for row in dbraw_engine.execute("SELECT * FROM Fortune"): - fortunes.append(Fortune(id=row.id, message=row.message)) + fortunes = list(dbraw_engine.execute("SELECT * FROM Fortune")) fortunes.append(Fortune(id=0, message="Additional fortune added at request time.")) fortunes.sort(key=attrgetter('message')) return render_template('fortunes.html', fortunes=fortunes) From 7d9ee0085e85fc602fc09c4d8307bd0ab8711607 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Mon, 13 May 2013 21:46:48 +0800 Subject: [PATCH 21/21] Add fortunes.html --- flask/templates/fortunes.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 flask/templates/fortunes.html diff --git a/flask/templates/fortunes.html b/flask/templates/fortunes.html new file mode 100644 index 00000000000..6755fe184e0 --- /dev/null +++ b/flask/templates/fortunes.html @@ -0,0 +1,18 @@ + + + + + + + + +{% for fortune in fortunes %} + + + + +{% endfor %} +
idmessage
{{ fortune.id }}{{ fortune.message }}
+ + +