Method and device for sending information

文档序号:1558853 发布日期:2020-01-21 浏览:12次 中文

阅读说明:本技术 用于发送信息的方法及装置 (Method and device for sending information ) 是由 刘宇 李莅 于 2019-10-11 设计创作,主要内容包括:本公开的实施例公开了用于发送信息的方法及装置,涉及云计算领域。该方法的一具体实施方式包括:响应于缓冲队列中存在待发送包,将上述缓冲队列中的待发送包封装成信息包,将上述信息包发送至信息服务器;响应于接收到上述信息服务器发来的对应上述信息包的信息存储成功消息,向上述信息采集协程发送偏移标志更新指令。该实施方式实现了对日志信息的并行采集,提高了日志信息的采集效率。(The embodiment of the disclosure discloses a method and a device for sending information, and relates to the field of cloud computing. One embodiment of the method comprises: responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet, and sending the information packet to an information server; and sending an offset mark updating instruction to the information acquisition coroutine in response to receiving an information storage success message which is sent by the information server and corresponds to the information packet. The embodiment realizes the parallel collection of the log information and improves the collection efficiency of the log information.)

1. A method for transmitting information, comprising:

responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet, and sending the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition coroutine, and the information acquisition coroutine is used for acquiring information from a log file to be processed and packaging the acquired information into the packet to be sent;

and in response to receiving an information storage success message which is sent by the information server and corresponds to the information packet, sending an offset mark updating instruction to the information acquisition coroutine, wherein the offset mark updating instruction is used for indicating the information acquisition coroutine to acquire a starting point of information in the log file to be processed.

2. The method of claim 1, wherein the method further comprises:

in response to detecting at least one log file to be processed, setting an information acquisition coroutine and an information acquisition period of the information acquisition coroutine for each log file to be processed in the at least one log file to be processed.

3. The method according to claim 1, wherein the name of the package to be sent comprises a name of the log file to be processed and a name of an offset identifier, the offset identifier is used for marking a starting position of information to be read in the log file to be processed, and

the encapsulating the packets to be sent in the buffer queue into information packets includes:

dividing the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent, wherein the packets to be sent in the packet sequence to be sent belong to the same log file to be processed, and the packets to be sent in the packet sequence to be sent are sorted according to the names of the offset identifiers;

and for the packet sequence to be sent in the at least one packet sequence to be sent, encapsulating the packet to be sent in the packet sequence to be sent into an information packet, and setting an information packet name for the information packet.

4. The method of claim 3, wherein encapsulating the packets to be transmitted in the sequence of packets to be transmitted into information packets comprises:

and extracting packets to be sent from the packet sequence to be sent according to the sequence and encapsulating the packets to be sent into information packets.

5. The method of claim 3, wherein the setting of the packet name for the packet comprises:

and setting the name of the information packet according to the name of the offset identifier of the packet to be sent in the information packet.

6. The method of any one of claims 1 to 5, wherein the sending the information package to an information server comprises:

in response to the data volume of an information packet being greater than a data volume threshold, dividing the information packet into at least two sub-information packets not exceeding the data volume threshold;

and sending the sub-information packet of the at least two sub-information packets to an information server.

7. A method for transmitting information, comprising:

acquiring an offset identifier of a log file to be processed, wherein the offset identifier is used for marking the starting position of information to be read in the log file to be processed;

taking the information to be read indicated by the offset mark as an information starting point, and acquiring the information to be sent from the log file to be processed;

and packaging the information to be transmitted into a packet to be transmitted, and transmitting the packet to a buffer queue.

8. The method of claim 7, wherein the obtaining the offset identification of the log file to be processed comprises:

inquiring a log file to be processed at intervals of a set information acquisition period;

and responding to the updating information of the log file to be processed, and acquiring the offset identifier of the log file to be processed.

9. The method of claim 8, wherein the obtaining the offset identification of the pending log file comprises:

and acquiring the offset identifier of the log file to be processed in response to the fact that the information amount of the updated information is larger than a set information amount threshold.

10. The method of claim 7, wherein the information within the log file to be processed is provided with corresponding time information, and

the obtaining information to be sent from the log file to be processed by using the information to be read indicated by the offset mark as an information starting point includes:

and setting the information between the information starting point and the information end point as the information to be sent.

11. The method of claim 7, wherein the encapsulating the information to be transmitted into packets to be transmitted and transmitting the packets to a buffer queue comprises:

and encapsulating the offset identifier and the information to be sent into a packet to be sent, and setting a name for the packet to be sent, wherein the name comprises the name of the log file to be processed and the name of the offset identifier.

12. The method of any of claims 7 to 11, wherein the method further comprises:

and in response to receiving an offset mark updating instruction, setting an updating offset mark for the last piece of information corresponding to the information to be sent in the log file to be processed, wherein the updating offset mark is used for marking the starting position of the information to be read next time in the log file to be processed.

13. An apparatus for transmitting information, comprising:

the first information sending unit is used for responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet and sending the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition protocol, and the information acquisition protocol is used for acquiring information from a log file to be processed and packaging the acquired information into the packet to be sent;

and the second information sending unit is used for responding to the information storage success message which is sent by the information server and corresponds to the information packet, and is configured to send an offset mark updating instruction to the information acquisition coroutine, wherein the offset mark updating instruction is used for indicating a starting point of the information acquisition coroutine for acquiring the information in the log file to be processed.

14. The apparatus of claim 13, wherein the apparatus further comprises:

the information acquisition coroutine setting unit is used for responding to the detection of at least one log file to be processed and setting an information acquisition coroutine and an information acquisition period of the information acquisition coroutine for each log file to be processed in the at least one log file to be processed.

15. The apparatus according to claim 13, wherein the name of the package to be sent comprises a name of the log file to be processed and a name of an offset identifier, the offset identifier is used to mark a starting position of information to be read in the log file to be processed, and

the first information transmitting unit includes:

the sequence dividing unit is configured to divide the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent, wherein the packets to be sent in the packet sequence to be sent belong to the same log file to be processed, and the packets to be sent in the packet sequence to be sent are sorted according to the names of the offset identifiers;

and the information packet packaging subunit is configured to, for the packet sequence to be sent in the at least one packet sequence to be sent, package the packets to be sent in the packet sequence to be sent into information packets, and set information packet names for the information packets.

16. The apparatus of claim 15, wherein the packet encapsulation subunit comprises:

and the information packet encapsulation module is configured to extract the packets to be sent from the packet sequence to be sent in sequence and encapsulate the packets to be sent into information packets.

17. The apparatus of claim 15, wherein the packet encapsulation subunit comprises:

and the information packet name setting module is configured to set the information packet name for the information packet according to the name of the offset identifier of the to-be-sent information packet in the information packet.

18. The apparatus according to any one of claims 13 to 17, wherein the first information transmitting unit includes:

a packet dividing subunit configured to divide the packet into at least two sub-packets not exceeding a data amount threshold in response to a data amount of the packet being greater than the data amount threshold;

a first information sending subunit configured to send a sub-packet of the at least two sub-packets to an information server.

19. An apparatus for transmitting information, comprising:

the offset identification acquisition unit is configured to acquire an offset identification of the log file to be processed, wherein the offset identification is used for marking the starting position of information to be read in the log file to be processed;

the information to be sent acquisition unit is configured to take the information to be read indicated by the offset mark as an information starting point and acquire the information to be sent from the log file to be processed;

and the third information sending unit is configured to encapsulate the information to be sent into a packet to be sent and send the packet to be sent to a buffer queue.

20. The apparatus of claim 19, wherein the offset flag obtaining unit comprises:

the log query subunit is configured to query the log file to be processed at intervals of a set information acquisition period;

and the offset identifier acquisition subunit is used for responding to the updating information existing in the log file to be processed and is configured to acquire the offset identifier of the log file to be processed.

21. The apparatus of claim 20, wherein the offset identity acquisition subunit comprises:

and the offset identifier acquisition module is used for responding to the information quantity of the updating information being larger than a set information quantity threshold value and is configured to acquire the offset identifier of the log file to be processed.

22. The apparatus of claim 19, wherein information within the log file to be processed is provided with corresponding time information, and

the information acquiring unit to be transmitted includes:

and the to-be-sent information acquisition subunit is configured to use the to-be-read information indicated by the offset mark as an information starting point, use the last information of the time information in the to-be-processed log file as an information ending point, and set the information between the information starting point and the information ending point as to-be-sent information.

23. The apparatus of claim 19, wherein the third information transmitting unit comprises:

and the third information sending subunit is configured to encapsulate the offset identifier and the information to be sent into a packet to be sent, and set a name for the packet to be sent, where the name includes a name of the log file to be processed and a name of the offset identifier.

24. The apparatus of any one of claims 19 to 23, wherein the apparatus further comprises:

and the offset mark updating unit is used for responding to the received offset mark updating instruction and setting an updating offset mark for the last piece of information corresponding to the information to be sent in the log file to be processed, wherein the updating offset mark is used for marking the starting position of the information to be read next time in the log file to be processed.

25. An electronic device, comprising:

one or more processors;

a memory having one or more programs stored thereon,

the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of any of claims 1-6 or the method of any of claims 7-12.

26. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method of any one of claims 1 to 6 or the method of any one of claims 7 to 12.

Technical Field

The embodiment of the disclosure relates to the technical field of computers, in particular to a method and a device for sending information.

Background

The log file is a record file or a file set for recording system operation events on the terminal, and can be divided into an event log and a message log. The method has important roles in processing historical data, tracing diagnosis problems, understanding system activities and the like.

The server can acquire log data of a log file on the terminal and process data such as the running state and data analysis of the terminal through the log data.

Disclosure of Invention

The embodiment of the disclosure provides a method and a device for sending information.

In a first aspect, an embodiment of the present disclosure provides a method for transmitting information, where the method includes: responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet, and sending the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition coroutine, and the information acquisition coroutine is used for acquiring information from a log file to be processed and packaging the acquired information into the packet to be sent; and in response to receiving an information storage success message which is sent by the information server and corresponds to the information packet, sending an offset mark updating instruction to the information acquisition coroutine, wherein the offset mark updating instruction is used for indicating the information acquisition coroutine to acquire a starting point of information in the log file to be processed.

In some embodiments, the above method further comprises: and setting an information acquisition coroutine and an information acquisition period of the information acquisition coroutine for each log file to be processed in at least one log file to be processed in response to the detection of at least one log file to be processed.

In some embodiments, the encapsulating the to-be-sent packets in the buffer queue into packets includes: dividing the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent, wherein the packets to be sent in the packet sequence to be sent belong to the same log file to be processed, and the packets to be sent in the packet sequence to be sent are sorted according to the names of the offset identifiers; and for the packet sequence to be sent in the at least one packet sequence to be sent, encapsulating the packet to be sent in the packet sequence to be sent into an information packet, and setting an information packet name for the information packet.

In some embodiments, encapsulating the packets to be transmitted in the sequence of packets to be transmitted into information packets includes: and extracting packets to be sent from the packet sequence to be sent according to the sequence and encapsulating the packets to be sent into information packets.

In some embodiments, the setting the packet name for the packet includes: and setting the name of the information packet according to the name of the offset identifier of the packet to be sent in the information packet.

In some embodiments, the sending the information packet to an information server includes: in response to the data volume of a packet being greater than a data volume threshold, dividing the packet into at least two sub-packets not exceeding the data volume threshold; and sending the sub-information packet of the at least two sub-information packets to an information server.

In a second aspect, an embodiment of the present disclosure provides a method for transmitting information, the method including: acquiring an offset identifier of a log file to be processed, wherein the offset identifier is used for marking the starting position of information to be read in the log file to be processed; taking the information to be read indicated by the offset mark as an information starting point, and acquiring the information to be sent from the log file to be processed; and encapsulating the information to be transmitted into a packet to be transmitted and transmitting the packet to a buffer queue.

In some embodiments, the obtaining the offset identifier of the log file to be processed includes: inquiring a log file to be processed at intervals of a set information acquisition period; and responding to the updating information of the log file to be processed, and acquiring the offset identifier of the log file to be processed.

In some embodiments, the obtaining the offset identifier of the log file to be processed includes: and acquiring the offset identifier of the log file to be processed in response to the fact that the information amount of the updated information is larger than a set information amount threshold.

In some embodiments, the setting of the information in the log file to be processed with corresponding time information, and the obtaining of the information to be sent from the log file to be processed with the information to be read indicated by the offset flag as an information starting point includes: and setting the information between the information starting point and the information end point as the information to be transmitted.

In some embodiments, the encapsulating the information to be transmitted into a packet to be transmitted and transmitting the packet to a buffer queue includes: and encapsulating the offset identifier and the information to be sent into a packet to be sent, and setting a name for the packet to be sent, wherein the name comprises the name of the log file to be processed and the name of the offset identifier.

In some embodiments, the above method further comprises: and in response to receiving an offset mark updating instruction, setting an updating offset mark for the last piece of information corresponding to the information to be sent in the log file to be processed, wherein the updating offset mark is used for marking the starting position of the next information to be read in the log file to be processed.

In a third aspect, an embodiment of the present disclosure provides an apparatus for transmitting information, the apparatus including: the first information sending unit is used for responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet and sending the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition protocol, and the information acquisition protocol is used for acquiring information from a log file to be processed and packaging the acquired information into the packet to be sent; and the second information sending unit is used for responding to the information storage success message which is sent by the information server and corresponds to the information packet, and is configured to send an offset mark updating instruction to the information acquisition protocol, wherein the offset mark updating instruction is used for indicating the information acquisition protocol to acquire the starting point of the information in the log file to be processed.

In some embodiments, the above apparatus further comprises: and the information acquisition coroutine setting unit is used for responding to the detection of at least one log file to be processed and setting an information acquisition coroutine and an information acquisition period of the information acquisition coroutine for each log file to be processed in the at least one log file to be processed.

In some embodiments, the name of the packet to be sent includes a name of the log file to be processed and a name of an offset identifier, where the offset identifier is used to mark a start position of information to be read in the log file to be processed, and the first information sending unit includes: a sequence dividing unit configured to divide the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent, wherein the packets to be sent in the packet sequence to be sent belong to the same log file to be processed, and the packets to be sent in the packet sequence to be sent are sorted according to the names of the offset identifiers; and the information packet packaging subunit is configured to, for the packet sequence to be sent in the at least one packet sequence to be sent, package the packets to be sent in the packet sequence to be sent into information packets, and set information packet names for the information packets.

In some embodiments, the packet encapsulation subunit includes: and the information packet encapsulation module is configured to extract the packets to be sent from the packet sequence to be sent according to the sequence and encapsulate the packets to be sent into the information packets.

In some embodiments, the packet encapsulation subunit includes: and the information packet name setting module is configured to set the information packet name for the information packet according to the name of the offset identifier of the to-be-sent information packet in the information packet.

In some embodiments, the first information sending unit includes: a packet dividing subunit, responsive to the data amount of a packet being greater than a data amount threshold, configured to divide the packet into at least two sub-packets not exceeding the data amount threshold; and the first information sending subunit is configured to send the sub-packet of the at least two sub-packets to the information server.

In a fourth aspect, an embodiment of the present disclosure provides an apparatus for transmitting information, the apparatus including: the offset identification acquisition unit is configured to acquire an offset identification of the log file to be processed, wherein the offset identification is used for marking the starting position of information to be read in the log file to be processed; the information to be sent acquisition unit is configured to take the information to be read indicated by the offset mark as an information starting point and acquire the information to be sent from the log file to be processed; and the third information sending unit is configured to encapsulate the information to be sent into a packet to be sent and send the packet to the buffer queue.

In some embodiments, the offset flag acquiring unit includes: the log query subunit is configured to query the log file to be processed at intervals of a set information acquisition period; and the offset identifier acquiring subunit is used for responding to the updating information existing in the log file to be processed and acquiring the offset identifier of the log file to be processed.

In some embodiments, the offset identifier obtaining subunit includes: and the offset identifier acquisition module is used for responding to the information quantity of the updated information being larger than a set information quantity threshold value and is configured to acquire the offset identifier of the log file to be processed.

In some embodiments, the information in the log file to be processed is provided with corresponding time information, and the information to be transmitted obtaining unit includes: and the to-be-sent information acquisition subunit is configured to use the to-be-read information indicated by the offset flag as an information starting point, use the last information of the time information in the to-be-processed log file as an information ending point, and set the information between the information starting point and the information ending point as to-be-sent information.

In some embodiments, the third information sending unit includes: and the third information sending subunit is configured to encapsulate the offset identifier and the information to be sent into a packet to be sent, and set a name for the packet to be sent, where the name includes a name of the log file to be processed and a name of the offset identifier.

In some embodiments, the above apparatus further comprises: and the offset mark updating unit is used for responding to the received offset mark updating instruction and setting an updating offset mark for the last piece of information corresponding to the information to be sent in the log file to be processed, wherein the updating offset mark is used for marking the starting position of the next information to be read in the log file to be processed.

In a fifth aspect, an embodiment of the present disclosure provides an electronic device, including: one or more processors; a memory having one or more programs stored thereon, which when executed by the one or more processors, cause the one or more processors to perform the method for transmitting information of the first aspect or the method for transmitting information of the second aspect.

In a sixth aspect, an embodiment of the present disclosure provides a computer-readable medium, on which a computer program is stored, wherein the program, when executed by a processor, implements the method for transmitting information of the first aspect or the method for transmitting information of the second aspect.

The method and the device for sending information provided by the embodiment of the disclosure firstly encapsulate a packet to be sent in a buffer queue into an information packet when the packet to be sent exists in the buffer queue, and send the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition coroutine, and the information acquisition coroutine is used for acquiring information from a log file to be processed and encapsulating the acquired information into the packet to be sent; and then when receiving an information storage success message which is sent by the information server and corresponds to the information packet, sending an offset mark updating instruction to the information acquisition coroutine, wherein the offset mark updating instruction is used for indicating the information acquisition coroutine to acquire a starting point of information in the log file to be processed. The method and the device can acquire the information of a plurality of log files to be processed simultaneously, realize the parallel acquisition of the log information and improve the acquisition efficiency of the log information.

Drawings

Other features, objects and advantages of the disclosure will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:

FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present disclosure may be applied;

FIG. 2 is a flow diagram for one embodiment of a method for transmitting information, according to the present disclosure;

FIG. 3 is a schematic diagram of one application scenario of a method for transmitting information according to the present disclosure;

FIG. 4 is a flow diagram of another embodiment of a method for transmitting information according to the present disclosure;

FIG. 5 is a schematic block diagram illustrating one embodiment of an apparatus for transmitting information according to the present disclosure;

FIG. 6 is a schematic block diagram illustrating another embodiment of an apparatus for transmitting information according to the present disclosure;

FIG. 7 is a schematic diagram of an electronic device suitable for use in implementing embodiments of the present disclosure.

Detailed Description

The present disclosure is described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.

It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.

Fig. 1 illustrates an exemplary system architecture 100 of a method for transmitting information or an apparatus for transmitting information to which embodiments of the present disclosure may be applied.

As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, a log collection device 105, and an information server 106. The network 104 is used to provide a medium for communication links between the terminal devices 101, 102, 103, the log collection device 105 and the information server 106. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.

The terminal devices 101, 102, 103 interact with the log collection device 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have various communication client applications installed thereon, such as a web browser application, a shopping application, a search application, an instant messaging tool, a mailbox client, social platform software, and the like.

The terminal apparatuses 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices having a display screen and supporting data processing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, mpeg compression standard Audio Layer 3), MP4 players (Moving Picture Experts Group Audio Layer IV, mpeg compression standard Audio Layer 4), laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented as a plurality of software or software modules (for example, for providing distributed services), or as a single software or software module, which is not specifically limited herein.

The log collection device 105 may be configured to set an information collection protocol for the log files on the terminal devices 101, 102, and 103, so as to collect data of the log files through the information collection protocol. The log collection device 105 may transmit the received log data to the information server 106.

It should be noted that the log collection device 105 may be hardware or software. When the log collection device 105 is hardware, it can be implemented as a distributed server cluster composed of multiple servers, or can be implemented as a single server. When the log collection device 105 is software, it may be implemented as a plurality of software or software modules (for example, to provide distributed services), or may be implemented as a single software or software module, and is not limited in particular.

The information server 106 may be a server providing various services, such as a server processing log data sent from the log collection device 105. The server may analyze and process the received data such as log data, and store the processing result in the server.

It should be noted that the method for sending information provided by the embodiment of the present disclosure is generally performed by the log collection device 105, and accordingly, the apparatus for sending information is generally disposed in the log collection device 105.

The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as a plurality of software or software modules (for example, to provide distributed services), or may be implemented as a single software or software module, and is not limited specifically herein.

It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.

With continued reference to fig. 2, a flow 200 of one embodiment of a method for transmitting information in accordance with the present disclosure is shown. The method for transmitting information includes the steps of:

step 201, in response to the existence of the packet to be sent in the buffer queue, encapsulating the packet to be sent in the buffer queue into an information packet, and sending the information packet to an information server.

In this embodiment, an execution main body (for example, the log collecting device 105 shown in fig. 1) of the method for sending information may receive, through a wired connection manner or a wireless connection manner, a packet to be sent, which is sent to a buffer sequence by an information collecting routine on the terminal devices 101, 102, and 103, where the buffer sequence is located on the execution main body and is used to store the packet to be sent. The packet to be sent comprises the information in the log file to be processed acquired by the information acquisition coroutine. It should be noted that the wireless connection means may include, but is not limited to, a 3G/4G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, a uwb (ultra wide band) connection, and other wireless connection means now known or developed in the future.

In the conventional log information collection method, although periodic collection of log information can be realized, the log information can only be read and processed by rows, and the log information cannot be efficiently pushed to the information server 106. In addition, in the existing log information collection method, a large number of small files are generated due to time intervals and the like in the process of collecting log information, and a plurality of log files on the same device cannot be collected in parallel.

When packets to be sent exist in a buffer queue on an execution main body, the packets to be sent in the buffer queue are packaged into information packets, and the information packets are sent to the information server 106. The execution main body does not send the packet to be sent to the information server when receiving each packet to be sent, but needs to package the packet to be sent into the information packet and then sends the information packet to the information server. The packaging process can effectively reduce the times and the quantity of sending packets to be sent, and effectively reduce the condition of small files. And the packet to be sent is sent to the buffer queue by the information acquisition coroutine. The information acquisition coroutine can be used for acquiring information from the log file to be processed and packaging the acquired information into a packet to be transmitted. The information collection coroutine may be a thread or a process running on a device where the log file to be processed is located, and is specifically set according to actual needs.

In some optional implementations of this embodiment, the method may further include: and setting an information acquisition coroutine and an information acquisition period of the information acquisition coroutine for each log file to be processed in at least one log file to be processed in response to the detection of at least one log file to be processed.

The execution agent may establish an information connection with a plurality of terminal apparatuses 101, 102, 103 at the same time and monitor the terminal apparatuses 101, 102, 103 for information changes. When the executing subject monitors that at least one new log file to be processed exists on the terminal devices 101, 102, and 103, an information acquisition protocol may be set for each log file to be processed in the at least one log file to be processed, respectively. For example, the executing entity may send an instruction to the terminal device 101, 102, 103, instructing the terminal device 101, 102, 103 to allocate a thread or a process for collecting log information corresponding to the log file to be processed. After receiving the instruction, the terminal devices 101, 102, and 103 allocate a thread or process dedicated to collecting information to the log file to be processed. Therefore, parallel information acquisition of a plurality of log files is realized. Then, the execution main body can further set an information acquisition period of an information acquisition coroutine, so that the information server 106 can acquire the log information more stably, network pressure caused by transmission of a large amount of short-time log information is avoided, and generation of small files is reduced.

In some optional implementation manners of this embodiment, the name of the packet to be sent may include a name of the log file to be processed and a name of an offset identifier, where the offset identifier is used to mark a start position of information to be read in the log file to be processed, and the encapsulating the packet to be sent in the buffer queue into an information packet may include the following steps:

the first step, dividing the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent.

The information collection routine may set a name for the name of the packet to be sent in order to mark the packet to be sent. The name of the packet to be sent may include the name of the log file to be processed and the name of the offset identifier. The offset mark is used for marking the starting position of information to be read in the log file to be processed in the information acquisition coroutine acquisition. The name of the offset identifier can be a line number of the log file to be processed and the like, and is used for representing the sequence of the information in the log file to be processed. As can be seen from the above description, the execution main body can obtain the packets to be sent of the multiple log files to be processed in parallel. In order to avoid information confusion during information transmission, the execution main body may further divide the packets to be sent in the buffer queue according to the names of the packets to be sent, so as to obtain at least one packet sequence to be sent. And the packets to be sent in the packet sequence to be sent belong to the same log file to be processed. The packets to be sent in the sequence of packets to be sent may be sorted by the name of the offset identifier.

The name of the offset identifier can represent the sequence of the information in the log file to be processed. Thus, the execution body may order the packets to be sent within the sequence of packets to be sent by the name identified by the offset. And the information acquisition coroutine acquires information in the log file to be processed according to the offset identifier and sends a packet to be sent. I.e. there is a coherent precedence order between each packet to be sent. Therefore, the packets to be transmitted in the sequence of packets to be transmitted obtained by the execution body are also continuous.

And secondly, for the packet sequence to be sent in the at least one packet sequence to be sent, encapsulating the packet to be sent in the packet sequence to be sent into an information packet, and setting an information packet name for the information packet.

The execution main body can encapsulate the packets to be sent in each packet sequence to avoid the packets to be sent of different log files to be processed being encapsulated together. In this way, it is also convenient to set the packet name for the packet.

In some optional implementation manners of this embodiment, the encapsulating the to-be-transmitted packets in the to-be-transmitted packet sequence into information packets may include: and extracting packets to be sent from the packet sequence to be sent according to the sequence and encapsulating the packets to be sent into information packets.

In order to avoid the information confusion, the execution main body may further extract the packets to be transmitted from the packet sequence to be transmitted in sequence and encapsulate the packets into the information packets.

