2014-06-18 5 views
0

현재 데이터베이스에서 데이터를 가져 와서 내보기의 테이블에 표시해야하는 프로젝트에서 작업 중입니다. 나는이 모든 작업을했지만 페이지를로드하는 데 약 10-15 초가 걸립니다. 가능하다면이 시간을 줄이고 싶습니다.어떻게하면 asp.net mvc 응용 프로그램의 속도를 높일 수 있을까요?

나는 데이터베이스에서 정보를 얻는 것이 문제라고 생각한다. 데이터베이스에서 가져온 항목이 많아서 가능한 한 더 좋은 방법이라고 생각합니다.

컨트롤러 :

public class HomeController : Controller 
{ 
    private RestoreDBEntities db = new RestoreDBEntities(); 

    public ActionResult Index() 
    { 
     W6ViewModel viewModel = new W6ViewModel(); 
     viewModel.engineers = db.W6ENGINEERS.OrderBy(w => w.Name).Include(w => w.W6CALENDARS).ToList(); 
     viewModel.tasks = db.W6TASKS.ToList(); 

     return View(viewModel); 
    } 

    public ActionResult Details(int? id) 
    { 
     if (id == null) 
     { 
      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 
     W6ENGINEERS w6ENGINEERS = db.W6ENGINEERS.Find(id); 
     if (w6ENGINEERS == null) 
     { 
      return HttpNotFound(); 
     } 
     return View(w6ENGINEERS); 
    } 

    [HttpPost] 
    public ActionResult Filter(FormCollection collection) 
    { 
     string city = collection["city"]; 

     W6ViewModel viewModel = new W6ViewModel(); 
     viewModel.engineers = db.W6ENGINEERS.Where(w => w.City == city).Include(w => w.W6CALENDARS).ToList(); 
     viewModel.tasks = db.W6TASKS.Where(w => w.City == city).Include(w => w.W6CALENDARS).ToList(); 

     return View("Index", viewModel); 
    } 

보기 :

@model WebApplication1.ViewModel.W6ViewModel 

@{ 
    ViewBag.Title = "Dispatcher"; 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
} 


<section id="fields"> 
    <h3 id="field_filter"><strong>Filters</strong></h3> 
    <h3 id="field_engineer"><strong>Engineers</strong></h3> 
    <h3 id="field_task"><strong>Tasks</strong></h3> 
</section> 

<section id="filters"> 
    @using (Html.BeginForm("Filter", "Home", FormMethod.Post)) 
    { 
     <input name="city" id="city" type="text" maxlength="15" title="City" value ="City" style="color:#888;" 
     onfocus ="inputFocus(this)" onblur="inputBlur(this)" /> 
     <input id="submit" type="submit" value="Submit" />`enter code here` 
    } 
</section> 

<section id="engineers"> 
    <table class="table-condensed table-striped"> 
     <tr> 
      <th> 
       Name 
      </th> 
      <th> 
       Phone number 
      </th> 
     <th> 
      City 
     </th> 
     <th> 
      Region 
     </th> 
     <th> 
      Availability Factor 
     </th> 
    </tr> 

     @foreach (var item in Model.engineers) 
     { 
      <tr> 
       <td> 
        @Html.ActionLink(item.Name, "Details", new { id = item.W6Key }) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.MobilePhone) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.City) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.Region) 
       </td> 
       <td> 
        @Html.DisplayFor(modelItem => item.AvailabilityFactor) 
       </td> 
      </tr> 
     } 
    </table> 
</section> 

<section id="work"> 
    <table class="table-condensed table-striped"> 
     <tr> 
      <th> 
       Job ID 
      </th> 
      <th> 
       Skills 
      </th> 
      <th> 
       Address 
      </th> 
     </tr> 

    @foreach(var item in Model.tasks) 
    { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.City) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.IsScheduled) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.IsPartsNotUsed) 
      </td> 
     </tr> 
    } 
</table> 

Webconfig : 많은 사전에

<?xml version="1.0" encoding="utf-8"?> 

