应用级队列/网站的流量管理 [英] Application level queueing / website traffic management

查看:201
本文介绍了应用级队列/网站的流量管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有我们预期在全年的几个点领取令人难以置信的高流量网站的应用程序。目前,我们可在繁忙期间从进来的请求数量被憋死将用户重定向到持有页面,以prevent我们的Web应用程序服务器的一些第三方的负载均衡软件。

We have a website application that we expect to receive incredibly high traffic at several points throughout the year. We currently have some third party load balancing software which redirects users to a 'holding' page during busy periods, to prevent our web application servers from being suffocated by the amount of requests coming in.

展望未来,我们希望能有在这个过程中更多的控制和实施某种形式的虚拟队列。目前的负载平衡器没有排队功能,但只允许通过的流量基于速率的限制。这是随机的,是家常便饭,当你刷新页面(或得到自动刷新)。

Going forward we would like to have more control over this process and implement a virtual queue of some kind. The current load balancer has no queuing functionality, but simply allows traffic through based on a rate limit. This is random and is pot luck on when you refresh the page (or get auto refreshed).

我已经做了一些在线阅读这个却发现关于如何实现一个非常基本的虚拟HTTP请求队列小的实现细节。当然也有公司提供这种作为一个完全成熟的服务,例如队列它并的净precept 但这些似乎矫枉过正目前的需求(和非常昂贵)。

I've done some reading online about this but found little implementation detail on how to implement a very basic virtual HTTP request queue. There are of course companies that offer this as a fully fledged service such as queue-it and Netprecept but these seem overkill for our current needs (and are very expensive).

在特定的Web应用程序是用ASP.Net MVC。记住,我们不会在此刻需要先进的功能,如队​​列优先级等进口轴承,我已经用一个静态的队列管理器类非常基本的验证的概念,使用 ConcurrentQueue< T&GT ; 等,但我想知道如果这是一个有效,可扩展的方法?这是东西,可以是主应用程序层的一部分?还是应分开存放?没有任何一个有关于如何实现这种功能到一个ASP.Net MVC应用程序的任何技术诀窍?

The web application in question is written in ASP.Net MVC. Bearing in mind that we do not need advanced features like 'queue priority' etc. at the moment, I have created a very basic proof-of-concept using a static queue manager class, using the ConcurrentQueue<T> etc. but am wondering if this is a valid, scalable approach? Is this something that can be part of the main application layer? Or should it be kept separate? Does any one have any technical know-how on how to implement this kind of feature into an ASP.Net MVC app?

修改:感谢迄今答案。大部分的答案似乎进入一个有关缓存很多细节。这已经是(非常)大量使用我们的网站上,使用ASP.Net Web缓存,缓存在负载均衡水平,对象缓存使用AppFabric的整页的请求。

EDIT: thanks for the answers so far. Most of the answers seem to go into a lot of detail about caching. This is already (very) heavily employed on our website, using ASP.Net web caching, caching full page requests at the load balancer level and object caching using AppFabric.

原因来管理队列的能力,是因为这个过程是非常数据库写重。我们切实为通过网站某些产品创建订单。这意味着这些DB交易正在服用的东西进去像最后一分钟查货等,这是性能问题出现在哪里,这是为希望实现某种类型的排队系统的原因。

The reason for the ability to manage a queue is because the process is very database-write heavy. We're effectively creating orders for a certain product via the website. This means these DB transactions are taking things into account like last-minute stock checking etc. This is where the performance issues arise, and this is the reason for wanting to implement a queuing system of some kind.

在数据库服务器上投入更多的资源并不是一个现实的选择。我真的很为这种性质(C#或其他方式)的排队系统的技术实现细节。很抱歉,如果这不是最初提出明确。

Throwing more resources at the database server is not a realistic option. I'm really looking for details of technical implementations of a queuing system of this nature (C# or otherwise). Sorry if this wasn't made clear originally.

推荐答案

您是否正在考虑以下几点同时测量的应用?性能


  1. 缓存

  2. 无会话控制器

  3. AsyncControllers

也许MVC3的最有用的功能(性能方面)输出缓存。最大的效果命中实际发生时,你的应用程序真的来获取数据,做它的计算并返回数据。输出缓存可以缓存这些结果,使他们能够直接甚至没有触及数据库返回。执行复杂的查询特别是当这可以在服务器上显著下降负载(其实你可以通过一个百日咳90%的陈昭国,官康仔细缓存在你的web应用程序拖放服务器上的负载)。

Output caching :

Perhaps the most useful feature of MVC3 (Performance-Wise) is output caching. The biggest Performance hits actually occur when your application really has to fetch data, do calculations on it and return the data. Output caching can cache these results so they can be returned directly without even touching the database. Especially when executing complex queries this can drop the load on your server significantly (in fact you could drop the load on your server by a whooping 90% by carefully inplementing caching in your web application).

namespace MvcApplication1.Controllers
{
     public class DataController : Controller
     {
          [OutputCache(Duration=10)]
          public string Index()
          {
               return DateTime.Now.ToString("T");    
          }
     }
}

无会话控制器:

与会话状态控制器禁用提供不需要会话状态控制器的优化。无状态控制器意味着,你不需要一个会话的概念的情况。

Sessionless controllers :

Controllers with session state disabled provide an optimization for controllers that do not require session state. Stateless controllers are meant for situations where you do not require the concept of a session.

默认情况下,ASP.NET管道不会处理属于同一个会话并发请求。它串行化它们,即它会将他们的顺序,它们被接收,以便它们被处理串联而非并联。这意味着,如果一个请求正在进行,并从同一个会话另一个请求到达时,它会被排队到仅开始执行时的第一个请求已完成。

让我们来看一个例子。网页制作3异步AJAX请求到服务器,与会话状态启用(也注意到必须实际使用的会话,如ASP.NET是足够聪明,不连载的要求,如果你从来没有使用会话状态,即使它启用)。

Let's look at an example; a page making 3 asynchronous AJAX requests to the server, with session state enabled(also note that session must actually be used, as ASP.NET is smart enough not to serialise requests if you never use session state, even if it's enabled).

