Configuration as a Service and Redis Cache configuration

  • Slides: 48
Download presentation
Configuration as a Service and Redis Cache configuration and deployment

Configuration as a Service and Redis Cache configuration and deployment

Who we are Azure Cloud Studios (A couple of Azure guys) Tonight’s Presenters Robert

Who we are Azure Cloud Studios (A couple of Azure guys) Tonight’s Presenters Robert Dytmire & Ed Hunkin 2

Agenda Configuration as a Service Why we think data beats config files for deploying,

Agenda Configuration as a Service Why we think data beats config files for deploying, managing and scaling your services. We’ll be discussing how we’re doing this and what enhancements we’re planning. Caching in Azure Who should use caching? What types of caching are available to us? How do you implement a cache? What are some considerations when using caching? Az. Studio A very quick tour of our Azure enterprise suite. We’ll be using Az. Studio plugins to demonstrate configuration and testing of a cache. Implement a Cache - Walkthrough Walk through the steps to impalement a Redis Cache. Configuring the cache in Az. Studio. Using the cache in a Redis Cache tester. Some tricks to pop and push more than the Azure stated maximums. Life cycle of a cache item. Q&A Open the floor to questions. 3

Configuration as a Service 4

Configuration as a Service 4

Configuration as a Service Replacing various configuration files with data services. Role asks for

Configuration as a Service Replacing various configuration files with data services. Role asks for configuration data via a series of service calls. Minimal configuration in the project code. 5

Configuration as a Service Replacing various configuration files with data services. Role asks for

Configuration as a Service Replacing various configuration files with data services. Role asks for configuration data via a series of service calls. Minimal configuration in the project code. Easier Configuration changes are stored and managed via a centralized data store. Configuration changes do not require re-deployment and in many cases do not require role recycling. 6

Configuration as a Service Replacing various configuration files with data services. Role asks for

Configuration as a Service Replacing various configuration files with data services. Role asks for configuration data via a series of service calls. Minimal configuration in the project code. Easier Configuration changes are stored and managed via a centralized data store. Configuration changes do not require re-deployment and in many cases do not require role recycling. More Secure The configuration tasks can be delegated to a completely different team. Configuration changes in one environment can be delegated to the coder (Dev) but QA and Production can manage their own implementations. Configuration can be segmented by major function. 7

Configuration as a Service Replacing various configuration files with data services. Role asks for

Configuration as a Service Replacing various configuration files with data services. Role asks for configuration data via a series of service calls. Minimal configuration in the project code. Easier Configuration changes are stored and managed via a centralized data store. Configuration changes do not require re-deployment and in many cases do not require role recycling. More Secure The configuration tasks can be delegated to a completely different team. Configuration changes in one environment can be delegated to the coder (Dev) but QA and Production can manage their own implementations. Configuration can be segmented by major function. Better consistency Ever wondered if your XML was well-formed? Missing an attribute? Is the section something that is supposed to be in consistent and well understood? A database-driven interface eliminates a lot of confusion. Database tables can enforce data consistency, security, and redundancy. 8

Configuration as a Service Replacing various configuration files with data services. Role asks for

Configuration as a Service Replacing various configuration files with data services. Role asks for configuration data via a series of service calls. Minimal configuration in the project code. Easier Configuration changes are stored and managed via a centralized data store. Configuration changes do not require re-deployment and in many cases do not require role recycling. More Secure The configuration tasks can be delegated to a completely different team. Configuration changes in one environment can be delegated to the coder (Dev) but QA and Production can manage their own implementations. Configuration can be segmented by major function. Better consistency Ever wondered if your XML was well-formed? Missing an attribute? Is the section something that is supposed to be in consistent and well understood? A database-driven interface eliminates a lot of confusion. Database tables can enforce data consistency, security, and redundancy. Scales Well Once you have your configuration schema, it’s very easy to scale for small, medium and large projects. Your pattern is the same in all environments and all scales. Dev works and deploys the same as production. 9

Overview Configuration Layer Database Store Configuration Tool (Az. Studio) Configuration Admins API SQL Connection

Overview Configuration Layer Database Store Configuration Tool (Az. Studio) Configuration Admins API SQL Connection Service Call (REST / JSON) Modules Cache 10 Data Queue Happy Coders SMTP

