forked from TechEmpower/FrameworkBenchmarks
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e5ed58
commit 2151722
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import multiprocessing | ||
from sanic import Sanic | ||
from sanic.log import log | ||
from sanic.response import json, text | ||
from sanic.exceptions import ServerError | ||
import aioredis | ||
from random import randint | ||
|
||
app = Sanic(__name__) | ||
app.engines = {} | ||
|
||
|
||
@app.route("/json") | ||
async def json_request(request): | ||
"""Test type 1: JSON serialization""" | ||
return json({'message': 'Hello, World!'}) | ||
|
||
|
||
@app.route("/redis/db") | ||
async def json_request(request): | ||
"""Test type 2: Single database query""" | ||
idx = randint(1, 10000) | ||
with (await app.engines['redis']) as redis: | ||
random_number = await redis.get('world:%i' % idx) | ||
return json({'Id': idx, 'RandomNumber': random_number}) | ||
|
||
|
||
@app.route("/plaintext") | ||
async def plaintext(request): | ||
"""Test type 6: Plaintext""" | ||
return text("Hello, World!") | ||
|
||
|
||
async def after_start(loop): | ||
app.engines['redis'] = await aioredis.create_pool(('127.0.0.1', 6379), | ||
minsize=40, | ||
maxsize=40, | ||
encoding='utf-8', | ||
loop=loop) | ||
|
||
async def before_stop(loop): | ||
await app.engines['redis'].clear() | ||
|
||
|
||
app.run(host="0.0.0.0", port=8000, debug=True, after_start=after_start, before_stop=before_stop, workers=multiprocessing.cpu_count()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
aioredis==0.2.8 | ||
hiredis==0.2.0 | ||
httptools==0.0.9 | ||
-e git+git@github.com:Eyepea/sanic.git@7dcdc6208dc8b69d2ba1ea9826f7bd7b226c690c#egg=Sanic | ||
ujson==1.35 | ||
uvloop==0.5.4 |