Friday, July 31, 2015

Updating Service Tiers in Azure SQL Database

Azure SQL Web and Business databases are being deprecated and retired September 2015 so it's time to start planning to upgrade existing Web or Business databases to the Basic, Standard, or Premium service tiers.

Upgrading a Web or Business database to a new service tier involves the following steps:

  1. Determine service tier based on feature capability
  2. Determine an acceptable performance level based on historical resource usage
  3. Why does existing performance for my Web or Business database map to the higher Premium levels?
  4. Tuning your workload to fit a lower performance level
  5. Upgrade to the new service tier/performance level
  6. Monitor the upgrade to the new service tier/performance level
  7. Monitor the database after the upgrade

In this post I will discuss about the point 2 : “Determine an acceptable performance level based on historical resource usage”


How to view the recommended service tier in the new Azure Management Portal

New Management Portal

  1. Log on to the new management portal and navigate to a server containing a Web or Business database.
  2. Go to browse all, Then SQL Servers
  3. Select the server you want to upgrade
  4. Click the Latest Update part in the server blade.


5. Click Upgrade this server.

The Upgrade this server blade now shows a list of Web or Business databases on the server along with the recommended service tier.


How to view DTU consumption in the Management Portal

Log on to the management portal and navigate to an existing Web or Business database.

  1. Click the MONITOR tab.
  2. Click ADD METRICS.
  3. Select DTU percentage and click the checkmark at bottom to confirm.


Hope this helps.

Monday, July 13, 2015

Clear Azure Cache : Get All keys in Azure Redis cache


Recently I got a requirement to clear cache value for a given client account. In our systems we have multiple contractors , and we cache some data related to that contractor account. Cache keys are as follows.

  1. string.Format("{0}:ServiceTypeList", clientConfiguration.Code);
  2.       string.Format("{0}:PropertyViewModelList", clientConfiguration.Code);
  3.       string.Format("{0}-{1}:FaultTypeList", clientConfiguration.Code,
  4.                     serviceType.ServiceTypeID);
  5.       string.Format("{0}-{1}:LocationList", clientConfiguration.Code,
  6.                     property.PropertyNo);

Here some cache keys are based on Client Configuration code, and some have client configuration and some code too. But when we have to clear the cache for a given client account we have only the Client Configuration code. So we used the following approach.

1. Get all Cache Keys

  1. private static ConnectionMultiplexer _connection;
  3. public static IServer GetDataCacheServer()
  4. {
  5.     if (_connection == null || !_connection.IsConnected)
  6.     {
  7.         _connection = ConnectionMultiplexer.Connect(HybridConfig.GetAppSetting("RedisCacheConnectionString"));
  8.     }
  11.     var endpoints = _connection.GetEndPoints();
  12.     var server = _connection.GetServer(endpoints.First());
  13.     return server;
  15. }
  18. public static IEnumerable<RedisKey> GetAllCacheKeys()
  19. {
  20.     var server = GetDataCacheServer();
  22.     var keys = server.Keys();
  23.     return keys;
  24. }

2. Create Remove method

  1. public static void Remove(string key)
  2.         {
  5.             try
  6.             {
  7.                 key = string.Format("{0}_{1}_{2}", key, HybridConfig.GetAppSetting("ApplicationUrl"), HybridConfig.GetAppSetting("ApplicationVersion"));
  8.                 var database = GetDataCache();
  9.                 database.KeyDelete(key);
  11.                 if (AllKeys.Contains(key))
  12.                 {
  13.                     AllKeys.Remove(key);
  14.                 }
  15.             }
  16.             catch (Exception ex)
  17.             {
  18.                 SqlLogger.Error(typeof(AzureCache), string.Format("Error while trying to remove the key : {0} | Message : {1}", key, ex.Message), ex);
  19.             }
  20.         }

