Web应用后台流程,新手设计题 [英] Web application background processes, newbie design question

查看:19
本文介绍了Web应用后台流程,新手设计题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过多年的桌面应用程序开发,我正在构建我的第一个 Web 应用程序(我正在使用 Django/Python,但也许这是一个完全通用的问题,我不确定).所以请注意 - 这可能是一个超新手的问题......

I'm building my first web application after many years of desktop application development (I'm using Django/Python but maybe this is a completely generic question, I'm not sure). So please beware - this may be an ultra-newbie question...

我的一个用户进程涉及服务器中的繁重处理(即用户输入一些内容,服务器需要大约 10 分钟来处理它).在桌面应用程序上,我会将用户输入扔到受互斥体保护的队列中,并使用该互斥体在队列上以低优先级阻塞运行专用后台线程.

One of my user processes involves heavy processing in the server (i.e. user inputs something, server needs ~10 minutes to process it). On a desktop application, what I would do it throw the user input into a queue protected by a mutex, and have a dedicated background thread running in low priority blocking on the queue using that mutex.

然而,在 Web 应用程序中,一切似乎都以与 HTTP 请求同步为导向.

However in the web application everything seems to be oriented towards synchronization with the HTTP requests.

假设我将使用数据库作为队列,运行后台进程的最佳实践架构是什么?

Assuming I will use the database as my queue, what is best practice architecture for running a background process?

推荐答案

对此(至少)有两种思想流派.

There are two schools of thought on this (at least).

  1. 将工作放到队列中,让 Web 堆栈之外的其他东西处理它.

  1. Throw the work on a queue and have something else outside your web-stack handle it.

将工作放到队列中,让您的网络堆栈中的其他东西处理它.

Throw the work on a queue and have something else in your web-stack handle it.

在任何一种情况下,您都可以在某处(例如数据库表)的队列中创建工作单元,并让某些进程来处理它们.

In either case, you create work units in a queue somewhere (e.g. a database table) and let some process take care of them.

我通常使用 1 号,我有一个专门的 Windows 服务来处理这些事情.您也可以使用 SQL 作业或类似的东西来做到这一点.

I typically work with number 1 where I have a dedicated windows service that takes care of these things. You could also do this with SQL jobs or something similar.

第 2 项的优点是您可以更轻松地将所有代码保存在一个位置——在 Web 层中.您仍然需要触发执行的东西(例如,加载处理具有足够高超时的工作单元的网页),但这可以通过各种机制轻松完成.

The advantage to item 2 is that you can more easily keep all your code in one place--in the web tier. You'd still need something that triggers the execution (e.g. loading the web page that processes work units with a sufficiently high timeout), but that could be easily accomplished with various mechanisms.

这篇关于Web应用后台流程,新手设计题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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