Kaynağa Gözat

Added API Star to Python frameworks. (#2633)

* Added APIStar to Python frameworks.

* Add ujson to requirements

* Resolve issues with adding API Star to the benchmarks.

* Add additional required keys to benchmark_config.json

* Switch apistar 'orm' config to 'Raw'.

* Fixing remaining API Star test issues.

* Updated API Star requirements

* Add missing trailing comma
Tom Christie 8 yıl önce
ebeveyn
işleme
46959e5797

+ 1 - 0
.travis.yml

@@ -148,6 +148,7 @@ env:
     - "TESTDIR=PHP/zend1"
     - "TESTDIR=PHP/phreeze"
     - "TESTDIR=Python/aiohttp"
+    - "TESTDIR=Python/apistar"
     - "TESTDIR=Python/api_hour"
     - "TESTDIR=Python/bottle"
     - "TESTDIR=Python/cherrypy"

+ 29 - 0
frameworks/Python/apistar/README.md

@@ -0,0 +1,29 @@
+# API Star Benchmark Test
+
+This is the API Star portion of a [benchmarking tests suite](../../)
+comparing a variety of web development platforms.
+
+The information below is specific to API Star. For further guidance,
+review the [documentation](http://frameworkbenchmarks.readthedocs.org/en/latest/).
+Also note that there is additional information provided in
+the [Python README](../).
+
+## Description
+
+[API Star](https://github.com/tomchristie/apistar) is a fast and expressive
+API framework for Python 3.
+
+## Server
+
+* Gunicorn & Meinheld on Python 3
+
+## Test Paths & Sources
+
+All of the test implementations are located within a single file ([app.py](app.py)).
+
+* [JSON Serialization](app.py): "/json"
+* [Plaintext](app.py): "/plaintext"
+
+## Resources
+
+* [Repo](https://github.com/tomchristie/apistar)

+ 32 - 0
frameworks/Python/apistar/app.py

@@ -0,0 +1,32 @@
+from apistar import App, Route, wsgi
+import ujson as json
+
+
+def json_view() -> wsgi.WSGIResponse:
+    content = json.dumps({'message': 'Hello, world!'}).encode('utf-8')
+    return wsgi.WSGIResponse(
+        '200 OK',
+        [
+            ('Content-Type', 'application/json'),
+            ('Content-Length', str(len(content)))
+        ],
+        [content]
+    )
+
+
+def plaintext_view() -> wsgi.WSGIResponse:
+    content = b'Hello, world!'
+    return wsgi.WSGIResponse(
+        '200 OK',
+        [
+            ('Content-Type', 'text/plain'),
+            ('Content-Length', str(len(content)))
+        ],
+        [content]
+    )
+
+
+app = App(routes=[
+    Route('/json', 'GET', json_view),
+    Route('/plaintext', 'GET', plaintext_view),
+])

+ 24 - 0
frameworks/Python/apistar/benchmark_config.json

@@ -0,0 +1,24 @@
+{
+  "framework": "apistar",
+  "tests": [{
+    "default": {
+      "setup_file": "setup",
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "framework": "API Star",
+      "language": "Python",
+      "flavor": "Python3",
+      "platform": "None",
+      "webserver": "Meinheld",
+      "os": "Linux",
+      "orm": "Raw",
+      "database_os": "Linux",
+      "database": "None",
+      "display_name": "API Star",
+      "notes": ""
+    }
+  }]
+}

+ 26 - 0
frameworks/Python/apistar/gunicorn_conf.py

@@ -0,0 +1,26 @@
+import multiprocessing
+import os
+import sys
+
+_is_pypy = hasattr(sys, 'pypy_version_info')
+_is_travis = os.environ.get('TRAVIS') == 'true'
+
+# falcon only implements json and plain. Not wait DB.
+workers = multiprocessing.cpu_count()  # *3
+if _is_travis:
+    workers = 2
+
+bind = "0.0.0.0:8080"
+keepalive = 120
+errorlog = '-'
+pidfile = 'gunicorn.pid'
+
+if _is_pypy:
+    worker_class = "tornado"
+else:
+    worker_class = "meinheld.gmeinheld.MeinheldWorker"
+
+    def post_fork(server, worker):
+        # Disable access log
+        import meinheld.server
+        meinheld.server.set_access_logger(None)

+ 4 - 0
frameworks/Python/apistar/requirements.txt

@@ -0,0 +1,4 @@
+gunicorn==19.7.1
+meinheld==0.6.1
+apistar==0.1.6
+ujson==1.35

+ 7 - 0
frameworks/Python/apistar/setup.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+fw_depends python3
+
+pip3 install --install-option="--prefix=${PY3_ROOT}" -r $TROOT/requirements.txt
+
+gunicorn app:app.wsgi -c gunicorn_conf.py &