Redis is a single-process service. It is mainly used for memory, CPU, and disk I/O (mainly for persistence, you can consider using multiple redis instances. Before using multiple instances, we should first consider the use of CPU and memory. During the test, I found that when the QPS of redis is about 6 to 8 W, the logic CPU core of this redis instance has a load of around 100%. Therefore, to optimize the CPU usage, it is usually due to the soft interruption of the network card to achieve a balance. This is the case that the CPU usage of a single process is too high, however, the network card must support soft network card interruptions, and the effect is good.
The management of multi-instance redis involves monitoring and service management. Here we only talk about the restart of multiple redis instances. The following is a restart script for multiple instances for your reference only:
#! /Usr/bin/env python
#-*-Coding: UTF-8 -*-
Import redis, threading, sys, socket, time, OS
From multiprocessing import Pool
Def port_check (host, port ):
POOL = redis. ConnectionPool (host = host, port = port)
My_server = redis. Redis (connection_pool = POOL)
Try:
A = my_server.ping ()
If:
Return 1
Else:
Return 0
Except t Exception, e:
Return 0
Def shutdown_server (host, port ):
Flag = port_check (host, port)
If flag = 1:
POOL = redis. ConnectionPool (host = host, port = port)
My_server = redis. Redis (connection_pool = POOL)
My_server.shutdown ()
While 1:
Flag = port_check (host, port)
If flag = 0:
Print "% s: % s is Shutdown OK" % (host, port)
Break
Else:
Time. sleep (1)
Else:
Print "% s: % s is Shutdown alreaday" % (host, port)
Def start_server (host, port ):
Flag = port_check (host, port)
If flag = 0:
Start_conm = "/usr/local/bin/redis-server/usr/local/redis/etc/redis _ % s. conf" % port
OS. popen (start_conm)
Time. sleep (3)
I = 0
While 1: # redis ping is detected every 5s, lasting for one minute. If it does not exist for one minute, the startup fails.
Flag = port_check (host, port)
If flag = 1:
Print "% s: % s is Start OK" % (host, port)
Break
Else:
If I> 12:
Print "% s: % s is Start Error" % (host, port)
Break
Else:
Time. sleep (5)
I = I + 1
Else:
Print "% s: % s is Start alreaday" % (host, port)
Def restart (host, port ):
Shutdown_server (host, port)
Start_server (host, port)
Def main ():
Server_list = ["127.0.0.1: 6379", "127.0.0.1: 16379"]
Pool = Pool (processes = 3)
For I in server_list:
Aa = I. split (':')
Host = aa [0]
Port = int (aa [1])
Results = pool. apply_async (restart, (host, port ))
Pool. close ()
Pool. join ()
If results. successful ():
Print 'successful'
If _ name __= = "_ main __":
Main ()
Redis details: click here
Redis: click here
Recommended reading:
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Redis. conf