在Tornado Web Server上运行Django的最佳方式是使用async + django admin + django orm可能性? [英] What is the best way to run Django on Tornado Web Server to have async + django admin + django orm possibilities?

查看:174
本文介绍了在Tornado Web Server上运行Django的最佳方式是使用async + django admin + django orm可能性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要django管理面板与龙卷风后端,这将处理从网络游戏的请求。我现在不知道,以下一种方式加载django应用程序是个好主意:

  wsgi_app = tornado.wsgi .WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application(
[
('/ hello-tornado',HelloHandler) ,
('。*',tornado.web.FallbackHandler,dict(fallback = wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
服务器.listen(options.port)
tornado.ioloop.IOLoop.instance()。start()

HelloHandler将成为一个后端解析器。



我将在wsgi + ioloop组合中松动一些表现?



如果它是一个坏的解决方案,它可能运行2个应用程序:django管理员和龙卷风网。你可以回答我如何使用龙卷风应用程序的Django ORM?

解决方案

只需采取这个方程式并解决它。


  • 你想拥有非阻塞IO - X.

  • 你想要有django ORM - Y.

  • 您要拥有django admin - Z。



现在,逐点移动: / p>


  • 对于X - 龙卷风就够了。

  • 对于Z - django本身就够了。我不认为,你想有一个
    的管理员,一次管理你的网站。

  • 对于Y它更难。 Django ORM正在阻止自己。



最好的方法 - 不要使用Django ORM与龙卷风。 p>

第二种方式 - 如果您确定不会阻止整个应用程序,您可以更深入地将其直接集成到龙卷风中。从这个答案中获取解决方案。第三种方式 - 您可以将django应用程序转换为服务,这使ORM成为重要工作,您可以使用 AsyncHTTPCLient 龙卷风。



第四种方式 - 将龙卷风网络服务器集成到您的django应用程序中。其实它会给你小的表现提升。



第五种方式 - 使用两个龙卷风网络服务器。听起来很疯狂,是的。使用一个与Django ORM集成,第二个与 AsyncHTTPClient



我相信,你可以把最好的2个世界。


I would like to have django admin panel with tornado backends, which will process requests from online game. I dont know at the moment, is it a good idea to load django app in the next way:

wsgi_app = tornado.wsgi.WSGIContainer(
django.core.handlers.wsgi.WSGIHandler())
tornado_app = tornado.web.Application(
[
  ('/hello-tornado', HelloHandler),
  ('.*', tornado.web.FallbackHandler, dict(fallback=wsgi_app)),
])
server = tornado.httpserver.HTTPServer(tornado_app)
server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()

HelloHandler is going to be a backend parser.

Will I loose some performance in combining wsgi + ioloop ?

If its a bad solution, its possible to run 2 apps: django admin and tornado web. Could you answer how can I use Django ORM with Tornado App?

解决方案

Just take this equation and solve it.

  • You want to have non-blocking IO - X.
  • You want to have django ORM - Y.
  • You want to have django admin - Z.

Now, move point by point:

  • For X - tornado is enough itself.
  • For Z - django is enough itself. I don't think, you want to have thousands of administrators, that manage your site at one time.
  • For Y it is harder. Django ORM is blocking itself.

Best way here - not to use Django ORM with tornado.

Second way - you can dive deeper and integrate it directly in tornado, if you are sure that it will not block whole application. Take solution from this answer.

Third way - you can convert your django application to service, that makes heavy work with ORM, and you can access this service with AsyncHTTPCLient from tornado.

Fourth way - integrate tornado web server into your django application. Actually, it will give you small performance boost.

Fifth way - use two tornado web servers. Sounds crazy, yes. Use one with Django ORM integrated, and second with AsyncHTTPClient.

I believe, that you can take best of 2 worlds.

这篇关于在Tornado Web Server上运行Django的最佳方式是使用async + django admin + django orm可能性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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