<configuration> 
<configSections> 
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 
    </configSections> 
    <connectionStrings> 
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WebApplication1-20140611092404.mdf;Initial Catalog=aspnet-WebApplication1-20140611092404;Integrated Security=True" providerName="System.Data.SqlClient" /> 
    <add name="RestoreDBEntities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=T520-R9K0H1K\SQLEXPRESS;initial catalog=RestoreDB;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 
    </connectionStrings> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="None" /> 
    <compilation debug="true" targetFramework="4.5.1" /> 
    <httpRuntime targetFramework="4.5.1" /> 
    </system.web> 

    <system.webServer> 
    <urlCompression doDynamicCompression="true" doStaticCompression="true" dynamicCompressionBeforeCache="true"/> 
    </system.webServer> 

    <system.webServer> 
    <modules> 
     <remove name="FormsAuthenticationModule" /> 
    </modules> 
    </system.webServer> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /> 
     </dependentAssembly> 
     <dependentAssembly> 
     <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /> 
     <bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
    <entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 
    <providers> 
     <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> 
    </providers> 
    </entityFramework> 
</configuration> 

감사합니다!

편집 :

내가 DotTrace과 경험이 없지만 너무 DotTrace를 설치하고 내 프로젝트를 진단하는 데 사용 후에는, 그것은 (내 의견을 긴 로딩 시간을 일으키는 데이터베이스에 내 전화 것 같다)

누구나 확인할 수있는 해결책을 제안 할 수 있다면 스크린 샷을 추가했습니다. 당신이 할 수있는

DotTrace Snapshot upon running the project

+0

유효한 답을 얻기에는이 질문에 정보가 충분하지 않습니다. 먼저 식별해야 할 점은 느린 점이 어디에 있는지입니다. 그것은 당신의 데이터 접근인가, 쿼리가 느린가, 또는 당신은 1M 레코드를 반환하고 그 다음 렌더링은 느린가 ...? 슬로우 포인트가 실제로 클라이언트 측에서 매우 느린 javascript를 사용하고 있습니까? – Paddy

+0

죄송 합니다만 정보가 부족합니다. 문제가있는 곳을 확실히 알 수는 없습니다. 데이터베이스에서 많은 정보를 얻고 있다는 사실을 알고 있습니다. 성능이 향상 될 수 있다고 생각합니다. 나는 그것이 클라이언트 측에 있다고 생각하지 않는다. –

+1

DotTrace 또는 ANTS Profiler와 같은 프로파일 러를 실행하여 느린 부분이 어디에 있는지 확인하십시오. SQL Server Profiler를 실행하여 어떤 쿼리를 실행하고 얼마나 오래 걸릴지 알아 봅니다. 성능 문제의 정확한 원인을 알게되면 문제 해결을 시작할 수 있습니다. –

답변

0

한 가지, 캐시하여 출력됩니다. 그러면 후속 요청에서 시간이 절약됩니다. 캐싱 할 작업 방법에 상관없이 출력 캐시 속성을 사용할 수 있습니다.

[OutputCache(Duration = 3600, Location = System.Web.UI.OutputCacheLocation.ServerAndClient)] 

지속 시간은 출력을 초 단위로 캐시하려는 기간이며, 캐시하려는 위치는 obv입니다.

또한 SqlCacheDependency를 사용하여 데이터가 업데이트 될 때까지 요청을 캐시 할 수 있습니다. SQL 의존성과 함께 출력 캐시 속성을 사용하는 것이 아마도 문제에 더 적합 할 것입니다. 다음은 msdn-http://msdn.microsoft.com/en-us/library/e3w8402y(v=vs.140).aspx에서 수행하는 방법에 대한 연습입니다.

또한 mvc 응용 프로그램의 속도를 높일 수있는 다른 것들이 있습니다. 내가 할 수있는 일에 대해 간단한 글을 올렸습니다. 여기에서 확인하십시오 - http://www.paulsodimu.co.uk/Post/How-to-speed-up-your-MVC-web-application