jQuery autocomplete - 缓慢服务器vs本地

问题描述:

根据标题我只面临一次部署的性能问题。它是一个ASP.NET MVC5站点,并部署在Azure上。我们正在讲话vs几秒钟:/jQuery autocomplete - 缓慢服务器vs本地

我可以准备一个视频或任何有助于解决此问题的内容。 没有JS错误黯然抛出:/

这里是展示它完美地本地Working

带电作业的图像,它最终显示7/8秒后如..如果不是很长。 代码传入...

$(document).ready(function() { 
 

 
      $("#SerialSearch").autocomplete({ 
 
       autoFocus: true, 
 
       //delay: 0, 
 
       minLength: 2, // minimum length to trigger suggestions 
 
       select: function(e, ui) { // define select handler 
 

 
        //alert(ui.item.value); 
 
        //hitting enter key on selected item works, mouse clicking after 609 on V609xxx will submit 609 sadly 
 
        //With this I override the problem 
 
        $('#SerialSearch').val(ui.item.value); 
 
        //alert('here'); 
 
        $(this).parents('form').submit(); 
 
       }, 
 

 
       source: function (request, response) { 
 
        @*var modelDataJSON = '@Html.Raw(Json.Encode(Model))';*@ 
 
        var check = @Html.Raw(val); 
 
        //var modelDataJSON = JSON.stringify(check); 
 
        $.ajax({ 
 
         url: "/Devices/DeviceSearch", 
 
         type: "POST", 
 
         dataType: "json", 
 
         data: { Prefix: request.term, model: check }, 
 
         success: function (data) { 
 
          //alert('success'); 
 
          response($.map(data, function (item) { 
 
           return { label: item.SerialNumber, value: item.SerialNumber }; 
 
          })) 
 

 
         } 
 
        }) 
 
       } 
 
       //messages: { 
 
       // noResults: "", results: "" 
 
       //} 
 
      }); 
 
     })

CSHTML:

@{ 
 
    ViewBag.Title = "Devices"; 
 
    Layout = "~/Views/Shared/_Layout.cshtml"; 
 
    //var val = Json.Encode(Model); 
 
    //Using viewdata to load in mem entire device list 
 
    var val = Json.Encode(@ViewData["FullDeviceList"]); 
 
} 
 

 
@using (Html.BeginForm(FormMethod.Get)) 
 
{ 
 
    @Html.AntiForgeryToken() 
 
    <div class="form-horizontal"> 
 
    <hr /> 
 
    <div class="form-group"> 
 
     <div class="col-md-12"> 
 
     @Html.EditorFor(model => model.SerialSearch, new { htmlAttributes = new { @class = "form-control" } }) 
 

 
     </div> 
 
    </div> 
 
    </div> 
 
}

+0

请给我们一个[最小,完整和可验证的例子](http://stackoverflow.com/help/mcve) – Liam

+0

你的问题是什么? – JohnH

+0

哇,你们快速:)来吧 – David

做的是确定问题的根源的第一件事。 我假设你有一个服务器端的自动完成控制源,并通过Ajax调用获取数据。在本地(开发站点?),Ajax调用的延迟将是最小的。在Azure上,由于主机是远程的,我预计延迟会增加。 (当然,不知道你的实现,这只是猜测)

+0

是的,星期一需要更多的调试。只是想着它的东西很傻,因为它们是同一个DB。 Web应用程序的本地实例,但无论本地还是远程,都可以使用azure数据库。 – David

+0

要添加到这一点,林存储页面加载设备 - 查看数据vs击中数据库每个按键, – David

+0

您可以使用Glimpse来查明问题。 (使用指南,包括天蓝色,在这里:[链接](https://www.asp.net/mvc/overview/performance/profile-and-debug-your-aspnet-mvc-app-with-glimpse#da)) –