Slow Azure websites with Redis

During a load test of an Azure website, we noticed that the site started to become unresponsive when 10 concurrent users we loaded.

Session management has been utilized through a Redis cache. For anyone looking to use this I would recommend here as a good starting point.

Deploying the site locally using the live web.config transforms, we were able to run the following in the command line, to show all connections that were being made from the computer.

netstat -b

It was noticed that there were over 100 concurrent connections being made to the cache which stopped the site from being able to connect to the azure portal.

redisconnections_connectionerror

The azure portal had displayed the following recommendations to fix the portal

redisconnections_warnings

 

This was due to the concurrent connections being maxed out a 256 connections.

redisconnections_256

What was the culprit? Creating a new connection every time the class was instantiated.

It is recommend in the by MSDN to create a static instance of the connection that is shared across the application. This can either be achieved by using a singleton pattern, using dependency injection or by using the below code.

private static Lazy _redisConnection = new Lazy(() => 
ConnectionMultiplexer.Connect(<>));

This then happened.

redisconnections_10

 

Azure search – Scoring profiles

A scoring profile allows Azure search to target and favor a combination of columns when searching for content.

Searching without a scoring profile lets Azure search calculate a score based on what it thinks the best match is. This produces a score against the search result and tells your what the most relevant item is.

To create a scoring profile, first log into the Azure portal and find the Azure search block and select the index of choice.

The opening blade will show you all of the properties of the index, including all of the scoring profiles. This is at the bottom.

azure_search_scoring_profile_100217
Available scoring profiles

Click the “Add scoring profile” button at the top

azure_search_scoring_profile_4_100217

name the new profile and a new profile will open in the blade

azure_search_scoring_profile_2_100217

Click on the weights button and select the filed and weighting against that field. The weights are between 0-10

azure_search_scoring_profile_3_100217

 

Save the profile to close the blade. In the prevous blade, click “Set as default” which will set the scoring as a default item. This means any search performed against the index will be run through this to ensure the results you are expecting match the criteria.