hello world!

# # associated QPS

QPS, number of requests processed per second. It can reflect the pressure of a service to some extent. Here is a case to analyze how to estimate the QPS of a service roughly.

Background: An activity launched yesterday will give coupons according to the time of singing, and calculate the QPS of this coupon.

Analysis: Every coupon sending behavior will be recorded in a log, as follows.

2017-10-27 15:10:16    songtime=355 userid=56135899 giftid=20331 addednumbers=1Copy the code

Therefore, calculating songtime requests per second is the target value.

Therefore, you can use the following command:

developer@hosttx:~$ sudo devpssh -i -h /opt/iplist.all.svn 'grep songtime /home/log/baofang-yanzhishengdian.log' | grep 10-27 | cut -d "" -f 2  | uniq -cCopy the code

Due to the small number of visitors, the QPS is basically 2~3.

Explanation: You may be wondering, how does this work out? To explain, our goal is to look at the number of SongTime logs in a given second.

  • Check whether a log containssongtime, you can run the grep command.
  • Find log records online between multiple GET machines, can be usedsudo devpssh -i -h /opt/iplist.all.svn 'grep songtime /home/log/baofang-yanzhishengdian.log'
  • To cut the second level log, use the cut command.-d "delimiter"Used to specify the delimiter character,-fNWhich field is used to display, counting from 1 by default.
  • The uniq command was short and pithy,-cParameter is used for statistics, but only two adjacent lines of the same log are added to the number before the first entry.

Simulate the Redis synchronization process

The redis service is currently enabled on your computer:

ps aux | grep redis-server

If not, we can start several Redis-servers on one machine, so we can specify different ports.

redis-server –port 6666

Also, start another Redis service using redis-server –port 7777.

Finally, let’s see if the service is up or not.

ps aux | grep redis-server

Now that you have two new Redis services, specify the master-slave relationship before you start preparing the specific master-slave replication and synchronization operations.

  • The port 6666 serves as the master
  • The port 7777 serves as the slave

Then monitor the slave through a redis-CLI monitor command to see how the slave will react when some key in the master changes.

Monitor the slave

Let’s make 7777 our slave of 6666.

Slaveof 127.0.0.1 6666

At the same time, some output of the slave 6666 will appear under the terminal of the 7777Server.

7777 Terminal output

At the same time, the master 6666 will also respond to the synchronization request sent by 7777.

6666 Terminal output

Confirming the synchronization result

To simulate synchronization, just set a few keys in the master and check the output in the monitor window of the slave.

Slave Synchronizes master data in real time

It can be seen that the slave synchronizes data from the master in real time to achieve data consistency. In this way, simple master-slave synchronization is complete.

Note, however, that the slave redis cannot be written. Let’s say we randomly set a few keys on the slave and see if it works, and if nothing goes wrong, you’ll see something like this.

Data cannot be written in the slave state

This is because the default value of the redis slave read-only variable is yes, so to modify this variable after the synchronization is complete, run the config set slave-read-only no command.

config set slave-read-only no

It is imperative that operations on the slave have no effect on the master.

Operations on the slave do not affect the master

If you don’t want 7777 to be the slaveof 6666 after the final synchronization, use Slaveof No One to do so.

Stopping slave mode can be done using Slaveof no One

Upgrade Redis online

Online running redis are generally not very high for stability. But not too low, so upgrading Redis is necessary at some point, and it’s inevitable. However, online Redis usually contain a large amount of data, which may be up to N gigabytes, and cannot be synchronized directly. In this way, the synchronization requests from the slave will overwhelm the external user requests. The service generates an alarm.

The usual way to update online Redis is to find a stand-in and do the following steps.

  • Let doubleslaveBecome an online machine, after synchronization is complete, willslave-read-onlySet tono.
  • Divert online traffic toslave, at this timeslaveBecome an online machine and view the online machineQPS, until it is 0.
  • While you’re at it, unload the lineOld RedisAnd then install the new versionRedis.
  • The new version of theRedisAs aslaveSynchronous onlineRedisThe data will also be synchronized after completionslave-read-onlySet tono“, and then redirect the online traffic backDouble RedistheQPSZero.

During this process, the best way to see the QPS requested by Redis is through Monitor.

Redis - 127.0.0.1 cli - h - p 6379 monitor | the cut-d "." -f1 | uniq -cCopy the code

And in the online Redis upgrade, especially pay attention to the external connections, sometimes is normal business request, sometimes crontab statistics was running script, anyway is diverse, can through the ss – anp | grep Redis: port command to check the connection.

Note that you must use the root permission to see the specific PID information.

ss -anp | grep .7777

You can then use the ps aux command to find out which command is running. And then you do the right thing and you do the whole thing.

See what command is connected to Redis


conclusion

To recap, this article is mainly to talk about the online Redis upgrade experience, as well as some common sense content description. In order to step by step, the specific operation steps of QPS and Redis master-slave synchronization are described, and finally the steps and process of upgrade are introduced.

In fact, what steps are not important, what is important is the overall idea, and the use of the tool proficiency.