简体   繁体   English

动态路由,生产中的龙卷风部署

[英]dynamic routing , tornado deployment in production

I have 4 python tornado threads running on different ports on different machines.我有 4 个 python 龙卷风线程在不同机器的不同端口上运行。 I used nginx to route and load balance.我使用 nginx 来路由和负载平衡。 The code is the same for all of them.所有这些代码都是相同的。 It is a asynchronous code.它是一个异步代码。 I also have a local file, lets say function.py on each machine that gets called by the python thread, does some computation and returns the answer.我也有一个本地文件,让我们说每台机器上的 function.py 被 python 线程调用,做一些计算并返回答案。

My requirement is that I may need to periodically update the function.py file.我的要求是我可能需要定期更新 function.py 文件。 However, I do not want the server to be stopped to reload the function since I don't want to drop any incoming request .但是,我不希望停止服务器以重新加载该功能,因为我不想删除任何传入请求 I am open to changing nginx to something else if required.如果需要,我愿意将 nginx 更改为其他内容。 Any suggestions will be appreciated.任何建议将不胜感激。 Thanks!谢谢!

Edit: Could there be a way to modify/configure the nginx in such a way that it will redirect to certain servers(say port 8011-8014) only when they are up ?编辑:是否有一种方法可以修改/配置 nginx,使其仅在某些服务器启动时才会重定向到某些服务器(例如端口 8011-8014)? In that case I can modify the main python threads and then gracefully shut down port 8011-8014.在这种情况下,我可以修改主 python 线程,然后正常关闭端口 8011-8014。 But is this type of configuration feasible ?但这种配置可行吗?

When updating your python code you can start a new set of python processes on different ports (say 8001-8004 for the previous set and 8011-8014 for the new set) then modify you nginx config to redirect to 8011-8014 instead 8001-8004 and run service nginx reload (or equivalent for your OS).更新您的python代码时,您可以在不同的端口上启动一组新的python进程(例如8001-8004用于前一组,8011-8014用于新组)然后修改nginx配置以重定向到8011-8014而不是8001-8004并运行service nginx reload (或等效于您的操作系统)。

This way, nginx will redirect new requests to the new processes without dropping any request and finishing pending ones on the previous processes.这样,nginx 会将新请求重定向到新进程,而不会丢弃任何请求并完成先前进程的待处理请求。 When you know that all pending requests to the old set of python processes are finished (that might be non trivial) you can stop them.当您知道对旧的 Python 进程集的所有待处理请求都已完成(这可能很重要)时,您可以停止它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM