The importance and implementation principle of transmitting network communication merged data

Source: Internet
Author: User

In network communication, information broadcasting and forwarding are often used, and QQ group chat is commonly used. People in the Group send a message to other people in the group. However, the forwarding volume is very small. Generally, the user's socket is used directly. the send method can be sent out. But in some cases, you are not allowed to do so. Why? In some scenarios, the forwarding volume and density of such information are very high, and the number can reach 10 W, 20 W, 50 W, W or more, maybe your server has a good performance of 10 w I/O per second. What about one w or more message forwarding? Someone may ask if there are so many forwarding requests. In fact, for 500 of users in the same field, each user has two behavior changes per second on average, which is enough to generate a million forwarding requests.

From the figure above, we can see that the interaction between users is always on the server, and the interaction of information is like this every second, so that there are 6 Tight lines. What if it is 500 or 1000? What is the situation. Therefore, it is impossible to eat the information from the IO throughput quantity.

What we need to do to address the above situation is to control Io. Some friends may have problems with how to control it. Is it hard to send it? In fact, it is very easy to do control. In fact, you only need to use fixed resources to do some things. When the loss of work exceeds the rated resources, let him wait.

The number of I/O processes can be controlled through the thread queue. When there is no heap pressure in the queue, there are generally the following situations: 1 threads have enough resources to complete these tasks, 2. There are not many messages you need to forward, which does not constitute a pressure on the queue. In fact, these situations do not need to be merged, because the processing does not store Io pressure.

When the queue is under pressure, the thread does not have enough resources to process a large number of Io operations. At this time, we need to do some additional work to send data merging, reducing the IO pressure.

Take out all the data in the current queue for a merge operation, and then send it again. Throughout the process, the performance of memory operations is much higher than that of network I/O processing. If the implementation of this process consumes more resources than I/O, check the implementation method carefully. This is not the case.

The latency of the above method is very optimistic, and it can decide whether to merge data based on the current resource usage. When your server resources are satisfied, but the latency is a little high, you can use multiple queues to handle the problem and share the pressure on other threads to achieve a short latency.

In practical application tests, due to limited network bandwidth, only 500 objects are tested in the same scenario. Two changes are generated for each object per second, and the actual broadcast information is 50 W per second, sending Io is about million per second. Core e4300 consumes about 25% of the CPU, uses 60 MB of memory, and bandwidth is 80 Mbps. The latency is about 60 ms.

The forwarding information structure is as follows:

Class Po: iMessage {public int ID; Public short X; Public short Y; Public short type; Public void load (bufferreader reader) {id = reader. readint32 (); X = reader. readint16 (); y = reader. readint16 (); type = reader. readint16 ();} public void save (bufferwriter writer) {writer. write (ID); writer. write (x); writer. write (y); writer. write (type );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.