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

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

问题描述

我经过多年的桌面应用程序开发(我使用Django / Python的,但也许这是一个完全通用的问题,我不知道)的建设我的第一个Web应用程序。所以,请小心 - 这可能是一个超新手的问题...

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. 扔在队列中的工作,让您的网络堆栈之外别的东西处理它。

  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号工作,在那里我有一个专门的窗口服务,它利用这些东西照顾。你也可以做到这一点与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项的好处是,你可以更容易地保留所有的code在一个地方 - 在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天全站免登陆