In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
What this article shares with you is about what the heartbeat mechanism is. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Heartbeat mechanism is a mechanism that regularly sends a custom heartbeat packet to let the other party know that he is still alive to ensure the validity of the connection; the so-called heartbeat packet is that the client regularly sends a simple message to the server to tell it that I am still there.
The heartbeat mechanism is a mechanism that periodically sends a custom structure (heartbeat package) to let the other party know that he or she is still alive to ensure the validity of the connection.
Concept introduction
Both receiving and sending data in the network are realized by using SOCKET in the operating system. But if the socket is disconnected, there must be problems sending and receiving data. But how can you tell if this socket can still be used? This requires the creation of a heartbeat mechanism in the system. In fact, a mechanism called heartbeat has been implemented for us in TCP. If you set the heartbeat, TCP will send your heartbeat within a certain amount of time (for example, 3 seconds), and this message will not affect the protocol you define. The so-called "heartbeat" is to send a custom structure (heartbeat packet or heartbeat frame) regularly to let the other person know that he is "online". To ensure the validity of the link.
The so-called heartbeat packet is that the client sends a simple message to the server to tell it that I am still there. The code is to send a fixed message to the server every few minutes, and the server will reply with a fixed message if the server does not receive the client message within a few minutes, then the client will be disconnected. For example, if some communication software is not used for a long time, if you want to know whether its status is online or offline, you need a heartbeat package and send and receive packets regularly. The contractor: it can be the customer or the server, depending on which side is convenient and reasonable. Usually on the client side. The server can also regularly poll the heartbeat. A heartbeat is called a heartbeat because it is sent at regular intervals like a heartbeat to tell the server that the client is still alive. In fact, this is to maintain a long connection, as for the content of this package, there is no special stipulation, but it is usually a very small package, or only an empty packet containing a header.
In the mechanism of TCP, there is a mechanism of hearthopping, that is, the option of TCP. The system defaults to a 2-hour heartbeat rate. But it can not detect machine power outage, network cable unplug, firewall and so on. And the logical layer may not be so easy to deal with disconnection. Generally speaking, it is OK if it is only used to keep alive. Heartbeat packets are generally implemented by sending empty packets at the logic layer. The next timer sends an empty packet to the client at a certain time interval, and then the client returns the same empty packet. If the server does not receive the feedback packet sent by the client within a certain period of time, it can only be determined to be offline. All you need is send or recv, and if the result is zero, it will be dropped.
However, under a long connection, there may be no data exchange for a long time. In theory, the connection is always connected, but in practice, it is difficult to know what happens to the intermediate node. What is more fatal is that some nodes (firewalls) will automatically disconnect the connections where there is no data interaction within a certain period of time. At this time, we need our heartbeat to maintain long connection and keep alive. After learning about the disconnection, the server logic may need to do some things, such as data cleaning after disconnection, reconnection, of course, this is naturally done by the logic layer according to the requirements. Generally speaking, heartbeat packets are mainly used for keeping long connections alive and disconnecting. In general applications, it is better to determine the time between 30 and 40 seconds. If it is really demanding, it will be in 6-9 seconds.
The above is what the heartbeat mechanism is, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.