In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
1. RTT
Redis is a TCP service based on client-server model and request / response protocol. This means that normally a Redis client executes a command in the following four procedures:
Send command queue command to execute the returned result
The client sends a query request to the server and listens for Socket returns, usually in blocking mode, waiting for the server to respond. The server processes the command and returns the result to the client. The client and the server are connected through the network. This connection can be fast or slow. No matter how late the network is, the packet can always reach the server from the client, and the server returns the data to the client.
This time is called RTT (Round Trip Time), for example, the above procedure sends a command and returns a result. It is easy to see how this affects performance when the client needs to execute multiple requests in a row (for example, adding multiple elements to the same list). For example, if the RTT time is 250ms (when the network connection is slow), even if the server can handle 100k requests per second, then we can only handle up to four requests per second. If you are using a local loopback interface, the RTT is much shorter, but if you need to perform multiple writes in a row, this is also a lot of overhead.
Let's take a look at the model of executing N commands:
2. Pipeline
We can use Pipeline to improve this situation. Pipeline is not a new technology or mechanism, and many technologies have been used. RTT will be different in different network environments, for example, the same computer room and the same computer room will be faster, and cross-server room and cross-region will be slow. Redis has supported Pipeline technology for a long time, so no matter what version you are running, you can use Pipeline to operate Redis.
Pipeline can assemble a set of Redis commands, transmit them to Redis through a RTT, then execute the set of Redis commands sequentially and return the results to the client. The above figure does not execute N commands using Pipeline, and the whole process requires N RTT. The following figure shows the execution of N commands using Pipeline, and the whole process requires only one RTT:
Redis provides batch operation commands (such as mget,mset, etc.), which effectively saves RTT. However, bulk operations are not supported for most commands.
3. Java Pipeline
Jedis also provides support for Pipeline features. We can use Pipeline to simulate batch deletions, which is not an atomic command like mget and mset, but can be used in most cases:
Public void mdel (List keys) {Jedis jedis = new Jedis ("127.0.0.1"); / / create Pipeline object Pipeline pipeline = jedis.pipelined (); for (String key: keys) {/ / Assembly command pipeline.del (key);} / execute command pipeline.sync ();}
4. Performance testing
The following table shows the effects of 10000 set operations performed by non-Pipeline and Pipeline in different network environments:
Network delay non-PipelinePipeline native 0.17ms573ms134ms intranet server 0.41ms1610ms240ms remote computer room 7ms78499ms1104ms
Due to different test environments, different test data may be obtained. This test Pipeline carries 100 commands at a time.
We can draw the following conclusions from the above table:
Pipeline execution is generally faster than one-by-one execution. The greater the network delay of the client and server, the more obvious the effect of Pipeline.
5. Comparison between batch commands and Pipeline
Let's take a look at the difference between bulk commands and Pipeline:
Native batch commands are atomic and Pipeline are non-atomic. Native batch commands are commands that support multiple commands corresponding to multiple key,Pipeline. Native batch commands are supported by the Redis server, while Pipeline needs the joint implementation of the server and the client.
6. Pay attention
When sending commands using Pipeline, the number of commands assembled by Pipeline must not be unrestrained, otherwise the amount of command data assembled at one time is too large, on the one hand, it will increase the waiting time of the client, on the other hand, it will cause certain network congestion, and the Pipeline containing a large number of commands can be split into several smaller Pipeline to complete.
Well, the above is the whole content of this article. I hope the content of this article has a certain reference and learning value for your study or work. Thank you for your support.
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.