In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the case analysis of redis event processing process, which has certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let Xiaobian take you to understand it together.
Foreword:
We know that redis server is an event driver that needs to handle two types of events, file events and time events.
So what does redis event processing look like? Let's take a look at the following picture:
The aeMain function schedules and executes file events and time events by calling the aeProcessEvents function. The aeEventLoop records information about the event. First, obtain the shortest time interval n of time event execution through aeSearchNearest Timer function, then call aeApiPoll function to obtain the monitored socket, finally execute event processing functions rfileProc and wfileProc corresponding to socket direction, and finally execute time event function processTimeEvents.
file event
Redis has developed its own network event handler based on the Reactor pattern, called the file event handler:
File event handlers use IO multiplexers to listen for multiple sockets and associate different event handlers for the sockets based on the tasks they are currently performing
When a listening socket is ready to accept, read, write, close, etc., file event handlers invoke event handlers associated with the socket to handle events when file events occur
Composition of file event handler
(Learn video sharing: redis video tutorial)
Handlers for file events
Redis writes several handlers for file events:
Connection response handler: When the Redis server is initialized, the program will associate this connection response handler with the AE_READABLE event of the service listening suite. When a client connects to the server with the connect function to listen to the socket, the socket will generate the AE_READABLE event, triggering the connection response handler to execute and execute the corresponding socket response operation.
Command request handler: When a client successfully connects to the server through the connection response handler, the server associates the AE_READABLE event of the client socket with the command request handler. When the client sends a command request to the server, the socket will generate the AE_READABLE event, triggering the command request handler to execute and execute the corresponding socket read operation.
Command Reply Processor: When the server has a command reply to deliver to the client, the server associates the AE_WRITABLE event of the client socket with the command reply processor. When the client is ready to receive the command reply returned by the server, the AE_WRITABLE event will be generated, triggering the command reply processor to execute and execute the corresponding socket write operation.
A complete client-server connection event
The server listens for AE_READABLE event of the socket. When the client sends a connection request and generates AE_READABLE event, the server responds to the client's connection request and associates AE_READABLE event of the client socket with the command request processor. The client can send a command request to the server.
The client sends a command request to the server. The client socket will generate an AE_READABLE event, triggering the command processor to execute. Executing the command will generate a corresponding command reply. The server associates the AE_WRITABLE event of the client socket with the command reply processor.
When the client tries to read the command reply, the client socket will generate an AE_WRITABLE event, triggering the command reply handler to execute. When the command reply handler writes all the command replies to the socket, the server will contact the association between the AE_WRITABLE event of the client socket and the command reply handler.
time event
Redis time events are divided into timed events and periodic events. A temporal event consists of three attributes:
id: Globally unique IDcreated by the server for time when: arrival time of recorded time (UNIX timestamp with millisecond precision) timeProc: Time event handler
All of the server's timed events are placed in an unordered list, and whenever the timed event executor runs, it traverses the list, finds all the timed events that have arrived, and invokes the corresponding event handler. In normal mode, Redis server uses serverCron for only one time event, while in benchmark mode, the server uses only two time events, so it does not affect the performance of event execution.
Thank you for reading this article carefully. I hope that the article "Case Analysis of Redis Event Handling Process" shared by Xiaobian will be helpful to everyone. At the same time, I hope that everyone will support you more and pay attention to the industry information channel. More relevant knowledge is waiting for you to learn!
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.