In some optional implementation manners of this embodiment, the setting a packet name for the packet may include: and setting the name of the information packet according to the name of the offset identifier of the packet to be sent in the information packet.

The execution main body can also set the name of the information packet according to the name of the offset identifier of the packet to be sent in the information packet. For example, the information packet includes three packets to be transmitted. The names of the three packets to be sent may be: file 1-line 50; file 1-line 150; file 1-line 300. Wherein, the 'file 1' is the name of the log file to be processed; the "50 th row", "150 th row" and "300 th row" may be names identified by the offset. The packet name may be: file 1-lines 50-300.

In some optional implementation manners of this embodiment, the sending the information packet to the information server may include the following steps:

in a first step, in response to the data amount of a packet being greater than a data amount threshold, the packet is divided into at least two sub-packets not exceeding the data amount threshold.

In order to ensure the success rate of sending the information packet to the information server each time, the execution main body may limit the data amount of the information packet according to the data amount threshold. When the data amount of the packet is greater than the data amount threshold, the execution body may divide the packet into at least two sub-packets not exceeding the data amount threshold. For example, the packet name may be: in file 1, lines 50-300, the names of the two sub-packets obtained by dividing may be: "File 1-lines 50-300-package 1" and "File 1-lines 50-300-package 2".

And secondly, sending the sub-information packet of the at least two sub-information packets to an information server.

Thereafter, the execution body may transmit the sub packets to the information server in the divided order.

Step 202, in response to receiving the information storage success message corresponding to the information packet sent by the information server, sending an offset flag update instruction to the information collection coroutine.

When the information server receives the information packet and stores the information packet, the information server can send an information storage success message to the execution main body. I.e. the information storage success message is used to characterize that the information packet has been successfully stored by the information server. After receiving the information storage success message, the execution main body can send an offset mark updating instruction to the information acquisition coroutine. After the information acquisition coroutine receives the offset mark updating instruction, the position for acquiring the information in the log file to be processed can be modified so as to avoid repeatedly acquiring the information. That is, the offset flag update instruction may be used to instruct the information collection routine to collect a starting point of information in the log file to be processed.

With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of the method for transmitting information according to the present embodiment. In the application scenario of fig. 3, a buffer queue of the log collection device 105 has a packet to be sent of the terminal device 102 collected by the information collection coroutine 1 and a packet to be sent of the terminal device 103 collected by the information collection coroutine 2. The log collection device 105 may encapsulate the packet to be sent into a packet, and then send the packet to the information server 106. When the log collection device 105 receives the information storage success message sent by the information server 106, it indicates that the information packet sent by the log collection device 105 has been successfully stored by the information server 106. The log collection device 105 may send an offset flag update instruction to the information collection coroutine 1 and the information collection coroutine 2, and instruct the information collection coroutine 1 and the information collection coroutine 2 to adjust a next collection starting point of the log file to be processed on the terminal device 102 and the terminal device 103.

The method provided by the embodiment of the present disclosure includes first encapsulating packets to be sent in a buffer queue into information packets when the packets to be sent exist in the buffer queue, and sending the information packets to an information server; and then when receiving the information storage success message which is sent by the information server and corresponds to the information packet, sending an offset mark updating instruction to the information acquisition coroutine. The method and the device can acquire the information of a plurality of log files to be processed simultaneously, realize the parallel acquisition of the log information and improve the acquisition efficiency of the log information.

With further reference to fig. 4, a flow 400 of yet another embodiment of a method for transmitting information is shown. The process 400 of the method for transmitting information includes the steps of:

step 401, obtaining an offset identifier of a log file to be processed.

In this embodiment, an executing body (for example, the terminal devices 101, 102, 103 shown in fig. 1) of the method for sending information may first acquire an offset identifier of a log file to be processed through an information acquisition protocol before acquiring information of the log file to be processed. The offset mark is used for marking the starting position of the information to be read in the log file to be processed.

In some optional implementation manners of this embodiment, the obtaining the offset identifier of the log file to be processed may include the following steps:

firstly, inquiring a log file to be processed at intervals of a set information acquisition period.

The change condition of the information in the log file to be processed is not determined. In order to collect information in the log file to be processed in time, the information server 106 is prevented from collecting information after a large amount of new information appears in the log file to be processed, and the log information cannot be obtained in time. The execution main body can inquire the log file to be processed at intervals of set information acquisition period.

And secondly, responding to the updating information of the log file to be processed, and acquiring the offset identifier of the log file to be processed.

When the log file to be processed has updated information (i.e., information that has not been collected by the information collection protocol), the execution main body may obtain the offset identifier of the log file to be processed.

In some optional implementation manners of this embodiment, the obtaining the offset identifier of the log file to be processed may include: and acquiring the offset identifier of the log file to be processed in response to the fact that the information amount of the updated information is larger than a set information amount threshold.

If the amount of the update information is small, the execution body may not update the update information, so as to avoid excessively sending packets to be sent with small amount of information. When the information amount of the updated information is greater than the set information amount threshold, the execution subject may obtain the offset identifier of the log file to be processed, so as to collect the information in the log file to be processed.

Step 402, taking the information to be read indicated by the offset mark as an information starting point, and acquiring the information to be sent from the log file to be processed.

