处理Web服务超时,同时执行长时间运行的数据库任务 [英] Handling Web Service Timeouts While Performing Long-Running Database Tasks

查看:170
本文介绍了处理Web服务超时,同时执行长时间运行的数据库任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的产品之一的体系结构是一个典型的3层解决方案:

The architecture of one of our products is a typical 3-tier solution:


  • C#客户端

  • WCF Web服务

  • SQL Server数据库

客户机请求来自web服务的信息。 Web服务访问数据库的信息,并将其返回给客户机。

The client requests information from the web service. The web service hits the database for the information and returns it to the client.

下面就是问题所在。其中一些查询可能需要很长很长的时间,而我们不知道的前期哪些将是缓慢的。我们知道一些往往比别人慢,但即使是最简单的要求可能会很慢给予足够的数据。有时会使用大量数据的查询或运行报告。该查询只能到目前为止的数据量巨大减慢下来之前进行了优化。

Here's the problem. Some of these queries can take a long, long time, and we don't know up-front which ones will be slow. We know some that are often slower than others, but even the simplest requests can be slow given enough data. Sometimes uses query or run reports on large amounts of data. The queries can be optimized only so far before the sheer volume of data slows them down.

如果在数据库中查询点击在SQL服务器的最大查询超时,数据库查询终止,以及Web服务返回一个错误给客户端。这是可理解的。我们可以处理这些错误。

If a query in the database hits the maximum query timeout in SQL server, the database query terminates, and the web service returns an error to the client. This is understood. We can handle these errors.

客户正在等待Web服务调用来完成。如果数据库调用需要很长的时间,客户端可能会超时它调用Web服务。客户端放弃,但数据库请求继续处理。在这点上,客户端是外的同步与数据库。数据库调用可能会或可能不会成功。有可能已被错误。客户端将永远不会知道。在某些情况下,我们不希望我们的用户发起,可能会导致给出的previous请求完成无效状态另一个请求。

The client is waiting for the web service call to complete. If the database call takes a long time, the client may timeout on its call to the web service. The client gives up, but the database request continues processing. At this point, the client is out-of-synch with the database. The database call may or may not succeed. There may have been an error. The client will never know. In some cases, we don't want our users initiating another request that may result in an invalid state given the completion of the previous request.

我很好奇,看看其他人如何处理这个问题。你从影响数据库调用使用prevent Web服务超时什么策略?

I'm curious to see how others have handled this problem. What strategies have you used to prevent web service timeouts from affecting database calls?

我可以想出涉及制作somewhere-- Web服务,附加到消息中queue--东西一个实际的数据库层的最好的想法。卸载每一个查询到另一个进程似乎过高。 (话又说回来,我们并不总是知道如果给定的请求将有快有慢。)

The best ideas I can come up with involve making an actual database layer somewhere-- inside the web service, attached to a message queue-- something. Offloading every single query to another process seems excessive. (Then again, we don't always know if a given request will be fast or slow.)

这将是巨大的,如果我们能够分开实现从启动和运行一个数据库进程的行为的HTTP请求的行为。我已经看到了这个用在previous公司定制的服务器完成,但它使用直插座的沟通,我宁愿避免与一些自定义应用程序取代了Web服务。

It would be great if we could separate the act of making an HTTP request from the act of initiating and running a database process. I've seen this done with a custom server at a previous company, but it was using straight socket communication, and I'd rather avoid replacing the web service with some custom application.

请注意,鉴于我们处理的数据量,我们都是在查询优化。查询优化,索引等,只需要你到目前为止当数据量很大。有时候,事情就需要很长的时间。

Note that given the amount of data we deal with, we are all over query optimization. Query optimization, indexes, etc., only takes you so far when the volume of data is high. Sometimes things just take a long time.

推荐答案

一,我们使用最近是掰开庞大的数据库处理成独立的并行操作的解决方案。每个操作小得多,设计得尽可能高效。客户机启动的操作,生成一个线程数,并尽一切可能并行。

One of the solutions we've used lately is to break apart huge database processes into separate parallel operations. Each operation is much smaller and designed to be as efficient as possible. The clients initiate the operations, spawn a few threads, and do whatever they can in parallel.

例如,我们已经分崩离析一些巨大的proceses成一系列的像开始,过程1块工作,完成的步骤,并收集报告数据。工作过程的步骤可以并行运行,但他们不能启动,直到开始步骤完成。完成步骤需要等待所有的流程工作步骤来完成。

For example, we've broken apart some huge proceses into a series of steps like Start, Process 1 Chunk of Work, Finish, and Gather Report Data. The Process Work steps can run in parallel, but they can't start until the Start step completes. The Finish step needs to wait for all Process Work steps to complete.

由于客户端的控制过程中,客户可以在报告进度到底是哪一步它是在

Since the client is controlling the process, the client can report progress on exactly which step it is on.

这篇关于处理Web服务超时,同时执行长时间运行的数据库任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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