Monday, June 19, 2017

Scheduled web jobs using CRON

On Internet We can find plenty of articles around how to create scheduled Web Jobs. I followed Microsoft's Documentation and added Web job to an existing web application. When I published the web app from Visual Studio a folder got created in to the App_Data folder of the web app, a scheduler job collection got created in Azure and web job schedule for the job. It worked fine for some time.
But recently I faced some issue with publishing web job from Visual studio and the error was like this "Microsoft.Web.WebJobs.Publish.1.0.12\tools\webjobs.console.targets(110,5): Error : An error occurred while creating the WebJob schedule". I did lot of searching on internet but couldn't find any solution and raised a ticket with Microsoft support. Microsoft suggested to Use CRON expression for scheduling the job instead for scheduler job collection. This approach really very helpful and since then We haven't faced any issues related to schedule and publishing of the web app.
I found the CRON expression better. Hope this will help.

Average response time high in Azure Web app

We have configured some alerts for our Azure Web app. One of them triggers when the average response time of the application is higher than the configured threshold value for certain duration. For eg:- "Average Server response time is xx.xx seconds: crossed threshold for 5 minutes".
We were trying to dig out the reason for this alert found no exceptions in the the application, CPU usage and Memory usage were also normal. It wasn't getting easy to reach out to the actual root cause for the CPU usage.
Later on with the help of Microsoft support We come to know that there is an activity called "Storage volume switch" which was causing the slow responses for the application.
Two recommendations were provided to us:-
  1. Switch of always on setting on the staging deployment slot of web app. This can be found in application settings section of your web app on azure portal
  2. Use local cache on the web app
Thanks

ADFS on Azure VM

In one of my application I was using ADFS as an Identity Provider for my application. My application was hosted on Azure. I wanted to set up ADFS on IAAS(Infrastructure as a service) offering. I was doing this set up for the first time and I found an article on google which helped me to set up ADFS on Azure.
While this set up at one step we need to specify the path for log files. for development purpose it is fine to give path to some local drive but suggest way is to attach a data disk to azure VM. I was using windows VM and here is the link which  clearly explains how to attach a data disk to azure VM
I added my application as a relying party in to ADFS. Here is how to create relying party trust in ADFS

Sitecore Device Detection

I was observing for my Sitecore CDE application “discovery-ces.cloud.sitecore.net” dependency was always failing.
Digging it out I found it is related to device detection.Below are some uses of Device detection:-
  1. Device detection can be used to personalize content on the basis of device type.
  2. Can be used for using different layouts for different devices.
  3. Sitecore analytics also start showing the device data if this feature is enabled.
Device detection is a paid service and available in Sitecore app center which We can browse through control panel on our Sitecore instance. Click Here for the details for setting up device detection.
By default this call happens every 10 minutes to download and update the device database. We were not using Device detection so “discovery-ces.cloud.sitecore.net” was getting tracked as a failed dependency call.
So We thought of disabling it. Click here to check how disable device detection.

Finding Most Visited Pages of your Sitecore site

We were looking for a solution where We were supposed to show highly visited news article pages of our site. This application was created with the help of Sitecore CMS. We thought of using Sitecore analytics for the solution.
In Sitecore 8.1 all the interactions done by a user on the site are firstly collected in mongo database as visit data. On the session end event, mongo data is processed and stored in to Sitecore analytics database. All the reporting data shown in the Experince Analytics section of Sitecore is pulled from this database.
Back to original problem, We pulled out the visit data from mongo database for 3o days and then filtered this to get our desired result. Click Here to check one of the ways to pull out the visit data. Now the problem which We faced with this approach was data being captured in mongo database was very large for 30 days which was causing the high CPU usage for our application.
Above problem made us think about another way to find the highly visited new articles. We thought of pulling the data from Sitecore analytics database as it already processed  and has lesser data as compare to mongo collection. The simplest query which we used to pull the data from Sitecore analytics database is
SELECT TOP 3
      [ItemId],
      sum(Views)
  FROM [YourSitecore_reporting].[dbo].[Fact_PageViews]
  group by ItemId
 
Thanks