The offset identifier is used for marking the starting position of the information to be read in the log file to be processed, and the execution main body can take the information to be read indicated by the offset identifier as the starting point of the information and acquire the information to be sent from the log file to be processed.

In some optional implementation manners of this embodiment, the setting of corresponding time information in the log file to be processed, and taking the information to be read indicated by the offset flag as an information starting point, and acquiring the information to be transmitted from the log file to be processed may include: and setting the information between the information starting point and the information end point as the information to be transmitted.

The information in the log file to be processed is usually provided with corresponding time information to mark the occurrence time of the information. For this purpose, the execution main body may set information to be read indicated by the offset flag as information start point, information of the last information of the time information in the log file to be processed as information end point, and information between the information start point and the information end point as information to be transmitted.

And step 403, encapsulating the information to be transmitted into a packet to be transmitted, and transmitting the packet to a buffer queue of the terminal.

After reading the information to be read, the execution main body may encapsulate the information to be transmitted into packets to be transmitted, and transmit the packets to the buffer queue of the log collection device 105.

In some optional implementation manners of this embodiment, the encapsulating the information to be transmitted into a packet to be transmitted, and transmitting the packet to a buffer queue may include: and encapsulating the offset identifier and the information to be sent into a packet to be sent, and setting a name for the packet to be sent.

In order to facilitate operations such as archiving log information by the information server 106, the executing entity may encapsulate the offset identifier and the information to be sent into a packet to be sent, and set a name for the packet to be sent. The name may include a name of the to-be-processed log file and a name of the offset identifier.

In some optional implementations of this embodiment, the method may further include: and in response to receiving an offset mark updating instruction, setting an updating offset mark for the last piece of information corresponding to the information to be sent in the log file to be processed.

When the information server 106 receives the corresponding information, it will send a message of successful information storage to the log collecting device 105. Thereafter, the log collection device 105 sends an offset flag update instruction to the execution body. After receiving the offset flag update instruction, the execution main body may set an update offset flag for the last piece of information in the to-be-processed log file, which corresponds to the to-be-transmitted information. The update offset flag may be used to mark a starting position of information to be read next time in the log file to be processed.

With further reference to fig. 5, as an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of an apparatus for sending information, which corresponds to the method embodiment shown in fig. 2, and which is particularly applicable in various electronic devices.

As shown in fig. 5, the apparatus 500 for transmitting information of the present embodiment may include: a first information transmitting unit 501 and a second information transmitting unit 502. The first information sending unit 501, in response to a packet to be sent existing in a buffer queue, packages the packet to be sent in the buffer queue into an information packet, and is configured to send the information packet to an information server, where the packet to be sent is sent to the buffer queue by an information acquisition coroutine, and the information acquisition coroutine is used to acquire information from a log file to be processed and package the acquired information into the packet to be sent; the second information sending unit 502, in response to receiving the information storage success message sent by the information server and corresponding to the information packet, is configured to send an offset flag updating instruction to the information collection routine, where the offset flag updating instruction is used to instruct the information collection routine to collect a starting point of information in the log file to be processed.

In some optional implementations of this embodiment, the apparatus 500 for sending information may further include: an information collection coroutine setting unit (not shown in the figures) configured to set an information collection coroutine and an information collection period of the information collection coroutine for each of at least one to-be-processed log file in response to detecting the at least one to-be-processed log file.

In some optional implementation manners of this embodiment, the name of the to-be-sent package includes a name of the to-be-processed log file and a name of an offset identifier, where the offset identifier is used to mark a starting position of information to be read in the to-be-processed log file, and

the first information sending unit 501 may include: a sequence dividing subunit (not shown) and a packet encapsulating subunit (not shown). The sequence dividing unit is configured to divide the packets to be sent in the buffer queue according to the names of the packets to be sent to obtain at least one packet sequence to be sent, wherein the packets to be sent in the packet sequence to be sent belong to the same log file to be processed, and the packets to be sent in the packet sequence to be sent are sorted according to the names of the offset identifiers; and the information packet packaging subunit is configured to, for the packet sequence to be sent in the at least one packet sequence to be sent, package the packets to be sent in the packet sequence to be sent into information packets, and set information packet names for the information packets.

In some optional implementation manners of this embodiment, the packet encapsulation subunit may include: and a packet encapsulation module (not shown in the figure) configured to extract packets to be sent from the packet sequence to be sent in sequence and encapsulate the packets into packets.

In some optional implementation manners of this embodiment, the packet encapsulation subunit may include: and a packet name setting module (not shown in the figure) configured to set a packet name for the packet according to the name of the offset identifier of the packet to be sent in the packet.

In some optional implementation manners of this embodiment, the first information sending unit 501 may include: a packet dividing subunit (not shown in the figure) and a first information transmitting subunit (not shown in the figure). The information packet dividing subunit is used for dividing the information packet into at least two sub-information packets which do not exceed the data quantity threshold value in response to the data quantity of the information packet being larger than the data quantity threshold value; the first information sending subunit is configured to send a sub-packet of the at least two sub-packets to the information server.

With further reference to fig. 6, as an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of an apparatus for sending information, which corresponds to the method embodiment shown in fig. 4, and which is particularly applicable in various electronic devices.

