Skip to content

Commit cde3323

Browse files
committed
kinto (uwsgi+pyramid) benchmark
kinto is a project built on top of pyramid run it using nginx+uwsgi
1 parent ee52cce commit cde3323

23 files changed

+768
-1
lines changed

benchmarks/kinto_bench.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
import os
3+
import requests
4+
import subprocess
5+
import sys
6+
import threading
7+
import time
8+
import urllib
9+
10+
from djangocms import waitUntilUp
11+
12+
from os.path import join, abspath, dirname
13+
14+
if __name__ == "__main__":
15+
exe = sys.executable
16+
def bin(name):
17+
return join(dirname(exe), name)
18+
def rel(path):
19+
return abspath(join(dirname(__file__), path))
20+
21+
times = []
22+
23+
subprocess.check_call([abspath(exe), rel("../data/kinto_project/setup.py"), "develop"], cwd=rel("../data/kinto_project"), stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT)
24+
25+
try:
26+
os.remove("/tmp/kinto.sock")
27+
except FileNotFoundError:
28+
pass
29+
p1 = subprocess.Popen([bin("uwsgi"), rel("../data/kinto_project/production.ini")], cwd=rel("../data/kinto_project"), stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT)
30+
# p1 = subprocess.Popen([bin("uwsgi"), rel("../data/kinto_project/production.ini")], cwd=rel("../data/kinto_project"))
31+
while not os.path.exists("/tmp/kinto.sock"):
32+
time.sleep(0.001)
33+
34+
# p2 = subprocess.Popen(["nginx", "-c", abspath("../data/kinto_project/nginx.conf"), "-p", abspath("../data/kinto_project")], cwd="../data/kinto_project", stdout=open("/dev/null", "w"), stderr=subprocess.STDOUT)
35+
p2 = subprocess.Popen(["nginx", "-c", rel("../data/kinto_project/nginx.conf"), "-p", rel("../data/kinto_project")], cwd=rel("../data/kinto_project"))
36+
37+
time.sleep(0.010)
38+
39+
try:
40+
waitUntilUp(("127.0.0.1", 8000))
41+
42+
assert p1.poll() is None, p1.poll()
43+
assert p2.poll() is None, p2.poll()
44+
45+
print(requests.get("http://localhost:8000/v1").text)
46+
# print(requests.put("http://localhost:8000/v1/accounts/testuser", json={"data": {"password": "password1"}}).text)
47+
48+
n = 5000
49+
if len(sys.argv) > 1:
50+
n = int(sys.argv[1])
51+
52+
start = time.time()
53+
for i in range(n):
54+
times.append(time.time())
55+
if i % 100 == 0:
56+
print(i, time.time() - start)
57+
# requests.get("http://localhost:8000/v1/").text
58+
urllib.request.urlopen("http://localhost:8000/v1/").read()
59+
times.append(time.time())
60+
elapsed = time.time() - start
61+
print("%.2fs (%.3freq/s)" % (elapsed, n / elapsed))
62+
63+
assert p1.poll() is None, p1.poll()
64+
assert p2.poll() is None, p2.poll()
65+
66+
finally:
67+
p1.terminate()
68+
p1.kill()
69+
p1.wait()
70+
# p2.kill()
71+
p2.terminate()
72+
p2.wait()
73+
74+
if len(sys.argv) > 2:
75+
json.dump(times, open(sys.argv[2], 'w'))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
appdirs==1.4.3
2+
attrs==20.3.0
3+
bcrypt==3.2.0
4+
CacheControl==0.12.6
5+
certifi==2019.11.28
6+
cffi==1.14.5
7+
chardet==3.0.4
8+
colander==1.8.3
9+
colorama==0.4.3
10+
contextlib2==0.6.0
11+
cornice==5.2.0
12+
cornice-swagger==1.0.0
13+
distlib==0.3.0
14+
distro==1.4.0
15+
dockerflow==2020.10.0
16+
html5lib==1.0.1
17+
hupper==1.10.2
18+
idna==2.8
19+
ipaddr==2.2.0
20+
iso8601==0.1.14
21+
jsonpatch==1.32
22+
jsonpointer==2.1
23+
jsonschema==3.2.0
24+
kinto==14.2.0
25+
lockfile==0.12.2
26+
logging-color-formatter==1.0.2
27+
msgpack==0.6.2
28+
packaging==20.3
29+
PasteDeploy==2.1.1
30+
pep517==0.8.2
31+
plaster==1.0
32+
plaster-pastedeploy==0.7
33+
progress==1.5
34+
pycparser==2.20
35+
pyparsing==2.4.6
36+
pyramid==1.10.8
37+
pyramid-mailer==0.15.1
38+
pyramid-multiauth==0.9.0
39+
pyramid-tm==2.4
40+
pyrsistent==0.17.3
41+
python-dateutil==2.8.1
42+
pytoml==0.1.21
43+
repoze.sendmail==4.4.1
44+
requests==2.22.0
45+
retrying==1.3.3
46+
six==1.14.0
47+
transaction==3.0.1
48+
translationstring==1.4
49+
ujson==4.0.2
50+
urllib3==1.25.8
51+
uWSGI==2.0.19.1
52+
venusian==3.0.0
53+
waitress==2.0.0
54+
webencodings==0.5.1
55+
WebOb==1.8.7
56+
zope.deprecation==4.4.0
57+
zope.interface==5.4.0