JQuery的

$(document).ready(function () {
    //Make 3 concurrent requests to /ajaxtest/test
    for (var i = 0; i < 3; i++) {       
        $.post("/ajaxtest/test/" + i,
            function (data) {                       
                //Do something with data...
            },
            "json");
    }
});

控制器 - 操作法

public class AjaxTestController : Controller
{       
    [HttpPost]
    public JsonResult Test(int? id)
    {
        Thread.Sleep(500);
        return Json(/*Some object*/);
    }
}

您可以看到在网络配置文件序列化要求的效果;每个请求需要大约500ms的时间超过了previous之一。因此,这意味着我们没有得到来自使这些AJAX异步调用任何好处。让我们来看看配置文件再次为我们AjaxTestController禁止(使用[SessionState会]属性)的会话状态。

[SessionState(SessionStateBehavior.Disabled)]
public class AjaxTestController : Controller
{       
    //...As above
}

高得多!你可以看到3个请求并行处理,并采取了总共500毫秒内完成,而不是我们在第一个例子中看到1500毫秒。

首先,控制器开始一个或多个外部I / O调用(例如,SQL数据库调用或web服务调用)。无需等待它们完成,它会释放线程回ASP.NET辅助线程池,以便它可以处理其他请求。

First, controller begins one or more external I/O calls (e.g., SQL database calls or web service calls). Without waiting for them to complete, it releases the thread back into the ASP.NET worker thread pool so that it can deal with other requests.

后来,当所有的外部I / O调用已经完成,底层ASP.NET平台抓起从池中的另一个免费的工作线程,它重新附加到你原来的HTTP上下文,并让它完成处理原始请求。

Later, when all of the external I/O calls have completed, the underlying ASP.NET platform grabs another free worker thread from the pool, reattaches it to your original HTTP context, and lets it complete handling the original request.

<一个href=\"http://blog.stevensanderson.com/2010/01/25/measuring-the-performance-of-asynchronous-controllers/\">I下面复制的内容从这个链接。因为某个环节被打破,所以我在这里保存了一些重要的组成部分。请检查此链接查看更多细节

要了解如何控制器的异步应对不同的流量水平,以及如何比较一个简单的同步控制器,你可以把创建示例MVC有两个控制器。为了模拟一个长期运行的外部,他们都执行一个SQL查询,需要2秒就可以完成(使用SQL命令WAITFOR DELAY '00:00:02'),然后他们将返回相同的固定文本浏览器。其中一人做它同步方式;其他异步。

在另一个例子中,你可以检查模拟交通繁忙创下了给定的URL一个简单的C#控制台应用程序。它简单地反复请求相同的URL,在计算的最后几响应时间的滚动平均值。首先它这样上只有一个线程,但随后逐渐在30分钟时间内并发线程的数量增加至150。如果您想尝试运行针对您自己的网站这个工具,你可以下载C#源$ C ​​$ C。

In another example you can check a simple C# console application that simulates heavy traffic hitting a given URL. It simply requests the same URL over and over, calculating the rolling average of the last few response times. First it does so on just one thread, but then gradually increases the number of concurrent threads to 150 over a 30-minute period. If you want to try running this tool against your own site, you can download the C# source code.

的结果说明有关异步请求如何执行的点数。检查出的平均响应时间与并发请求数这个图(下响应时间越好):

The results illustrate a number of points about how asynchronous requests perform. Check out this graph of average response times versus number of concurrent requests (lower response times are better):

要理解这一点,首先我要告诉你,我已经把我的ASP.NET MVC应用程序的工作线程池的50工作线程人为压低最大限制。我的服务器实际上有200个默认的最大线程池大小 -​​ 一个更明智的极限 - 但结果更清楚,如果我酌减。
正如你所看到的,同步和异步请求,只要有足够的工作线程去各地演出如出一辙。而你们为什么不?
但是,一旦线程池被耗尽(> 50个客户端),同步请求必须形成被服务的队列。基本排队理论告诉我们,平均花费的时间在排队是由下式给出:

结果

而这正是我们在图中看到的。排队时间与队列的长度呈线性增长。 (道歉我用一个公式放纵 - 有时我只是不能燮preSS我内心的数学家,我会,如果它成为一个问题得到治疗。)
异步请求并不需要启动这么快就排队,虽然。它们并不需要阻止工作线程在等待,所以线程池限制不是一个问题。那么为什么他们开始的时候有100多家客户排队?这是因为ADO.NET连接池默认情况下,仅限于100个并发连接。

希望这会帮助你。

这篇关于应用级队列/网站的流量管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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