As shown in fig. 6, the apparatus 600 for transmitting information of the present embodiment may include: an offset flag acquisition unit 601, a to-be-transmitted information acquisition unit 602, and a third information transmission unit 603. The offset identifier acquiring unit 601 is configured to acquire an offset identifier of a log file to be processed, where the offset identifier is used to mark a starting position of information to be read in the log file to be processed; an information to be sent obtaining unit 602, configured to obtain information to be sent from the log file to be processed by using the information to be read indicated by the offset flag as an information starting point; a third information sending unit 603, configured to encapsulate the information to be sent into a packet to be sent, and send the packet to the buffer queue.

In some optional implementation manners of this embodiment, the offset identifier obtaining unit 601 may include: a log query subunit (not shown in the figure) and an offset flag acquisition subunit (not shown in the figure). The log query subunit is configured to query the log file to be processed at intervals of a set information acquisition period; and the offset identifier acquiring subunit is used for responding to the updating information existing in the log file to be processed and acquiring the offset identifier of the log file to be processed.

In some optional implementation manners of this embodiment, the offset identifier obtaining subunit may include: and an offset identifier obtaining module (not shown in the figure) configured to obtain an offset identifier of the log file to be processed in response to the information amount of the update information being greater than a set information amount threshold.

In some optional implementation manners of this embodiment, the information in the log file to be processed is provided with corresponding time information, and the to-be-transmitted information obtaining unit 602 may include: a to-be-transmitted information acquiring subunit (not shown in the figure) configured to set the information to be read indicated by the offset flag as an information start point, the information of the last time information in the to-be-processed log file as an information end point, and the information between the information start point and the information end point as to-be-transmitted information.

In some optional implementation manners of this embodiment, the third information sending unit 603 may include: and a third information sending subunit (not shown in the figure), configured to encapsulate the offset identifier and the information to be sent into a packet to be sent, and set a name for the packet to be sent, where the name includes a name of the log file to be processed and a name of the offset identifier.

In some optional implementations of this embodiment, the apparatus 600 for sending information may further include: an offset flag updating unit (not shown in the figure), in response to receiving an offset flag updating instruction, is configured to set an update offset flag for marking a starting point position of information to be read next time in the log file to be processed, for a last piece of information in the log file to be processed, which corresponds to the information to be transmitted.

The present embodiment also provides an electronic device, including: one or more processors; a memory having one or more programs stored thereon, which when executed by the one or more processors, cause the one or more processors to perform the above-described method for transmitting information.

The present embodiment also provides a computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the above-mentioned method for transmitting information.

Referring now to FIG. 7, a block diagram of a computer system 700 suitable for use with an electronic device (e.g., log collection device 105 of FIG. 1) implementing embodiments of the present disclosure is shown. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.

As shown in fig. 7, electronic device 700 may include a processing means (e.g., central processing unit, graphics processor, etc.) 701 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)702 or a program loaded from storage 708 into a Random Access Memory (RAM) 703. In the RAM 703, various programs and data necessary for the operation of the electronic apparatus 700 are also stored. The processing device 701, the ROM 702, and the RAM 703 are connected to each other by a bus 704. An input/output (I/O) interface 705 is also connected to bus 704.

Generally, the following devices may be connected to the I/O interface 705: input devices 706 including, for example, a touch screen, touch pad, keyboard, mouse, camera, microphone, accelerometer, gyroscope, etc.; an output device 707 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 708 including, for example, magnetic tape, hard disk, etc.; and a communication device 709. The communication means 709 may allow the electronic device 700 to communicate wirelessly or by wire with other devices to exchange data. While fig. 7 illustrates an electronic device 700 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 7 may represent one device or may represent multiple devices as desired.

In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such embodiments, the computer program may be downloaded and installed from a network via the communication means 709, or may be installed from the storage means 708, or may be installed from the ROM 702. The computer program, when executed by the processing device 701, performs the above-described functions defined in the methods of embodiments of the present disclosure.

It should be noted that the computer readable medium mentioned above in the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In embodiments of the disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In embodiments of the present disclosure, however, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (radio frequency), etc., or any suitable combination of the foregoing.

The computer readable medium may be embodied in the electronic device; or may exist separately without being assembled into the electronic device. The computer readable medium carries one or more programs which, when executed by the electronic device, cause the electronic device to: responding to the existence of a packet to be sent in a buffer queue, packaging the packet to be sent in the buffer queue into an information packet, and sending the information packet to an information server, wherein the packet to be sent is sent to the buffer queue by an information acquisition coroutine, and the information acquisition coroutine is used for acquiring information from a log file to be processed and packaging the acquired information into the packet to be sent; and in response to receiving an information storage success message which is sent by the information server and corresponds to the information packet, sending an offset mark updating instruction to the information acquisition coroutine, wherein the offset mark updating instruction is used for indicating the information acquisition coroutine to acquire a starting point of information in the log file to be processed.

Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).

The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.

The units described in the embodiments of the present disclosure may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a first information transmitting unit and a second information transmitting unit. Here, the names of these units do not constitute a limitation to the unit itself in some cases, and for example, the first information transmission unit may also be described as "a unit for transmitting log information to an information server".

The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention in the present disclosure is not limited to the specific combination of the above-mentioned features, but also encompasses other embodiments in which any combination of the above-mentioned features or their equivalents is possible without departing from the inventive concept as defined above. For example, the above features and (but not limited to) the features disclosed in this disclosure having similar functions are replaced with each other to form the technical solution.

21页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种基于DPDK的数据包处理方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!