data/kinto_project/.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
source = kinto_project
3+
omit = kinto_project/test*

data/kinto_project/CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
0.0
2+
---
3+
4+
- Initial version

data/kinto_project/MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include *.txt *.ini *.cfg *.rst
2+
recursive-include kinto_project *.ico *.png *.css *.gif *.jpg *.pt *.txt *.mak *.mako *.js *.html *.xml *.jinja2

data/kinto_project/README.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
kinto_project README
2+
==================
3+
4+
Getting Started
5+
---------------
6+
7+
- cd <directory containing this file>
8+
9+
- $VENV/bin/pip install -e .
10+
11+
- $VENV/bin/pserve development.ini
12+

data/kinto_project/app.wsgi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import configparser
2+
import logging.config
3+
import os
4+
5+
from kinto import main
6+
7+
here = os.path.dirname(__file__)
8+
9+
ini_path = os.environ.get('KINTO_INI')
10+
if ini_path is None:
11+
ini_path = os.path.join(here, 'config', 'kinto.ini')
12+
13+
# Set up logging
14+
logging.config.fileConfig(ini_path)
15+
16+
# Parse config and create WSGI app
17+
config = configparser.ConfigParser()
18+
config.read(ini_path)
19+
20+
application = main(config.items('DEFAULT'), **dict(config.items('app:main')))
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
###
2+
# app configuration
3+
# https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:kinto_project
8+
9+
pyramid.reload_templates = false
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
15+
###
16+
# wsgi server configuration
17+
###
18+
19+
[server:main]
20+
use = egg:waitress#main
21+
listen = *:6543
22+
23+
###
24+
# logging configuration
25+
# https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/logging.html
26+
###
27+
28+
[loggers]
29+
keys = root, kinto_project
30+
31+
[handlers]
32+
keys = console
33+
34+
[formatters]
35+
keys = generic
36+
37+
[logger_root]
38+
level = WARN
39+
handlers = console
40+
41+
[logger_kinto_project]
42+
level = WARN
43+
handlers =
44+
qualname = kinto_project
45+
46+
[handler_console]
47+
class = StreamHandler
48+
args = (sys.stderr,)
49+
level = NOTSET
50+
formatter = generic
51+
52+
[formatter_generic]
53+
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
54+
55+
[uwsgi]
56+
wsgi-file = app.wsgi
57+
# virtualenv = .venv
58+
socket = /tmp/kinto.sock
59+
# uid = kinto
60+
# gid = kinto
61+
enable-threads = true
62+
chmod-socket = 666
63+
processes = 1
64+
master = true
65+
module = kinto
66+
harakiri = 120
67+
lazy = true
68+
lazy-apps = true
69+
single-interpreter = true
70+
buffer-size = 65535
71+
post-buffering = 65535
72+
plugin = python

data/kinto_project/development.ini

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
###
2+
# app configuration
3+
# https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/environment.html
4+
###
5+
6+
[app:main]
7+
use = egg:kinto_project
8+
9+
pyramid.reload_templates = true
10+
pyramid.debug_authorization = false
11+
pyramid.debug_notfound = false
12+
pyramid.debug_routematch = false
13+
pyramid.default_locale_name = en
14+
pyramid.includes =
15+
pyramid_debugtoolbar
16+
17+
# By default, the toolbar only appears for clients from IP addresses
18+
# '127.0.0.1' and '::1'.
19+
# debugtoolbar.hosts = 127.0.0.1 ::1
20+
21+
###
22+
# wsgi server configuration
23+
###
24+
25+
[server:main]
26+
use = egg:waitress#main
27+
listen = localhost:6543
28+
29+
###
30+
# logging configuration
31+
# https://docs.pylonsproject.org/projects/pyramid/en/1.10-branch/narr/logging.html
32+
###
33+
34+
[loggers]
35+
keys = root, kinto_project
36+
37+
[handlers]
38+
keys = console
39+
40+
[formatters]
41+
keys = generic
42+
43+
[logger_root]
44+
level = INFO
45+
handlers = console
46+
47+
[logger_kinto_project]
48+
level = DEBUG
49+
handlers =
50+
qualname = kinto_project
51+
52+
[handler_console]
53+
class = StreamHandler
54+
args = (sys.stderr,)
55+
level = NOTSET
56+
formatter = generic
57+
58+
[formatter_generic]
59+
format = %(asctime)s %(levelname)-5.5s [%(name)s:%(lineno)s][%(threadName)s] %(message)s
60+
61+
[uwsgi]
62+
wsgi-file = app.wsgi
63+
# virtualenv = .venv
64+
socket = /tmp/kinto.sock
65+
# uid = kinto
66+
# gid = kinto
67+
enable-threads = true
68+
chmod-socket = 666
69+
processes = 1
70+
master = true
71+
module = kinto
72+
harakiri = 120
73+
lazy = true
74+
lazy-apps = true
75+
single-interpreter = true
76+
buffer-size = 65535
77+
post-buffering = 65535
78+
plugin = python
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pkg_resources
2+
3+
import kinto.core
4+
from pyramid.config import Configurator
5+
6+
# Module version, as defined in PEP-0396.
7+
__version__ = pkg_resources.get_distribution(__package__).version
8+
9+
10+
def main(global_config, **settings):
11+
config = Configurator(settings=settings)
12+
13+
kinto.core.initialize(config, __version__, 'myproject')
14+
return config.make_wsgi_app()

0 commit comments

Comments
 (0)