Просмотр исходного кода

added Python vibora -- certain issues with the framework only allow f… (#4412)

* added Python vibora -- certain issues with the framework only allow for 3 tests currently

* changed updateworld to fetch a random world before updating it
jenriquez-techempower 6 лет назад
Родитель
Сommit
c11360444f

+ 46 - 0
frameworks/Python/vibora/README.md

@@ -0,0 +1,46 @@
+# [Vibora](https://github.com/vibora-io/vibora) Benchmark Test
+
+The information below is specific to Vibora. For further guidance, 
+review the [documentation](http://frameworkbenchmarks.readthedocs.org/en/latest/). 
+Also note that there is additional information that's provided in 
+the [Python README](../).
+
+This is the Python Vibora portion of a [benchmarking tests suite](../../) 
+comparing a variety of frameworks.
+
+All test implementations are located within a single file 
+([app.py](app.py)).
+
+## Description
+
+Vibora, Vibora + psycopg2
+
+### Database
+
+Postgres
+
+## Test URLs
+### JSON Encoding 
+
+http://localhost:8080/json
+
+### Single Row Random Query
+
+http://localhost:8080/db
+
+### Plaintext
+
+http://localhost:8080/plaintext
+
+
+
+The following tests cannot be currently run due to an issue with the framework
+[Details Here] = https://github.com/vibora-io/vibora/issues/223
+
+### Update random rows
+
+http://localhost:8080/updates/?queries=
+
+### Variable Row Query Test 
+
+http://localhost:8080/db?queries=

+ 98 - 0
frameworks/Python/vibora/app.py

@@ -0,0 +1,98 @@
+from vibora import Vibora
+from vibora.request import Request
+from vibora.responses import JsonResponse, Response
+from vibora.hooks import Events
+from random import randint
+from operator import itemgetter
+import psycopg2
+
+READ_ROW_SQL = 'SELECT * FROM "world" WHERE id={0}'
+WRITE_ROW_SQL = 'UPDATE "world" SET "randomnumber"={0} WHERE id={1} RETURNING id, randomNumber'
+READ_ALL_FORTUNES = 'SELECT * FROM "fortune"'
+ADDITIONAL_ROW = [0, 'Additional fortune added at request time.']
+sort_fortunes_key = itemgetter(1)
+
+app = Vibora()
+con = psycopg2.connect("dbname=hello_world user=benchmarkdbuser host=tfb-database password=benchmarkdbpass")
+cur = con.cursor()
+
+def getQueriesTotal(params):
+    try:
+        queries = params['queries']
+        query_count = int(queries)
+    except:
+        return 1
+    
+    if query_count < 1:
+        return 1
+    if query_count > 500:
+        return 500
+    return query_count
+
+
+async def fetchWorld():
+    rand = randint(1, 10000)
+    cur.execute(READ_ROW_SQL.format(rand))
+    res = cur.fetchone()
+    return res
+
+async def updateWorld(world_id):
+    new_num_rand = randint(1, 10000)
+    cur.execute(WRITE_ROW_SQL.format(new_num_rand, world_id))
+    res = cur.fetchone()
+    return res
+
+async def fetchMultipleWorlds(total):
+    worlds = []
+    for x in range(total):
+        res = await fetchWorld()
+        worlds.append({'id': res[0], 'randomNumber': res[1]})
+    return worlds
+
+async def updateMultipleWorlds(total):
+    worlds = []
+    for x in range(total):
+        res = await fetchWorld()
+        updated = await updateWorld(res[0])
+        worlds.append({'id': updated[0], 'randomNumber': updated[1]})
+    return worlds
+
+async def fetchFortunes():
+    cur.execute(READ_ALL_FORTUNES)
+    res = cur.fetchall()
+    return res
+
[email protected]('/fortunes')
+async def fortunes():
+    fortunes = await fetchFortunes()
+    fortunes.append(ADDITIONAL_ROW)
+    fortunes = fortunes.sort(key=sort_fortunes_key)
+    return await app.render('index.html', fortunes=fortunes)
+
[email protected]('/db')
+async def single_query(request: Request):
+    res = await fetchWorld()
+    return JsonResponse({'id': res[0], 'randomNumber': res[1]}, headers={'Server': 'Vibora'})
+
[email protected]('/plaintext')
+async def plaintext():
+    return Response(b'Hello, World!', headers={'Server': 'Vibora', 'Content-Type': 'text/plain'})
+
[email protected]('/json')
+async def json():
+    return JsonResponse({'message': 'Hello, World!'}, headers={'Server': 'Vibora'})
+
[email protected]('/queries')
+async def multiple_queries(request: Request):
+    total_queries = getQueriesTotal(request.args)
+    worlds = await fetchMultipleWorlds(total_queries)
+    return JsonResponse(worlds, headers={'Server': 'Vibora', 'Content-Type': 'application/json', 'Content-Length': str(total_queries)})
+
[email protected]('/updates')
+async def update_queries(request: Request):
+    total_queries = getQueriesTotal(request.args)
+    worlds = updateMultipleWorlds(total_queries)
+    return JsonResponse(worlds, headers={'Server': 'Vibora', 'Content-Type': 'application/json', 'Content-Length': str(total_queries)})
+
+if __name__ == '__main__':
+    app.run(host="0.0.0.0", port=8000)

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

@@ -0,0 +1,24 @@
+{
+  "framework": "vibora",
+  "tests": [{
+    "default": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "db_url": "/db",
+      "port": 8000,
+      "approach": "Realistic",
+      "classification": "Platform",
+      "framework": "vibora",
+      "language": "Python",
+      "flavor": "Python3",
+      "platform": "None",
+      "webserver": "None",
+      "os": "Linux",
+      "orm": "Full",
+      "database_os": "Linux",
+      "database": "Postgres",
+      "display_name": "Vibora",
+      "notes": ""
+    }
+  }]
+}

+ 9 - 0
frameworks/Python/vibora/requirements.txt

@@ -0,0 +1,9 @@
+django-jsonresponse==0.10.0
+pendulum==2.0.4
+psycopg2-binary==2.7.7
+python-dateutil==2.7.5
+pytzdata==2018.7
+six==1.12.0
+ujson==1.35
+uvloop==0.12.0
+vibora==0.0.6

+ 21 - 0
frameworks/Python/vibora/templates/index.html

@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Fortunes</title>
+</head>
+<body>
+    <table>
+        <tr>
+            <th>id</th>
+            <th>message</th>
+        </tr>
+        {% for fortune in fortunes %}
+        <tr>
+            <td>{{ fortune[0] }}</td>
+            <td>{{ fortune[1] }}</td>
+        </tr>
+        {% endfor %}
+    </table>
+</body>
+</html>

+ 9 - 0
frameworks/Python/vibora/vibora.dockerfile

@@ -0,0 +1,9 @@
+FROM python:3.6.6-stretch
+
+ADD ./ /vibora
+
+WORKDIR /vibora
+
+RUN pip3 install -r /vibora/requirements.txt
+
+CMD ["python3", "app.py"]