如何使CherryPy服务并发请求? [英] How to make CherryPy serve concurrent requests?

查看:140
本文介绍了如何使CherryPy服务并发请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已阅读到Cherrypy使用了自己的线程池.但是我看不到这样做的好处.

I have read that cherrypy uses a threadpool of its own. But I am unable to see the advantage of that.

假设我关闭了一个需要很长时间的请求,然后在另一个选项卡中我关闭了一个需要很短时间的请求.如果确实使用多线程,则短请求应在长请求之前完成.但是我看到,长请求首先完成,然后时间很短,就好像一切都按顺序处理一样.

Let's say I fire off a request which will take a long time and after that in another tab I fire off a request which will take a short time. If it really uses multithreading, the short request should complete before the long one. But I am seeing that first the long request gets completed and then the short time, as if everything is processed sequentially.

我曾尝试与不同的uWSGI框架(如Tornado和twisted)进行集成,但是我仍然看不到任何区别. http://cherrypy.readthedocs.org/en/latest/deploy.html#tornado

I have tried integrating with different uWSGI frameworks like Tornado and twistd, but still I don't see a difference. http://cherrypy.readthedocs.org/en/latest/deploy.html#tornado

这是我的入门代码.有人可以帮我吗?

This is my starter code. Can anyone help me out here?

cfg = {
'global' : {
  'server.socket_host' : Utils.gflags.FLAGS.bind_addr,
  'server.socket_port' : Utils.gflags.FLAGS.bind_port,
  'server.thread_pool' : 10,
  'engine.timeout_monitor.frequency' : gflags.FLAGS.request_time_out_secs,
},
'/static' : {"tools.sessions.on": False, 'tools.auth.on': False},
'/favicon.ico' : {"tools.sessions.on": False, 'tools.auth.on': False},
}

# To turn off the cherrypy errors on screen.
cfg['global'].update({'log.screen': False})
cfg['/static'].update({'tools.staticdir.on': True})
cfg['/static'].update({'tools.staticdir.dir': Utils.gflags.FLAGS.static_dir})
cfg['/favicon.ico'].update({'tools.staticfile.on': True})
cfg['/favicon.ico'].update({'tools.staticfile.filename':
                          Utils.gflags.FLAGS.favicon_file})


# Disable the auto reload on code change.
cherrypy.engine.autoreload.unsubscribe()

# Start the cherrypy
#Root() is defined somewhere else. Don't worry about that
cherrypy.quickstart(Root(), config = cfg)

推荐答案

是的,您似乎在此博客文章中提到了有关会话锁定的相同问题:

Yes it looks like you're having the same issue mentioned in this blog post about session locking: http://blog.schmichael.com/2007/09/20/session-locking-and-performance-in-cherrypy/

基本上,解决方案是将会话明确锁定在代码中不会阻止所有其他请求的其他位置.

Basically the solution is to explicitly lock your sessions at a different point in the code where it won't block all other requests.

cherrypy.session.acquire_lock()
cherrypy.session.release_lock()

这篇关于如何使CherryPy服务并发请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