Role / Caa. S Process 01 Boot – What am I? Upon booting, the

Role / Caa. S Process 01 Boot – What am I? Upon booting, the role needs to know what it actually is 11

Role / Caa. S Process 01 Boot – What am I? Upon booting, the

Role / Caa. S Process 01 Boot – What am I? Upon booting, the role needs to know what it actually is 12 02 Where am I? The role now needs to know what environment it is in

Role / Caa. S Process 01 Boot – What am I? Upon booting, the

Role / Caa. S Process 01 Boot – What am I? Upon booting, the role needs to know what it actually is 13 02 Where am I? The role now needs to know what environment it is in 03 Download Modules The role needs to download it’s modules and start them. Composition / Dependency injection

Role / Caa. S Process 01 Boot – What am I? Upon booting, the

Role / Caa. S Process 01 Boot – What am I? Upon booting, the role needs to know what it actually is 02 Where am I? The role now needs to know what environment it is in 03 Download Modules The role needs to download it’s modules and start them. Composition / Dependency injection 04 Modules Initialize Each module contacts the configuration service it needs for information 14

Role / Caa. S Process 01 Boot – What am I? Upon booting, the

Role / Caa. S Process 01 Boot – What am I? Upon booting, the role needs to know what it actually is 02 Where am I? The role now needs to know what environment it is in 05 System Ready All modules running. Role is now fully functional 15 03 Download Modules The role needs to download it’s modules and start them. Composition / Dependency injection 04 Modules Initialize Each module contacts the configuration service it needs for information

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio,

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio, which is our Caa. S tool / product. We wanted you to understand the apparent non-standard configuration steps. 16

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio,

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio, which is our Caa. S tool / product. We wanted you to understand the apparent non-standard configuration steps. Going Forward If permitted, we’d like to demonstrate more Caa. S and code automation techniques in future presentations. Having this information will form a good foundation for more advanced techniques. 17

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio,

Why was all that Important? Tonight’s Demo Our Redis cache demo uses Az. Studio, which is our Caa. S tool / product. We wanted you to understand the apparent non-standard configuration steps. Going Forward If permitted, we’d like to demonstrate more Caa. S and code automation techniques in future presentations. Having this information will form a good foundation for more advanced techniques. General Trends Our team is convinced that Caa. S will be an emerging trend in Iaa. S environments. It’s a natural progression of the toolsets as they respond to this new paradigm. 18

Caching in Azure 19

Caching in Azure 19

When you need Caching Speed You do not want the overhead of querying an

When you need Caching Speed You do not want the overhead of querying an SQL server or other storage container. This is especially true when data structure you’re referencing is complex, built from multiple queries or is small and easy to cache in memory. In-memory caching is very good for small sets of frequently referenced data that do not change very often. 20

When you need Caching Speed You do not want the overhead of querying an

When you need Caching Speed You do not want the overhead of querying an SQL server or other storage container. This is especially true when data structure you’re referencing is complex, built from multiple queries or is small and easy to cache in memory. In-memory caching is very good for small sets of frequently referenced data that do not change very often. Reduce Load Reduce DTU’s! You want your SQL server to be the accessed only when it is absolutely necessary to read and write persistent data. Caching reduces redundant SQL work. Use caching to reduce loads on these systems. 21

When you need Caching Speed You do not want the overhead of querying an

When you need Caching Speed You do not want the overhead of querying an SQL server or other storage container. This is especially true when data structure you’re referencing is complex, built from multiple queries or is small and easy to cache in memory. In-memory caching is very good for small sets of frequently referenced data that do not change very often. Reduce Load Reduce DTU’s! You want your SQL server to be the accessed only when it is absolutely necessary to read and write persistent data. Caching reduces redundant SQL work. Use caching to reduce loads on these systems. Reduce Costs It costs money to access SQL and other storage resources. Some resources, such as blobs and queues have absolute upper limits on instance access per minute. 22

When you need Caching Speed You do not want the overhead of querying an

