In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to achieve StackExchange.Redis performance tuning, the editor feels very practical, so share with you to learn, I hope you can get something after reading this article, say no more, follow the editor to have a look.
People often have the problem of synchronous call Redis timeout, but when it is changed to asynchronous, there are very few errors, but it is possible to find that Redis commands are very slow through things like pre-and post-logging.
PS: all the future code runs in Windows bash, with StackExchange.Redis version 1.2.6
To quickly reproduce and solve the problem, run the following code first
Run Discovery and throw StackExchange.Redis.RedisTimeoutException. Why? Because the current worker thread is simply insufficient, the synchronization wait time has timed out. Please refer to the source code for details.
What if you change the above ThreadPool.SetMinThreads (8,8) to ThreadPool.SetMinThreads (100,100)? Is not to throw an exception.
As for the problem that the asynchronous interface slows down, run the following code first:
The final output shows that Run1 and Main2 use the same thread, while Run2's ElapsedMilliseconds basically adds 100 to Run1.
Then go back to calling the Redis code
Do you find that the output is over 100 or more than 1000? Why? It turns out that there is a special setting in sdk to protect the order in which asynchronous code is executed, and then we add a code connection.PreserveAsyncOrder = false before the GetDatabase line
Then run it again to see what the result is. By doing the code above, you can basically determine that asynchronous slowness is related to TaskCompletionSource and, for more information, see the source code of sdk.
To sum up the above two points, most of the problems can be solved simply through SetMinThreads and connection.PreserveAsyncOrder = false, but how to find more other deep-seated problems?
Next, we will introduce StackExchange.Redis 's two artifacts, ConnectionCounters and IProfiler.
There are three properties that are very useful after the object obtained through connection.GetCounters () .Interactive
Each attribute represents the current state of the pending command for the current redis connection. From the literal meaning, you can know that PendingUnsentItems indicates that the command that has not been sent in the queue to be sent has been carried out; SentItemsAwaitingResponse indicates that the command has been sent but has not yet received the response result; and ResponsesAwaitingAsyncCompletion indicates that the command has been received, but the command of TaskCompletionSource () .TrySetResult () has not been called yet.
The reason why PendingUnsentItems and SentItemsAwaitingResponse are too large is basically because the network is blocked. You need to check whether the network bandwidth or the value of redis is very large.
ResponsesAwaitingAsyncCompletion is because the code after await, such as the code in the example above, takes a long time to synchronize and needs to optimize the code and set PreserveAsyncOrder to false.
ConnectionCounters analyzes the instantaneous state of a thread, while IProfiler can track the total number of redis commands executed by a request and how long they have been used. Please write code for details. Reference documentation
To find a problem, you need to solve the problem, and you need to learn deeply in order to solve the problem. I don't like writing articles, but I found that there have been several articles about redis timeout recently. Finally, I would like to share my experience of stepping on the trap with you.
The good news is that StackExchange.Redis 2.0 has refactored asynchronous queues and used pipes to solve the problem of asynchronous slowness.
The above is how to achieve StackExchange.Redis performance tuning, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.