Improve Redis performance One finger Zen

Source: Internet
Author: User

Rumors, in Redis, a command ("Get or Set key value") in the length of the value of more than 1k, its performance dropped sharply.

A little look at the Redis code, found that its network module closed the Nagel algorithm, if you modify the Redis source code to start the algorithm?

1 Using Redis Default code test (that is, turn off the Nagel algorithm)

To verify whether this algorithm is enabled or not, it affects the performance of Redis. Do not change the Redis code, use Redis-benchmark to test, execute the following command:

./redis-benchmark-p 30000-n 50000-k 1-d 2048-q

The above command related parameter meaning is: The connection server disconnects 30000, test 50,000 times, open keepalive option, value length 2k, only output results do not output test process.

The test results are:

set:51599.59 requests per secondget:50403.23 requests per secondincr:55493.89 requests per secondlpush:54112.55 reques TS per secondlpop:48875.86 requests per secondsadd:54644.81 requests per secondspop:54112.55 requests per SecondLPUSH ( needed to benchmark Lrange): 49067.71 requests per secondlrange_600 (first elements): 400.68 requests per secondmset ( Ten keys): 33134.53 Requests per second

2 Using the socket default property

    Below is /redis-2.8.19/

  53 redisclient *createclient (INT FD)  {  54      redisclient *c = zmalloc (sizeof (redisclient));  55   56      /* passing -1 as fd it is possible to  create a non connected client.  57      *  This is useful since all the redis commands needs to be  executed  58      * in the context of a  client. When commands are executed in other  59       * contexts  (For instance a lua script)  we need  a non connected client. */  60     if  (FD  != -1)  { &nbsP;61         anetnonblock (NULL,FD);  62          // anetenabletcpnodelay (NULL,FD);  63          if  (server.tcpkeepalive)   64              anetkeepalive (null,fd,server.tcpkeepalive);   65         if  (Aecreatefileevent (Server.el,fd,AE_READABLE,   66              READQUERYFROMCLIENT, C)  == ae_err)   67          {  68             close (FD);   69             zfree (c);   70             return null;  71          }  72     }

Please note that I have commented out line 62 with the system default settings.

Execute the same command with the test result:

set:50968.40 requests per secondget:50607.29 requests per secondincr:55432.37 requests per secondlpush:47438.33 reques TS per secondlpop:49950.05 requests per secondsadd:54945.05 requests per secondspop:55187.64 requests per SecondLPUSH ( needed to benchmark Lrange): 47709.93 requests per secondlrange_600 (first elements): 398.41 requests per secondmset ( Ten keys): 26766.60 Requests per second
3 explicitly enable the Nagel algorithm 

Similarly, the code can be modified to explicitly enable the Nagel algorithm, and the same code block is modified as follows:

  53 redisclient *createclient (INT FD)  {  54      redisclient *c = zmalloc (sizeof (redisclient));  55   56      /* passing -1 as fd it is possible to  create a non connected client.  57      *  This is useful since all the redis commands needs to be  executed  58      * in the context of a  client. When commands are executed in other  59       * contexts  (For instance a lua script)  we need  a non connected client. */  60     if  (FD  != -1)  { &nbsP;61         anetnonblock (NULL,FD);  62          // anetenabletcpnodelay (NULL,FD);  63          anetdisabletcpnodelay (NULL,FD);  64          if  (server.tcpkeepalive)   65              anetkeepalive (null,fd,server.tcpkeepalive);   66          if  (Aecreatefileevent (server.el,fd,ae_readable,   67              READQUERYFROMCLIENT, C)  == ae_err)   68          {  69             close (FD);   70      &Nbsp;      zfree (c);  71              return NULL;  72          }  73     }

When the Nagel algorithm is explicitly enabled, its test results are:

set:49164.21 requests per secondget:48496.61 requests per secondincr:52910.05 requests per secondlpush:50556.12 reques TS per secondlpop:49164.21 requests per secondsadd:53937.43 requests per secondspop:53248.14 requests per SecondLPUSH ( needed to benchmark Lrange): 48169.56 requests per secondlrange_600 (first elements): 406.73 requests per secondmset ( Ten keys): 34106.41 Requests per second
4 Summary

From the comparison above, the performance of Redis is about 2% higher in most cases when the Nagel algorithm is enabled.


Improve Redis performance One finger Zen

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.