When you need Caching Speed You do not want the overhead of querying an SQL server or other storage container. This is especially true when data structure you’re referencing is complex, built from multiple queries or is small and easy to cache in memory. In-memory caching is very good for small sets of frequently referenced data that do not change very often. Reduce Load Reduce DTU’s! You want your SQL server to be the accessed only when it is absolutely necessary to read and write persistent data. Caching reduces redundant SQL work. Use caching to reduce loads on these systems. Reduce Costs It costs money to access SQL and other storage resources. Some resources, such as blobs and queues have absolute upper limits on instance access per minute. Persistent Shared Data When you want multiple roles to access the same data quickly and cheaply. For example: Complex session state data for your logged in users. Any data that is frequently accesses but produces significant query load is a candidate. 23

Caching Technologies Available in Azure Local Cache Instance Only • • 24 No Lifetime

Caching Technologies Available in Azure Local Cache Instance Only • • 24 No Lifetime Management Concurrency considerations Lightweight Fastest In-Role Cache Role Shared • No Lifetime Management • Difficult to configure and manage • Inconsistent operation • Depreciated Managed Cache Service Redis Data Center • Lifetime Management • Inconsistent operation • Depreciated. You cannot create this service going forward. • Lifetime Management • Microsoft Recommended • Stable

Have a Backup Plan 25 Database Cache Table Storage Blob Storage Re-Hydrate Use a

Have a Backup Plan 25 Database Cache Table Storage Blob Storage Re-Hydrate Use a simple SQL table to store a copy of your JSON data. Use table storage for fast cache backup. We like this solution better than SQL. Not as flexible. If you use a consistent keying strategy then store the JSON as a blob. Slowest but necessary. Your code must know how to rehydrate its state from original data.

Az. Studio 26

Az. Studio 26

Az. Studio Unified Azure Configuration One stop application that allows us to manage all

Az. Studio Unified Azure Configuration One stop application that allows us to manage all aspects of configuration. Any Azure / C# module can be configured for every environment. 27

Az. Studio Unified Azure Configuration One stop application that allows us to manage all

Az. Studio Unified Azure Configuration One stop application that allows us to manage all aspects of configuration. Any Azure / C# module can be configured for every environment. Unified Application Management Any application we deploy to Azure can be managed via this toolset. Plugins allow us to extend the toolset for each client as necessary. 28

Az. Studio Unified Azure Configuration One stop application that allows us to manage all

Az. Studio Unified Azure Configuration One stop application that allows us to manage all aspects of configuration. Any Azure / C# module can be configured for every environment. Unified Application Management Any application we deploy to Azure can be managed via this toolset. Plugins allow us to extend the toolset for each client as necessary. Code Generation Toolset We’ve taken our code blowers and turned them into Azure-Aware plugins. Single point of code creation and template management. 29

Az. Studio Unified Azure Configuration One stop application that allows us to manage all

Az. Studio Unified Azure Configuration One stop application that allows us to manage all aspects of configuration. Any Azure / C# module can be configured for every environment. Unified Application Management Any application we deploy to Azure can be managed via this toolset. Plugins allow us to extend the toolset for each client as necessary. Code Generation Toolset We’ve taken our code blowers and turned them into Azure-Aware plugins. Single point of code creation and template management. Super Flexible Plugin Architecture Host app follows our best practices in Azure and allows plugins to quickly leverage this foundation. 30

Az. Studio 31

Az. Studio 31

Setting Up Redis Cache in Azure 32

Setting Up Redis Cache in Azure 32

Create your Cache in Azure Note: This is the new portal. Ensure you are

Create your Cache in Azure Note: This is the new portal. Ensure you are in the new “preview” portal 33

Select your Pricing Tier Watch Expenses! Examine each offering, as it’s easy to select

Select your Pricing Tier Watch Expenses! Examine each offering, as it’s easy to select a caching size that’s much more than you need. We find the B 1 service works pretty well for most businesses. Also keep in mind you need THREE of these caches (Dev, QA and Production) but your Dev and QA caches should be B 0 tier in almost all cases. Scale up your cache before you federate. Carefully consider if you need replication or an SLA, as those cost more. Using the failsafe methods mentioned earlier are often more cost effective. 34

Create the Cache Set your Resource Group and Location This let’s Azure know where

Create the Cache Set your Resource Group and Location This let’s Azure know where you want the physical instance located. Select Create A tile will appear on your portal that looks like this: Wait for Deployment The portal will inform you when your cache is ready. This takes a bit of time. 35

