局限性
@app.route('/<tag:int>')
async def helloWorld(request, tag=None):
return response.html('''
<div>
<h1>
hello, {}
</h1>
</div>'''.format(tag))
为url添加一个参数,或者一个类型检测,会极大的降低框架的并发量,因为框架内部需要做比较多的事情去解析URL地址。当你注册的URL地址越多,这种影响就越明显。
根据我的测试,每多10个URL,框架并发量就会下降20%左右。到后面会成倍的增长。因此,我推荐大家使用全静态的路由,也就是
from luya import Luya
from luya import response
app = Luya()
@app.route('/get')
async def helloWorld(request):
return response.text('this is get method')
@app.route('/')
async def helloWorld(request):
return response.text('hello,world')
if __name__ == '__main__':
app.run()
在这种情况下,无论你注册多少个路由,框架速度几乎不会有任何的损失。