{"id":85,"date":"2019-04-16T07:02:00","date_gmt":"2019-04-16T07:02:00","guid":{"rendered":"https:\/\/opstree.com\/blog\/\/2019\/04\/16\/redis-best-practices-and-performance-tuning\/"},"modified":"2025-11-19T18:03:57","modified_gmt":"2025-11-19T12:33:57","slug":"redis-best-practices-and-performance-tuning","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2019\/04\/16\/redis-best-practices-and-performance-tuning\/","title":{"rendered":"Redis Best Practices and Performance Tuning for High-Speed Systems"},"content":{"rendered":"<p data-start=\"1332\" data-end=\"1680\">In modern high traffic systems, Redis is one of the fastest in-memory data stores, but without proper tuning, even Redis can start showing performance bottlenecks.<\/p>\n<p data-start=\"1682\" data-end=\"1750\">The solution? <strong data-start=\"1696\" data-end=\"1750\">Performance tuning and configuration optimization.<\/strong><\/p>\n<p data-start=\"1752\" data-end=\"1889\">This guide covers the <strong data-start=\"1774\" data-end=\"1827\">most important Redis performance tuning practices<\/strong> every DevOps engineer, SRE, or backend developer must follow.<\/p>\n<p dir=\"ltr\" style=\"text-align: left;\">One of the thing that I love about my organization is that you don&#8217;t have to do the same repetitive work, you will always get the chance to explore some new technologies. The same chance came across to me a few days back when one of our clients was facing issue with Redis.<br \/>\nThey were using the Redis Cluster with Sentinel for which they were facing issue regarding performance, whenever the connection request was high the Redis Cluster was not able to bear the load.<br \/>\nSince they were using a decent configuration of the server in terms of CPU and Memory but the result was the same. So now what????<br \/>\nThe Answer was to tune the performance.<!--more--><\/p>\n<p>There are plenty of Redis performance articles out there, but I wanted to share my experience as a DevOps with Redis by creating an article which will include the most essential and important stuff that is needed for a Developer or a DevOps Engineer.<\/p>\n<p><strong>[ Searching for the best <a href=\"https:\/\/opstree.com\/\" target=\"_blank\" rel=\"noopener\">DevOps company<\/a> for your business solutions?]<\/strong><\/p>\n<h2 style=\"text-align: left;\">Enable TCP KeepAlive for Connection Stability<\/h2>\n<p>Keepalive is a method to allow the same TCP connection for HTTP conversation instead of opening a new one with each new request.<\/p>\n<p>In simple words, if the keepalive is off the Redis will open a new connection for every request which will slow down its performance. If the keepalive is on then Redis will use the same TCP connection for requests.<\/p>\n<p>Let&#8217;s see the graph for more details. The Red Bar shows the output when keepalive is on and Blue Bar shows the output when keepalive is off<\/p>\n<div><span id=\"docs-internal-guid-b0f443cf-7fff-ef8d-8250-25e3b2bc2bb8\"><img decoding=\"async\" title=\"Chart\" src=\"https:\/\/lh4.googleusercontent.com\/8rsvV5aUYbDAtuqeFCG0i_RqsNn0849lVC_HX1GdST5SrbfEuHwWu_24cI9MPEqT4je9KSpojPOx2-GoORd8lbh2Kd3b4X9i9ZLl2SQqOc5fbGITXSbD1gPyTFCXReHkABBM46XPcPE\" width=\"614px;\" height=\"331px;\" \/><\/span><\/div>\n<p>For enabling the TCP keepalive, Edit the redis\u00a0configuration and update this value.<\/p>\n<div>\n<pre><span style=\"color: #005cc5;\">vim \/etc\/redis\/redis.conf\r\n<\/span><\/pre>\n<pre># Update the value to 0\r\ntcp-keepalive 0<\/pre>\n<\/div>\n<p><strong>[ Also Read: <a href=\"https:\/\/opstree.com\/blog\/2025\/06\/03\/redis-observability-with-open-telemetry\/\" target=\"_blank\" rel=\"noopener\">Redis Observability with Open Telemetry<\/a> ]<\/strong><\/p>\n<h2 style=\"text-align: left;\">Use Redis Pipelining for Faster Request Processing<\/h2>\n<p>This feature could be your lifesaver in terms of Redis Performance. Pipelining facilitates a client to send multiple requests to the server without waiting for the replies at all and finally reads the reply in a single step.<\/p>\n<p>For example:-<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-978\" src=\"https:\/\/opstree.com\/blog\/\/wp-content\/uploads\/2019\/04\/1.png\" alt=\"1\" width=\"700\" height=\"370\" \/><\/p>\n<p>You can also see in the graph as well.<\/p>\n<p><span id=\"docs-internal-guid-b07b7e68-7fff-f8d5-a85c-adb65b3664a8\"><img decoding=\"async\" title=\"Chart\" src=\"https:\/\/lh4.googleusercontent.com\/OIJdiz5xtUk3BVk0zavk61LuEpwFwzJk7vhZXDLuuIJzDQC5-3kHIQhi7lGW7Ox9o6uR8LsGHzP2Igp696N7GD24ZcJJ3c0pw6jun0XrvMeVG-Q0w7_e8ZrKVg5GWAJZzEEZTW7HNw4\" width=\"595px;\" height=\"345px;\" \/><\/span><\/p>\n<p>Pipelining will increase the performance of redis drastically.<\/p>\n<p>Want high-performance <a href=\"https:\/\/opstree.com\/services\/database-and-data-engineering\/\">data pipeline development services<\/a> that ensure seamless data processing?, Click now to learn more.<\/p>\n<h2 style=\"text-align: left;\">Increase Maximum Connections (somaxconn)<\/h2>\n<p>Max-connection is the parameter in which is used to define the maximum connection limit to the Redis Server. You can set that value accordingly (Considering your server specification) with the following steps.<\/p>\n<div>\n<pre><span style=\"color: #005cc5;\">sudo vim \/etc\/rc.local\r\n\r\n# make sure this line is just before of exit 0.\r\n<\/span>sysctl -w net.core.somaxconn=65365<\/pre>\n<\/div>\n<p>This step requires the reboot if you don&#8217;t want to reboot the server execute the same <b>sysctl\u00a0<\/b>command on the terminal itself.<\/p>\n<h2 style=\"text-align: left;\">Enable Overcommit Memory to Avoid OOM Errors<\/h2>\n<p>Overcommit memory is a kernel parameter which checks if the memory is available or not. If the overcommit memory value is 0 then there is a chance that your Redis will get OOM (Out of Memory) error. So do me a favor\u00a0and change its value to 1 by using the following steps<\/p>\n<pre style=\"background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; line-height: 1.45; overflow-wrap: normal; overflow: auto; padding: 16px; word-break: normal;\"><span style=\"font-size: 13.6px;\">echo 'vm.overcommit_memory = 1' &gt;&gt; \/etc\/sysctl.conf<\/span><\/pre>\n<div><\/div>\n<div>\n<h2 style=\"text-align: left;\">Disable RDB and AOF in Redis Cluster Mode<\/h2>\n<\/div>\n<p>RDB persistence and Append Only File options are used to persist data on disk. If you are using the cluster mode of Redis then the RDB persistence and AOF is not required. So simply comment out these lines in redis.conf<\/p>\n<div><\/div>\n<pre style=\"background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; font-size: 13.6px; line-height: 1.45; overflow-wrap: normal; overflow: auto; padding: 16px; word-break: normal;\"><span style=\"color: #005cc5;\">sudo vim \/etc\/redis\/redis.conf\r\n\r\n# Comment out these lines\r\n<\/span><span style=\"color: #005cc5;\">save 900 1\r\nsave 300 10\r\nsave 60 10000\r\n<\/span>\r\n<span style=\"color: #005cc5;\">rdbcompression no\r\nrdbchecksum no\r\n\r\nappendonly no<\/span>\r\n<\/pre>\n<div><\/div>\n<div>\n<h2 style=\"text-align: left;\">Disable Transparent Huge Pages (THP)<\/h2>\n<\/div>\n<div>\n<p>Most of the people are not aware of this term. Basically, For making the translation of physical and virtual memory kernel uses the concept of paging. This feature was defined to enhance the memory mapping process but somehow it slows down the databases which are memory based (for example &#8211; in the case of Redis). To overcome this issue you can disable THP.<\/p>\n<p style=\"background-color: #f6f8fa; border-radius: 3px; box-sizing: border-box; font-size: 13.6px; line-height: 1.45; overflow-wrap: normal; overflow: auto; padding: 16px; word-break: normal;\"><span style=\"color: #005cc5;\">sudo vim \/etc\/rc.local # Add this line before exit 0<\/span> <span style=\"color: #005cc5;\">echo never &gt; \/sys\/kernel\/mm\/transparent_hugepage\/enabled<\/span><\/p>\n<\/div>\n<div>As graph also shows the difference in performance. The Red Bar is showing THP disabled performance and Blue Bar is showing THP disabled performance.<\/div>\n<div>\n<p><span id=\"docs-internal-guid-6fb5a88c-7fff-bf60-55dd-e7d5b0572624\"><img decoding=\"async\" title=\"Chart\" src=\"https:\/\/lh3.googleusercontent.com\/RS9wwgRGU5QuywnibzP0kzBfGEI2O7qbwW5B39p3McitF9eF_GddumE1br2Onx0Oim1_v61UDruNtr-KGbEmOtAIVwsGRuTcZUigEwxplu6J-Qj3W7arja1z1AK9Jw4AtRhRB9BqWkU\" width=\"547px;\" height=\"338px;\" \/><\/span><\/p>\n<p>Some Other Basic Measures in Redis Configuration<\/p>\n<div>\n<table style=\"border-collapse: collapse; border: none;\">\n<colgroup>\n<col width=\"253px\" \/>\n<col width=\"253px\" \/>\n<col width=\"253px\" \/> <\/colgroup>\n<tbody>\n<tr style=\"height: 40px;\">\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">Config Option<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">Value<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">Description<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 40px;\">\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">maxmemory<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">70% of the system<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">maxmemory should be 70 percent of the system so that it will not take all the resource of the server.<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 40px;\">\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">maxmemory-policy<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">volatile-lru<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">It adds a random key with an expiry time<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 40px;\">\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">loglevel<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">notice<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">Loglevel should be &#8220;notice&#8221;, so that log will not take too much resource<\/p>\n<\/td>\n<\/tr>\n<tr style=\"height: 40px;\">\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">timeout<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">300<\/p>\n<\/td>\n<td style=\"vertical-align: top; padding: 10px; border: solid #9E9E9E 1px;\">\n<p dir=\"ltr\" style=\"line-height: 1.2; margin-bottom: 0; margin-top: 0;\">There should be a timeout value as well in redis configuration which prevents redis from spending too much time on the connection. It closes the connection of the client if it is ideal for more than 300 seconds.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>So now your redis is ready to give a killer performance. In this blog, we have discussed redis best practices and performance tuning.<br \/>\nThere are multiple factors which are yet to be explored to enhance the performance of <a href=\"https:\/\/redis.io\/\" target=\"_blank\" rel=\"noopener\">Redis<\/a> if you find that before I do, please let me know to improve this blog.<\/p>\n<p><b>In my next blog, I will discuss around how can we do Redis Performance Testing and how we are doing it in our Organisation.<\/b><\/p>\n<h2>Conclusion<\/h2>\n<p data-start=\"5165\" data-end=\"5455\">Redis is fast but only when configured correctly.<br data-start=\"5216\" data-end=\"5219\" \/>By applying these performance tuning techniques such as enabling TCP KeepAlive, using pipelining, optimizing memory usage, disabling THP, and adjusting system-level parameters, you can drastically improve Redis throughput and stability.<\/p>\n<p data-start=\"5457\" data-end=\"5561\">More optimizations exist, and I will cover <strong data-start=\"5500\" data-end=\"5540\">Redis Performance Testing Automation<\/strong> in the next article.<\/p>\n<p data-start=\"5563\" data-end=\"5660\">If you discover additional tuning strategies, share them so we can optimize this guide further.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern high traffic systems, Redis is one of the fastest in-memory data stores, but without proper tuning, even Redis can start showing performance bottlenecks. The solution? Performance tuning and configuration optimization. This guide covers the most important Redis performance tuning practices every DevOps engineer, SRE, or backend developer must follow. One of the thing &hellip; <a href=\"https:\/\/opstree.com\/blog\/2019\/04\/16\/redis-best-practices-and-performance-tuning\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Redis Best Practices and Performance Tuning for High-Speed Systems&#8221;<\/span><\/a><\/p>\n","protected":false},"author":89038429,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[475,768739308,768739285,29632,1930,768739306],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-1n","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/85"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/89038429"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=85"}],"version-history":[{"count":8,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/85\/revisions"}],"predecessor-version":[{"id":29871,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/85\/revisions\/29871"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=85"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=85"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=85"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}