3. Search the client configuration code in it and clear the cache

            var keys = AzureCache.GetAllCacheKeys();
            string applicationTag = string.Format("_{0}_{1}", HybridConfig.GetAppSetting("ApplicationUrl"),
            List<string> cacheKeys = (from redisKey in keys
                                      select redisKey.ToString()
                                      into key
                                      where key.Contains(applicationTag) && key.Contains(clientConfiguration.Code)
                                      select key.Replace(applicationTag, string.Empty)).ToList();
            if (cacheKeys.Any())

Happy Coding !!!

Monday, July 6, 2015

Azure Search Introduction


Today almost al the web applications and mobile applications provides search functionality. That is the best way the user could access the data they want to see. Most common way of searching data is giving a search textbox. Further there are many ways of providing richer search experience to the users to make their life comfort when using the application. But providing such search functionality can be challenging for the application developers.It’s not reasonable to expect every development team to build its own search engine. Even installing and running a commercial search engine can be a lot of work. What’s needed is a managed search service that can be used by many different applications, whether they’re running in the cloud or on premises. This is exactly what Azure Search offers.

What is Azure Search?

Azure Search is a managed service running in the public cloud. You can create a new instance of azure search and use it. Application using azure search can run on Microsoft azure, on-premises or in another cloud platform.You can create Indexes in azre search, which is similar to a Table in SQL and sync your data to that. There are different ways of syncing your data to Search indexes.

  • Push: Where the data is in a different store, or when the application wants more control over how data is updated, developers can use the upload API to push content into the index in batches
  • Indexer: Data population and updates from Azure SQL, SQL Server on Azure VM’s or DocumentDB stores can be automatically loaded into the index (NOTE: Other stores will be supported based on customer demand)

Azure search provides a RESTful interface to the application so the application developers can send search requests to that service. Following figure illustrates the this.



This provides many functionalities.

  • Search Text: Text as written by the user used for full text search
  • Highlighting: Define fields to be used for hit highlighting of search text
  • Filter: Used to further limit results. E.g., a product catalog might exclude products with no stock left
  • Sorting: Sort results by values in document fields instead of score
  • Paging: Limit the number of results to be returned (skip & take)
  • Projection: Limits results to a subset of the fields in results allowing conservation of bandwidth
  • Count: Total count of fetched items
  • Lookup: Retrieves a specific document from Azure Search by its key
  • MoreLikeThis: Finds documents that are relevant to another specific document

E-commerce applications:

such as the web site for an online retailer. Providing a search option for an ecommerce site is essential—users expect it. But the organization that provides this site almost certainly wants to control what information is returned and—especially—the order of those results. Think of an online shoe store, for example, that’s currently running a promotion with a particular shoe manufacturer. Suppose that manufacturer is paying the online retailer for this promotion, and so the site’s search results need to list this brand of shoes first. Or perhaps the shoe store has lots of a particular style in stock right now that it wants to sell off. Placing the style first in search results can help the retailer achieve this business goal. Owning its own search function has other benefits, too, such as letting this firm see what its customers are searching for that it doesn’t currently sell. None of this makes internet search engines any less important; an online retailer should still do whatever it can to direct Google and Bing searches to its site. Once people are there, however, the retailer can benefit from controlling how customers search the site.

User-generated content sites

such as a discussion site for movie buffs. As with e-commerce applications, users expect to be able to navigate this kind of site via search. For the creators of the site, controlling that search once again brings some advantages. As with e-commerce applications, for example, there might be business reasons for returning search results in a particular order. Suppose an online cooking site is sponsored by three large food companies. The site’s owners might choose to show recipes that use foods sold by these companies higher in search results. (This might seem cynical—do we really need more pay-for-play sites?—yet it is in fact how much of the internet business works.) And because Azure Search lowers the barrier to entry for creating custom search, an organization doesn’t need to realize enormous benefits to justify the effort of doing this.

Custom business applications

such as an employee benefits solution. Traditionally, a line-of-business application is accessed by clicking through its UI until the user finds what he needs. If the application is simple, or if the user knows the application very well, this approach works. But many business applications (maybe even most of them) would be significantly more usable if they provided a search option. Once again, people love search. (Don’t you?) Add a search box to an application’s UI, then watch how rapidly people start using it. In fact, one way to smooth adoption of a new business application in an organization might be to make sure that it has a search option in its UI.

Azure Search Pricing


for more details about azure search pricing go here.

I will discuss how to create a azure search serving using azure portal and how to manage it in my next post.