Take Note of Configuration Strategy You’ll want to have your configuration strategy planned out

Take Note of Configuration Strategy You’ll want to have your configuration strategy planned out at this point. For this demonstration, we’re going to use our Caa. S strategy. There are many online tutorials on how to use configuration files and slightly different C# to accomplish the same tasks. Information you Need Note the Hostname and access key. We find using secondary key to be the best practice. 36

Create a Configuration String format: [hostname], ssl=true, password=[accesskey] Demo’s connection string would look like

Create a Configuration String format: [hostname], ssl=true, password=[accesskey] Demo’s connection string would look like this: presentation. redis. cache. windows. net, ssl=true, password=Mn 4 n/Ysspnu. KBSp. K 4 VG/DXAa 3 TOu. Ll. VP 1 mcmi. ADz. N 3 B= 37

Adding Redis Cache to your Project 38

Adding Redis Cache to your Project 38

Install the Packages Install Json. NET if you plan to serialize objects (we do)

Install the Packages Install Json. NET if you plan to serialize objects (we do) and Stack. Exchange. Redis, the Redis cache C# library. 39

Create a Caching Class Create a Project and Class In your C# code, add

Create a Caching Class Create a Project and Class In your C# code, add the Stack. Exchange. Redis and Newtonsfot. Json references. 40

Az. Studio’s Caching Class Static Class We use a static class that manages different

Az. Studio’s Caching Class Static Class We use a static class that manages different cache instances. The cache instances each maintain a persistent cache connection and manage writing and reading from the Redis Instance. The Connection. Multiplexer is the key class. Connect uses your connection string and produces a connection object. You should persist the connection object as it is meant to have a long life-cycle (it’s a heavy object to create). 41

Create Set Method Now we have a connection. We can leverage the connection to

Create Set Method Now we have a connection. We can leverage the connection to write our own Get and Set methods. We like to use JSON encoders to serialize our object in and out of the cache. This seems to work for us fairly well. You can also serialize into a byte stream 42

Create Get Method Get is pretty straightforward. We attempt to read the cache. If

Create Get Method Get is pretty straightforward. We attempt to read the cache. If we find the value in the cache we de-serialize it into <T>. If the key is null or missing…or we encounter an exception de-serializing then it returns default(T). 43

Quick Cache Facts 44

Quick Cache Facts 44

Quick Redis Cache Facts Maximum Key Size You’ll want to keep your key size

Quick Redis Cache Facts Maximum Key Size You’ll want to keep your key size as small as possible. The Key and Value size count together A hard limit of 512 MB on key size. Maximum Value Size Max value is 512 MB for a serialized string. Keep in mind the key size counts towards this limit. But really, what are you doing caching a 512 MB string? ! Concurrent Connections? Depends on cache size. Keep in mind that a 250 MB cache runs on a A-0 size machine. The larger the cache size the larger the dedicated box to host the cache will be, so load test your app. The absolute limit is 10 K. Note: We found that a 1 GB cache size was sufficient to handle most of our smaller to mid-sized client’s modest caching needs. Lifespan Set the MAXMEM policy in your cache settings, all settings. The default is volatile LFU. That is old values will be deleted after several minutes or if the cache needs to make room, the Least Frequently Used item will be deleted. 45

Live Demo 46

Live Demo 46

Summary Caching is Easy & Strategy is Less so Azure makes setting up and

Summary Caching is Easy & Strategy is Less so Azure makes setting up and accessing a cache very easy. How you implement caching in your project is less so. Configuration can play a big role. Peak load, moving between environments simply, and coming up with a consistent fallback strategy are all import considerations. Caa. S Going forward, we see Caa. S logically complementing Iaa. S. Consistent, data-checked and environment aware configuration tools will become more consistent and powerful. We’d like to present on this subject in more depth at a future date. 47

What Next? Takeaway We will now pass out your take-away. Use this as a

What Next? Takeaway We will now pass out your take-away. Use this as a quick guide to help you with our challenge. Challenge We challenge you to write your own Redis Cache test project this week. Place load on the system. See if you can break the I/O. Test the limits of different sizes. See what kind of performance you get. Report back on the Azure Meet-Up Group message board. Doing this yourself will educate you more than anything that I can stand here and yammer on about. 48