WebService issue - first call is very slow | The ASP.NET Forums
ASP.NET Forums/General ASP.NET/ASP.NET Web Pages/WebService issue - first call is very slow
WebService issue - first call is very slowRSS
Last post Mar 06, 2017 04:09 AM by Chris Zhao
WebService issue - first call is very slow
Mar 03, 2017 04:09 PM|asanders2552|LINK
Hello. We have a touch screen application that displays events and pictures sent to the app by Web services. There is one particular web service that I have an issue with. It pulls data from the table in SQL for 1 event that user choses on the screen. This particular table has lots of images, around 300 rows, with up to 5 images per row (each image is stored in a different column). Even if I open the table directly in SQL, it takes 18 seconds to load the table with 300 rows. We are working on optimizing images, but not sure how much faster it would be once we are done. Back to the touch screen app. The first call of the web service takes around 25 seconds, I do cache it and all other calls take 2-5 seconds. I tried to set to call the web service at 5 am, pulling the images for the next event, but it didn't solve anything. Still the first call takes 25 seconds. Is there any other way to call the web service in advance, early in the morning? Even that I would always need only 1 event at a time (filter by ID in the service), it seems the first call still takes long time and looks through the whole table. I would not know which event would user press on. Below there is a code for calling the web service
public static List<ActivitiesListViewModel> GetImageOneEvent(bool dontUseCache = false)             {                 JavaScriptSerializer ser = new JavaScriptSerializer();                 ser.MaxJsonLength = Int32.MaxValue;                 MasterListService.MasterLists ms = new MasterListService.MasterLists();                 ms.UseDefaultCredentials = true;
string fileCache = CacheFolder + "image.json";                 List<MasterListService.ActivitiesListViewModel> ImageInfo = null;                                if (HttpRuntime.Cache["imageOneEvent"] != null && !dontUseCache)                 {                     ImageInfo = HttpRuntime.Cache.Get("imageOneEvent") as List<ActivitiesListViewModel>;                 }                 else if (File.Exists(fileCache) && !dontUseCache)                 {
try                     {                         ImageInfo = new JavaScriptSerializer().Deserialize<List<ActivitiesListViewModel>>(File.ReadAllText(fileCache));                     }                     catch (Exception)                     {                                           }                 }                 if ((ImageInfo == null) || (HttpRuntime.Cache["Act_ID_keep"] != HttpRuntime.Cache["Act_ID"]) || HttpRuntime.Cache["imageOneEvent"] == null)                 {                     ImageInfo = ms.GetImagesOneActivity(Convert.ToInt32(HttpRuntime.Cache["Act_ID"])).ToList();                     HttpRuntime.Cache["Act_ID_keep"] = HttpRuntime.Cache["Act_ID"];                     if (ExpCacheImg == null)                     {                         ExpCacheImg = TimeSpan.FromHours(16);                     }                     HttpRuntime.Cache.Insert("imageOneEvent", ImageInfo, null, System.Web.Caching.Cache.NoAbsoluteExpiration, ExpCacheImg);
File.WriteAllText(fileCache, ser.Serialize(ImageInfo));
}                 return ImageInfo;             }
Re: WebService issue - first call is very slow
Mar 03, 2017 04:59 PM|HostingASPNet|LINK
You could check if the application pools expired, if so then increase the application pool time out. You could create a Windows service or Powershell script in task scheduler which to execute at particular time.
Mar 03, 2017 05:00 PM|asanders2552|LINK
Thanks. We already adjusted all IIS settings as recommended... Can you please point me in the right direction about creating a windows service? Thank you!
Mar 06, 2017 04:09 AM|Chris Zhao|LINK
Can you please point me in the right direction about creating a windows service?
The following articles demonstrate how to create a simple Windows Service application.
WebService issue - first call is very slow | The ASP.NET Forums
ASP.NET Forums/General ASP.NET/ASP.NET Web Pages/WebService issue - first call is very slow
WebService issue - first call is very slowRSS
Last post Mar 06, 2017 04:09 AM by Chris Zhao
WebService issue - first call is very slow
Mar 03, 2017 04:09 PM|asanders2552|LINK
Hello. We have a touch screen application that displays events and pictures sent to the app by Web services. There is one particular web service that I have an issue with. It pulls data from the table in SQL for 1 event that user choses on the screen. This particular table has lots of images, around 300 rows, with up to 5 images per row (each image is stored in a different column). Even if I open the table directly in SQL, it takes 18 seconds to load the table with 300 rows. We are working on optimizing images, but not sure how much faster it would be once we are done. Back to the touch screen app. The first call of the web service takes around 25 seconds, I do cache it and all other calls take 2-5 seconds. I tried to set to call the web service at 5 am, pulling the images for the next event, but it didn't solve anything. Still the first call takes 25 seconds. Is there any other way to call the web service in advance, early in the morning? Even that I would always need only 1 event at a time (filter by ID in the service), it seems the first call still takes long time and looks through the whole table. I would not know which event would user press on. Below there is a code for calling the web service
public static List<ActivitiesListViewModel> GetImageOneEvent(bool dontUseCache = false)             {                 JavaScriptSerializer ser = new JavaScriptSerializer();                 ser.MaxJsonLength = Int32.MaxValue;                 MasterListService.MasterLists ms = new MasterListService.MasterLists();                 ms.UseDefaultCredentials = true;
string fileCache = CacheFolder + "image.json";                 List<MasterListService.ActivitiesListViewModel> ImageInfo = null;                           
     if (HttpRuntime.Cache["imageOneEvent"] != null && !dontUseCache)                 {                     ImageInfo = HttpRuntime.Cache.Get("imageOneEvent") as List<ActivitiesListViewModel>;                 }                 else if (File.Exists(fileCache) && !dontUseCache)                 {
try                     {                         ImageInfo = new JavaScriptSerializer().Deserialize<List<ActivitiesListViewModel>>(File.ReadAllText(fileCache));                     }                     catch (Exception)                     {                                           }                 }                 if ((ImageInfo == null) || (HttpRuntime.Cache["Act_ID_keep"] != HttpRuntime.Cache["Act_ID"]) || HttpRuntime.Cache["imageOneEvent"] == null)                 {                     ImageInfo = ms.GetImagesOneActivity(Convert.ToInt32(HttpRuntime.Cache["Act_ID"])).ToList();                     HttpRuntime.Cache["Act_ID_keep"] = HttpRuntime.Cache["Act_ID"];                     if (ExpCacheImg == null)                     {                         ExpCacheImg = TimeSpan.FromHours(16);                     }                     HttpRuntime.Cache.Insert("imageOneEvent", ImageInfo, null, System.Web.Caching.Cache.NoAbsoluteExpiration, ExpCacheImg);
File.WriteAllText(fileCache, ser.Serialize(ImageInfo));
}                 return ImageInfo;             }
Re: WebService issue - first call is very slow
Mar 03, 2017 04:59 PM|HostingASPNet|LINK
You could check if the application pools expired, if so then increase the application pool time out. You could create a Windows service or Powershell script in task scheduler which to execute at particular time.
Mar 03, 2017 05:00 PM|asanders2552|LINK
Thanks. We already adjusted all IIS settings as recommended... Can you please point me in the right direction about creating a windows service? Thank you!
Mar 06, 2017 04:09 AM|Chris Zhao|LINK
Can you please point me in the right direction about creating a windows service?
The following articles demonstrate how to create a simple Windows Service application.