Web performance optimizations for Images

  • JPEGs are the most popular file format online and is commonly used for product images, photographs, and homepage hero banners/images. These can be used where transparency is not required while PNGs are many times used for logos because they are high quality, and can handle transparency. JPEG is best for images, PNG for the layout and GIF for icons.
  • Dimensions should be enough to be viewable in the browser (and avoid scrolling)
  • High resolution images should not be bigger than 1.5 - 2MB. making it this big is like bigger than the webpage contents itself.
  • For full-width slideshows (that automatically stretch to the full size of the browser), Go for 2560 pixels in width, which is the common resolution width for 27″ and 30″ monitors. Images can have any height you need, to create an aspect ratio you’re comfortable with. For example, for full-page slideshows keep the original aspect ratio of images. But for smaller slideshows at the top of a homepage, try to keep the images shorter (to an aspect ratio of around 3:1 or more).
  • Whenever an image needs to enlarge on screen (like in a lightbox display after clicking on a thumbnail, possibly part of a gallery slideshow), keep them to a max of 1500 pixels in width (and a max height of around 800-900 pixels), that’s usually acceptable. Restricting the image dimensions like this will keep the file size reasonably small, for a faster transition between images (if the slideshow allows navigating between images)
  • Assuming you’re using a tool like Adobe Lightroom or Adobe Photoshop, you almost never need to export images at 100 (in the quality). Choosing something like 60 or 70 gives you good-enough quality at much smaller file sizes. Only when you start to go lower than 50-60% do you start getting discernible image noise. But between 100 and 70-80, the quality difference is imperceptible, while the difference in file size is huge.
  • For example, my content area is 690 pixels wide.  There is no need for me to size my photos any larger than 690 pixels, since the content area will only display up to 690 pixels.  An image of 800 pixels will automatically be shrunk when shown on screen.
  • PPI and DPI are not relevant to web displays.  So PPI (pixels per inch) and DPI (dots per inch) are not relevant when editing your photos for your site, even though they may be available as options in your software.  Images at different PPIs, has no difference in picture quality!
  • PPI and DPI are not relevant to web displays, but they are important when creating printables.  Images that are meant to be downloaded and printed should be created at 300 PPI.

Sitecore Performance Optimization

1         IIS:-

  1. Ensure that Maximum Worker Processes for the Application Pool is set to 1 (under advanced settings)
  2. Ensure that Load User Profile settings of the Application Pool is set to "true" (under advanced settings)
  3. Ensure anonymous access is denied for folders /App_Config, /sitecore/admin, /sitecore/debug, /sitecore/shell/webservice.
  4. Enable HTTP keep alive
  5. Enable static content compression
  6. On the CMS server, enable dynamic content compression
  7. Disable execute permissions on the upload folder
  8. Enable content expiration using HTTP response headers, especially for the /sitecore folder (optional). Sitecore recommends that the Expire Web content be enabled, Set to "After" 30 days.

 

2         Sitecore Configurations:-

  1. Check if the History, PublishQueue, and EventQueue Cleanup Tasks are configured. Schedulingfrequency = 00:05:00 (5 minutes),                               Sitecore.Tasks.CleanupHistory interval = 04:00:00 (4 hours) Sitecore.Tasks.CleanupPublishQueue interval = 04:00:00 (4 hours)  Sitecore.Tasks.CleanupEventQueue interval = 04:00:00 (4 hours)
  2. Include the path to static media files (header images, CSS files, JavaScript files) in the IgnoreURLPrefixes settings in sitecore config to prevent Sitecore from intercepting the requests.
  3. Disable counters. Counters.Enabled setting should be false in sitecore config.
  4. Enabled should be false in sitecore config.
  5. Restrict access to .XML, .XSLT and .MRT files using the <system.webServer><handlers> section.
  6. Disable the UploadWatcher.
  7. Disable client RSS feeds by removing the Sitecore.Shell.Feeds.FeedRequestHandler.
  8. EnableBucketDebug should be false in sitecore.config.

3         Database:-

  1. Make sure that the Compatibility level is set for the version of SQL Server that you have installed. Values can be 110,100,90
  2. Auto Close Property Set To False
  3. Auto Shrink Property Set To False
  4. Recovery Model Set to Simple
  5. Defragment indexes
  6. Clean up History, EventQueue and PublishQueue tables.

4         Sitecore Content Tree:-

  1. Check Long Running Validation Rules. Set log level to info and then use Sitecore log analyzer to see the long running
  2. Number of versions for the item should be less than 10.
  3. Number of items under a folder should be less than 100.