我的rest api使用python-bottle服务器。收到请求后,我使用os.system调用RScript。rscript需要一些时间才能执行,之后它将继续操作。我的问题是,当多个用户使用api时,它会被排队,而不是并行发生。
@route('/UploadFiles', method='POST')
def UploadFiles():
#Reading the initial text file to get application name and other details
with open('/home/user/abc.txt') as f:
for line in f:
if('Application Name' in line):
appName=line.split(" - ")
appName=str(appName[1])
appName=appName.strip()
print "inside upload files"
uniquename=str(uuid.uuid1())
print "uuid is :",uniquename
retcode = subprocess.call(['Rscript','/home/user/RProgram.r',uniquename])
print "executed r script"
run(host='192.168.1.155', port=8555)
所有这些都必须对每个用户并行进行。但它正在排队。我在这里做错了什么。
我正在使用运行
sudo nohup python restcall.py -&
所以我认为印刷声明不是问题所在。
我想我找到了一个解决方案。Bottle默认运行在内置的wsgiref WSGIServer上。这种非线程HTTP服务器非常适合开发和早期生产,但当服务器负载增加时,可能会成为性能瓶颈。
提高性能的最简单方法是安装一个多线程服务器库,如paste或cherrypy,并告诉Bottle使用它来代替单线程服务器:
bottle.run(server='paste')
引用python-bottle文档