-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Expand file tree
/
Copy pathmanagement-faq.yml
More file actions
158 lines (117 loc) · 12.5 KB
/
management-faq.yml
File metadata and controls
158 lines (117 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
### YamlMime:FAQ
metadata:
title: Azure Managed Redis management FAQs
description: Learn the answers to common questions that help you manage Azure Managed Redis
ms.date: 05/18/2025
ms.topic: faq
ms.custom:
- devx-track-csharp
- ignite-2024
- build-2025
appliesto:
- ✅ Azure Managed Redis
title: Azure Managed Redis management FAQs
summary: This article provides answers to common questions about how to manage Azure Managed Redis.
sections:
- name: Ignored
questions:
- question: |
When should I enable the non-TLS/SSL port for connecting to Redis?
answer: |
Using TLS is recommended as a best practice across virtually all Redis use-cases. The option to connect without TLS is included for backwards compatibility purposes.
- question: |
What are some production best practices?
answer: |
- [StackExchange.Redis best practices](#stackexchangeredis-best-practices)
- [Configuration and concepts](#configuration-and-concepts)
- [Performance testing](#performance-testing)
### StackExchange.Redis best practices
- Set `AbortConnect` to false, then let the ConnectionMultiplexer reconnect automatically.
- Use a single, long-lived `ConnectionMultiplexer` instance rather than creating a new connection for each request.
- Redis works best with smaller values, so consider chopping up bigger data into multiple keys. In [the Redis discussion](https://groups.google.com/forum/#!searchin/redis-db/size/redis-db/n7aa2A4DZDs/3OeEPHSQBAAJ), 100 kb is considered large. For more information, see [Best practices development](best-practices-development.md#consider-more-keys-and-smaller-values).
- Configure your [ThreadPool settings](#important-details-about-threadpool-growth) to avoid time-outs.
- Use at least the default connectTimeout of 5 seconds. This interval gives StackExchange.Redis sufficient time to re-establish the connection if there's a network blip.
- Be aware of the performance costs associated with different operations you're running. For instance, the `KEYS` command is an O(n) operation and should be avoided. The [redis.io site](https://redis.io/commands/) has details around the time complexity for each operation that it supports. Select each command to see the complexity for each operation.
### Configuration and concepts
- Remember that Redis is an _In-Memory_ data store. For more information, see [Troubleshoot data loss in Azure Managed Redis](troubleshoot-data-loss.md) so that you're aware of scenarios where data loss can occur.
- Develop your system such that it can handle connection blips caused by [patching and failover](failover.md).
### Performance testing
- See [Performance testing with Azure Managed Redis](best-practices-performance.md) for example benchmarks and instructions for running your own performance tests on Azure Managed Redis.
- question: |
What are some of the considerations when using common Redis commands?
answer: |
- Avoid using certain Redis commands that take a long time to complete, unless you fully understand the result of these commands. For example, don't run the [KEYS](https://redis.io/commands/keys) command in production. Depending on the number of keys, it could take a long time to return. Each Redis shard is a single-threaded, and it processes commands one at a time. If you have other commands issued after KEYS, they're not be processed until Redis processes the KEYS command. The [redis.io site](https://redis.io/commands/) has details around the time complexity for each operation that it supports. Select each command to see the complexity for each operation.
- Key sizes - should I use small key/values or large key/values? It depends on the scenario. If your scenario requires larger keys, you can adjust the ConnectionTimeout, then retry values and adjust your retry logic. From a Redis server perspective, smaller values give better performance.
- These considerations don't mean that you can't store larger values in Redis; you must be aware of the following considerations. Latencies are higher. If you have one set of data that is larger and one that is smaller, you can use multiple ConnectionMultiplexer instances. Configure each with a different set of time-out and retry values, as described in the previous [What do the StackExchange.Redis configuration options do](development-faq.yml#what-do-the-stackexchange-redis-configuration-options-do-) section.
- question: |
How can I benchmark and test the performance of my cache?
answer: |
- Enable cache diagnostics so you can [monitor](monitor-cache.md) the health of your cache. You can view the metrics in the Azure portal and you can also [download and review](https://github.com/rustd/RedisSamples/tree/master/CustomMonitoring) them using the tools of your choice.
- See [Performance testing with Azure Managed Redis](best-practices-performance.md) for example benchmarks and instructions for running your own performance tests on Azure Managed Redis.
- question: |
Important details about ThreadPool growth
answer: |
The CLR ThreadPool has two types of threads - _Worker_ and _I/O Completion Port_ (IOCP) threads.
- Worker threads are used for things like processing the `Task.Run(…)`, or `ThreadPool.QueueUserWorkItem(…)` methods. These threads are also used by various components in the CLR when work needs to happen on a background thread.
- IOCP threads are used when asynchronous IO happens, such as when reading from the network.
The thread pool provides new worker threads or I/O completion threads on demand (without any throttling) until it reaches the "Minimum" setting for each type of thread. By default, the minimum number of threads is set to the number of processors on a system.
Once the number of existing (busy) threads hits the "minimum" number of threads, the ThreadPool throttles the rate at which it injects new threads to one thread per 500 milliseconds. Typically, if your system gets a burst of work needing an IOCP thread, it processes that work quickly. However, if the burst is more than the configured "Minimum" setting, there's some delay in processing some of the work as the ThreadPool waits for one of two possibilities:
- An existing thread becomes free to process the work.
- No existing thread becomes free for 500 ms and a new thread is created.
Basically, when the number of Busy threads is greater than Min threads, you're likely paying a 500-ms delay before the application processes the network traffic. Also, when an existing thread stays idle for longer than 15 seconds, it gets cleaned up and this cycle of growth and shrinkage can repeat.
If we look at an example error message from StackExchange.Redis (build 1.0.450 or later), we see that it now prints ThreadPool statistics. See IOCP and WORKER details later in the article.
```
System.TimeoutException: Timeout performing GET MyKey, inst: 2, mgr: Inactive,
queue: 6, qu: 0, qs: 6, qc: 0, wr: 0, wq: 0, in: 0, ar: 0,
IOCP: (Busy=6,Free=994,Min=4,Max=1000),
WORKER: (Busy=3,Free=997,Min=4,Max=1000)
```
As shown in the example, you see that for IOCP thread there are six busy threads and the system is configured to allow four minimum threads. In this case, the client would see two 500-ms delays, because 6 > 4.
> [!NOTE]
> StackExchange.Redis can hit timeouts if growth of either IOCP or WORKER threads gets throttled.
### Recommendation
We recommend that customers set the minimum configuration value for IOCP and WORKER threads to something larger than the default value. We can't give one-size-fits-all guidance on this value because the right value for one application can be too high or low for another application. This setting can also affect the performance of other parts of complicated applications. Each customer needs to fine-tune this setting to their specific needs. A good starting place is 200 or 300, then test and tweak as needed.
How to configure this setting:
We recommend changing this setting programmatically using the [ThreadPool.SetMinThreads (...)](/dotnet/api/system.threading.threadpool.setminthreads#System_Threading_ThreadPool_SetMinThreads_System_Int32_System_Int32_) method in .NET Framework and .NET Core applications.
For example, in NET Framework, you set it in `Global.asax.cs` in the `Application_Start` method:
```csharp
private readonly int minThreads = 200;
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
ThreadPool.SetMinThreads(minThreads, minThreads);
}
```
If you're using .NET Core, you set it in `Program.cs`, just before the call to `WebApplication.CreateBuilder()`:
```csharp
const int minThreads = 200
ThreadPool.SetMinThreads(minThreads, minThreads);
var builder = WebApplication.CreateBuilder(args);
// rest of application setup
```
> [!NOTE]
> The value specified by this method is a global setting, affecting the whole AppDomain. For example, if you have a machine with four cores and want to set `minWorkerThreads` and `minIoThreads` to 50 per CPU during run-time, use `ThreadPool.SetMinThreads(200, 200)`.
>
It's also possible to specify the minimum threads setting by using the `minIoThreads` or `minWorkerThreads` [configuration setting](/previous-versions/dotnet/netframework-4.0/7w2sway1(v=vs.100)) under the `<processModel>` configuration element in `Machine.config`. `Machine.config` is typically located at `%SystemRoot%\Microsoft.NET\Framework\[versionNumber]\CONFIG\`.
Setting the number of minimum threads in this way isn't recommended because it's a system-wide setting. If you do set it this way, you must restart the application pool.
> [!NOTE]
> The value specified in this configuration element is a _per-core_ setting. For example, if you have a four core machine and want your `minIoThreads` setting to be 200 at runtime, use `<processModel minIoThreads="50">`.
>
- question: |
Enable server GC to get more throughput on the client when using StackExchange.Redis
answer: |
Enabling server GC can optimize the client and provide better performance and throughput when using StackExchange.Redis. For more information on server GC and how to enable it, see the following articles:
- [To enable server GC](/dotnet/framework/configure-apps/file-schema/runtime/gcserver-element)
- [Fundamentals of Garbage Collection](/dotnet/standard/garbage-collection/fundamentals)
- [Garbage Collection and Performance](/dotnet/standard/garbage-collection/performance)
- question: |
Performance considerations around connections
answer: |
Different SKUs might have different limits for client connections, memory, and bandwidth. While each size of cache allows up to some number of connections, each connection to Redis has overhead associated with it. An example of such overhead would be CPU and memory usage because of TLS/SSL encryption. The maximum connection limit for a given cache size assumes a lightly loaded cache. If load from connection overhead plus load from client operations exceeds capacity for the system, the cache can experience capacity issues even if you don't exceed the connection limit for the current cache size.
For more information about the different connections limits for each tier, see [Azure Managed Redis pricing](https://azure.microsoft.com/pricing/details/cache/).
additionalContent: |
## Related content
- Learn about other [Azure Managed Redis FAQs](faq.yml).