This commit is contained in:
Channel Cat 2016-10-09 23:07:14 +00:00
parent 1c427181e2
commit f43578ab24
6 changed files with 131 additions and 173 deletions

View File

@ -1,13 +0,0 @@
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
app = web.Application()
app.router.add_get('/', handle)
app.router.add_get('/{name}', handle)
web.run_app(app)

View File

@ -1,12 +0,0 @@
# launch with
# gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker falcon:api
import sys
import falcon
import ujson as json
class Resource:
def on_get(self, req, resp):
resp.body = json.dumps({"test": True})
api = falcon.API()
api.add_route('/', Resource())

View File

@ -1,17 +0,0 @@
# launch with
# gunicorn --workers=1 --worker-class=meinheld.gmeinheld.MeinheldWorker falcon:api
from flask import Flask
app = Flask(__name__)
from ujson import dumps
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
@app.route('/')
def hello_world():
return dumps({"test": True})
if __name__ == '__main__':
import sys
app.run(port=sys.argv[-1])

View File

@ -1,33 +1,33 @@
import asyncpg import asyncpg
import sys import sys
import os import os
import inspect import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.insert(0,currentdir + '/../../../') sys.path.insert(0,currentdir + '/../../../')
import timeit import timeit
from sanic.response import json from sanic.response import json
print(json({ "test":True }).output()) print(json({ "test":True }).output())
print("Running New 100,000 times") print("Running New 100,000 times")
times = 0 times = 0
total_time = 0 total_time = 0
for n in range(6): for n in range(6):
time = timeit.timeit('json({ "test":True }).output()', setup='from sanic.response import json', number=100000) time = timeit.timeit('json({ "test":True }).output()', setup='from sanic.response import json', number=100000)
print("Took {} seconds".format(time)) print("Took {} seconds".format(time))
total_time += time total_time += time
times += 1 times += 1
print("Average: {}".format(total_time/times)) print("Average: {}".format(total_time/times))
print("Running Old 100,000 times") print("Running Old 100,000 times")
times = 0 times = 0
total_time = 0 total_time = 0
for n in range(6): for n in range(6):
time = timeit.timeit('json({ "test":True }).output_old()', setup='from sanic.response import json', number=100000) time = timeit.timeit('json({ "test":True }).output_old()', setup='from sanic.response import json', number=100000)
print("Took {} seconds".format(time)) print("Took {} seconds".format(time))
total_time += time total_time += time
times += 1 times += 1
print("Average: {}".format(total_time/times)) print("Average: {}".format(total_time/times))

View File

@ -1,17 +1,17 @@
import sys import sys
import os import os
import inspect import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.insert(0,currentdir + '/../../../') sys.path.insert(0,currentdir + '/../../../')
from sanic import Sanic from sanic import Sanic
from sanic.response import json from sanic.response import json
app = Sanic("test") app = Sanic("test")
@app.route("/") @app.route("/")
async def test(request): async def test(request):
return json({ "test": True }) return json({ "test": True })
app.run(host="0.0.0.0", port=sys.argv[1]) app.run(host="0.0.0.0", port=sys.argv[1])

View File

@ -1,83 +1,83 @@
import sys import sys
import os import os
import inspect import inspect
currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
sys.path.insert(0,currentdir + '/../../../') sys.path.insert(0,currentdir + '/../../../')
from sanic import Sanic from sanic import Sanic
from sanic.response import json, text from sanic.response import json, text
from sanic.exceptions import ServerError from sanic.exceptions import ServerError
app = Sanic("test") app = Sanic("test")
@app.route("/") @app.route("/")
async def test(request): async def test(request):
return json({ "test": True }) return json({ "test": True })
@app.route("/sync", methods=['GET', 'POST']) @app.route("/sync", methods=['GET', 'POST'])
def test(request): def test(request):
return json({ "test": True }) return json({ "test": True })
@app.route("/text/<name>/<butt:int>") @app.route("/text/<name>/<butt:int>")
def rtext(request, name, butt): def rtext(request, name, butt):
return text("yeehaww {} {}".format(name, butt)) return text("yeehaww {} {}".format(name, butt))
@app.route("/exception") @app.route("/exception")
def exception(request): def exception(request):
raise ServerError("yep") raise ServerError("yep")
@app.route("/exception/async") @app.route("/exception/async")
async def test(request): async def test(request):
raise ServerError("asunk") raise ServerError("asunk")
@app.route("/post_json") @app.route("/post_json")
def post_json(request): def post_json(request):
return json({ "received": True, "message": request.json }) return json({ "received": True, "message": request.json })
@app.route("/query_string") @app.route("/query_string")
def query_string(request): def query_string(request):
return json({ "parsed": True, "args": request.args, "url": request.url, "query_string": request.query_string }) return json({ "parsed": True, "args": request.args, "url": request.url, "query_string": request.query_string })
import sys import sys
app.run(host="0.0.0.0", port=sys.argv[1]) app.run(host="0.0.0.0", port=sys.argv[1])
# import asyncio_redis # import asyncio_redis
# import asyncpg # import asyncpg
# async def setup(sanic, loop): # async def setup(sanic, loop):
# sanic.conn = [] # sanic.conn = []
# sanic.redis = [] # sanic.redis = []
# for x in range(10): # for x in range(10):
# sanic.conn.append(await asyncpg.connect(user='postgres', password='zomgdev', database='postgres', host='192.168.99.100')) # sanic.conn.append(await asyncpg.connect(user='postgres', password='zomgdev', database='postgres', host='192.168.99.100'))
# for n in range(30): # for n in range(30):
# connection = await asyncio_redis.Connection.create(host='192.168.99.100', port=6379) # connection = await asyncio_redis.Connection.create(host='192.168.99.100', port=6379)
# sanic.redis.append(connection) # sanic.redis.append(connection)
# c=0 # c=0
# @app.route("/postgres") # @app.route("/postgres")
# async def postgres(request): # async def postgres(request):
# global c # global c
# values = await app.conn[c].fetch('''SELECT * FROM players''') # values = await app.conn[c].fetch('''SELECT * FROM players''')
# c += 1 # c += 1
# if c == 10: # if c == 10:
# c = 0 # c = 0
# return text("yep") # return text("yep")
# r=0 # r=0
# @app.route("/redis") # @app.route("/redis")
# async def redis(request): # async def redis(request):
# global r # global r
# try: # try:
# values = await app.redis[r].get('my_key') # values = await app.redis[r].get('my_key')
# except asyncio_redis.exceptions.ConnectionLostError: # except asyncio_redis.exceptions.ConnectionLostError:
# app.redis[r] = await asyncio_redis.Connection.create(host='127.0.0.1', port=6379) # app.redis[r] = await asyncio_redis.Connection.create(host='127.0.0.1', port=6379)
# values = await app.redis[r].get('my_key') # values = await app.redis[r].get('my_key')
# r += 1 # r += 1
# if r == 30: # if r == 30:
# r = 0 # r = 0
# return text(values) # return text(values)