简体   繁体   English

从SQL数据库缓慢加载某些数据

[英]Slow loading of certain data from SQL database

We have a website that is taking a long time to download certain data on 4G network. 我们有一个网站需要很长时间才能在4G网络上下载某些数据。 It is able to load a large list of customers and all of their details very quickly from the database. 它能够从数据库中快速加载大量客户及其所有详细信息。 But loading only a few details on a customer's last activity from another table in the database is taking a very long time (5-6 seconds to load only 6 database fields). 但是,从数据库中的另一个表仅加载客户的上一个活动的一些详细信息会花费很长时间(5-6秒仅加载6个数据库字段)。

A sample SQL Query: SQL查询示例:

SELECT TOP(1) EventID,  StartOnDate, Description, Fullname,  ForeColor, BackColor,  WhatHappened
FROM qryCustomerHistory WHERE CustomerID=610376 AND StartOnDate < '2/21/2014' 
ORDER BY StartOnDate DESC

Our site is a .net 4.5 website displaying the data in a boostrap modal popup window. 我们的站点是一个.net 4.5网站,在boostrap模态弹出窗口中显示数据。 The database is Microsoft SQL Server 2012. Both the website and database are on the same Virtual Machine hosted on Windows Azure. 数据库是Microsoft SQL Server2012。网站和数据库都位于Windows Azure上托管的同一虚拟机上。

It would be hard to guess what's the root cause. 很难猜测出根本原因是什么。

Maybe you're table contains lots of data and if so, you need a composite index containing CustomerID and StartOnDate to speed up the table scan. 也许您的表包含大量数据,如果这样,则需要一个包含CustomerIDStartOnDate的复合索引以加快表扫描的速度。

Also whatever comes in Order by clause generally needs an index. 同样, Order by子句中出现的所有内容通常都需要索引。

You must trace the request both on client side and server side to be sure what's the problem. 您必须在客户端和服务器端都跟踪请求,以确保出了什么问题。

You can user Developer Tools of almost any recent browser to trace the request on client side (checkout firebug network monitoring ). 您可以使用几乎所有最新浏览器的开发人员工具在客户端上跟踪请求(检出Firebug网络监视 )。

For the server side, user profiling tools or debug level logging of a logging framework like NLog or Log4net. 对于服务器端,用户配置文件工具或NLog或Log4net等日志记录框架的调试级别日志记录。

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

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