CN111651286A - Data communication method, device, computing equipment and storage medium - Google Patents
Data communication method, device, computing equipment and storage medium Download PDFInfo
- Publication number
- CN111651286A CN111651286A CN202010463557.4A CN202010463557A CN111651286A CN 111651286 A CN111651286 A CN 111651286A CN 202010463557 A CN202010463557 A CN 202010463557A CN 111651286 A CN111651286 A CN 111651286A
- Authority
- CN
- China
- Prior art keywords
- message
- memory
- shared
- address
- shared memory
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/544—Buffers; Shared memory; Pipes
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a data communication method, a device, a computing device and a storage medium, which relate to the technical field of computers, and the method is applied to the communication between a message production process and a message consumption process, wherein the message production process is used for writing messages, the message consumption process is used for reading the messages, and shared objects are created in a shared memory; and, real-time maintaining the address file in the shared memory; the address file comprises respective memory addresses and online quantities of a current head message and a current tail message of the shared object; the online number is used for indicating whether an accessed process exists in the shared memory; and performing access management on the processes accessing the shared memory according to the online quantity. The information is written and/or read in the shared memory through the address file, data communication is achieved, and compared with the shared data distributed through the middleware, the efficiency of data communication is improved.
Description
Technical Field
The present application relates to the field of computer technologies, and in particular, to a data communication method and apparatus, a computing device, and a storage medium.
Background
In the related art, an operating system includes not only one process running, but also unavoidable data communication among multiple processes, data communication among the processes usually transmits data through a message middleware, data communication needs to be realized through distribution of the message middleware when each process performs data communication, and a physical interface corresponding to an address of each process needs to be acquired when the message middleware performs data distribution, and data distribution is performed after the acquisition is successful.
Therefore, it is known that it takes time and labor to transmit messages through the message middleware, and the efficiency of data communication between programs is reduced when the message middleware is abnormal.
Based on this, a new data communication method is needed to solve the above problems.
Disclosure of Invention
The embodiment of the application provides a data communication method and device, a computing device and a storage medium, which are used for solving the problem of low data communication efficiency in the related technology.
In a first aspect, an embodiment of the present application provides a data communication method, applied to communication between a message production process and a message consumption process, where the message production process is used to write a message, and the message consumption process is used to read a message, and the method includes:
creating a shared object in a shared memory; and maintaining an address file in the shared memory in real time; the address file comprises respective memory addresses and online quantities of the current head message and the current tail message of the shared object; the online number is used for indicating whether an accessed process exists in the shared memory; performing access management on the processes accessing the shared memory according to the online quantity; the message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file; and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
Optionally, at any time point, the access process of the shared memory is the message production process or the message consumption process; if the online quantity is a first preset value, it indicates that there is no process accessed in the shared memory, and other processes can access the shared memory; if the online quantity is a second preset value, the process is accessed in the shared memory, and other processes can not access the shared memory;
optionally, when it is determined that an abnormal condition occurs in the process that has accessed the shared memory, releasing the process that has accessed the shared memory from the shared memory, and updating the online quantity from the second preset value to the first preset value; wherein the abnormal condition comprises: and the process accessed to the shared memory fails to acquire the designated information.
Optionally, the address file further includes: memory capacity status of the shared object; and the memory capacity state is used for indicating whether the process accessed to the shared memory is allowed to carry out read-write operation on the shared memory.
Optionally, the messages in the shared memory are stored based on a cyclic address; a memory capacity status determined based on the cyclic address after writing or reading the message; updating the address file based on the determined memory capacity status.
Optionally, the memory capacity status of the shared object includes: a first preset state, a second preset state and a third preset state; when the memory address of the current head message is the same as the memory address of the current tail message, determining that the memory capacity state is the first preset state; when the next address of the memory address of the current tail message is the memory address of the current head message, determining that the memory capacity state is the second preset state; and when the memory address of the current tail message is different from the memory address of the current head message, and the next address of the memory address of the current tail message is not the memory address of the current head message, determining that the memory capacity state is the third preset state.
Optionally, if the memory capacity state of the shared object is the first preset state or the third preset state, it indicates that the message production process is allowed to write a message in the shared object; and if the memory capacity state of the shared object is the second preset state or the third preset state, indicating that a message consumption process is allowed to read the message in the shared object.
In a second aspect, an embodiment of the present application provides a data communication apparatus, configured to communicate between a message production process and a message consumption process, where the message production process is used to write a message, and the message consumption process is used to read the message, and the apparatus includes: the system comprises a creating module, a maintaining module and a managing module;
the creating module is used for creating a shared object in the shared memory; the maintenance module is used for maintaining the address file in the shared memory in real time; the address file comprises respective memory addresses of a current head message and a current tail message of the shared object, respective memory addresses of the current tail message and online quantity; the online number is used for indicating whether an accessed process exists in the shared memory; the management module is used for carrying out access management on the processes accessing the shared memory according to the online quantity; the message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file; and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
Optionally, at any time point, the access process of the shared memory is the message production process or the message consumption process; if the online quantity is a first preset value, it indicates that there is no process accessed in the shared memory, and other processes can access the shared memory; if the online quantity is a second preset value, the process is accessed in the shared memory, and other processes can not access the shared memory;
optionally, the apparatus further comprises: an abnormal condition determining module, configured to release the process accessed to the shared memory in the shared memory and update the online quantity from the second preset value to the first preset value when it is determined that an abnormal condition occurs in the process accessed to the shared memory; wherein the abnormal condition comprises: and the process accessed to the shared memory fails to acquire the designated information.
Optionally, the address file further includes: memory capacity status of the shared object; and the memory capacity state is used for indicating whether the process accessed to the shared memory is allowed to carry out read-write operation on the shared memory.
Optionally, the messages in the shared memory are stored based on a cyclic address; the maintenance module is specifically configured to: a memory capacity status determined based on the cyclic address after writing or reading the message; updating the address file based on the determined memory capacity state;
optionally, the memory capacity status of the shared object includes: a first preset state, a second preset state and a third preset state; when the memory address of the current head message is the same as the memory address of the current tail message, determining that the memory capacity state is the first preset state; when the next address of the memory address of the current tail message is the memory address of the current head message, determining that the memory capacity state is the second preset state; and when the memory address of the current tail message is different from the memory address of the current head message, and the next address of the memory address of the current tail message is not the memory address of the current head message, determining that the memory capacity state is the third preset state.
Optionally, the apparatus further comprises: the message processing module is configured to indicate that a message production process is allowed to write a message in the shared object if the memory capacity state of the shared object is the first preset state or the third preset state; and if the memory capacity state of the shared object is the second preset state or the third preset state, indicating that a message consumption process is allowed to read the message in the shared object.
In a third aspect, an embodiment of the present application further provides a computing device, including:
a memory and a processor;
a memory for storing program instructions;
a processor for invoking program instructions stored in said memory, according to the data communication method of the first aspect of the obtained program.
In a fourth aspect, the present application further provides a computer storage medium, where the computer storage medium stores computer-executable instructions, and the computer-executable instructions are configured to cause a computer to execute any data communication method in the present application.
According to the data communication method and device, the computing equipment and the storage medium, a shared object is created in a shared memory; then maintaining the address file in the shared memory in real time; the address file comprises respective memory addresses and online quantities of a current head message and a current tail message of the shared object; the online quantity is used for indicating whether an accessed process exists in the shared memory; and then carrying out access management on the processes accessing the shared memory according to the online quantity. The message production process writes the new message into the shared object according to the memory address of the current tail message in the address file; and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file. The information is written and/or read in the shared memory through the address file, data communication is achieved, and compared with the method that data sharing is achieved through middleware distribution, the data communication efficiency is improved. In addition, because the online number is maintained in the address file, whether the access process exists in the shared memory can be determined based on the online number, the shared memory is managed based on the online number, and the shared memory does not need to be locked during data sharing.
Additional features and advantages of the application will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by the practice of the application. The objectives and other advantages of the application may be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments of the present invention will be briefly described below, and it is obvious that the drawings described below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a data communication method according to an embodiment of the present application;
fig. 2 is a schematic view of a storage structure of a shared memory according to an embodiment of the present disclosure;
fig. 3 is a schematic flowchart of a data communication method according to an embodiment of the present application;
fig. 4 is a schematic view of a storage structure of a shared memory according to an embodiment of the present disclosure;
fig. 5 is a schematic view of a storage structure of a shared memory according to an embodiment of the present disclosure;
FIG. 6 is a schematic structural diagram of a loop pointer provided in an embodiment of the present application;
fig. 7 is a schematic view of a storage structure of a shared memory according to an embodiment of the present disclosure;
fig. 8 is a schematic diagram of data communication provided in an embodiment of the present application;
fig. 9 is a schematic structural diagram of a data communication device according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a computing device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention.
As will be appreciated by one skilled in the art, aspects of the present application may be embodied as a system, method or program product. Accordingly, various aspects of the present application may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
As described in the background, in the related art, data communication is implemented through message middleware, such as: the message queue MQ. And when the message middleware is applied to data communication among the processes, the precision is high. However, under the condition that the operation and storage of the operating system are limited, the maintenance of the message middleware occupies a large amount of system resources, and the communication efficiency of data among the processes is reduced. In addition, in the related art, data communication is performed by copying memory information of each process, but the method occupies a large memory and is low in efficiency.
The inventor finds that, on the premise of not using message middleware, if it is desired to implement efficient data communication between processes through a shared memory, how to implement data communication between processes through the shared memory will be described in detail below with reference to the technical method of the present application.
Fig. 1 is a schematic diagram illustrating an application scenario of a data communication method according to an embodiment of the present application, where the schematic diagram includes a message production process, a message consumption process, and a shared memory. The message generating process and the message consuming process are processes which can execute operations in the same operating system and communicate data through the shared memory, the message generating process is used for writing messages, and the message consuming process is used for reading messages.
The shared memory is a virtual address space opened up for the operating system, the operating system maps the first byte of the address file to the first byte of the virtual address space, and the process can access the virtual address space. In the application, only a single process is allowed to execute the operation aiming at the message in the shared memory, that is, the multiple processes are not allowed to simultaneously perform the operation of the message in the shared memory, if one message production process writes the message in the shared memory, other message production processes are not allowed to write the message before the message production process finishes writing the message in the shared memory, and other message consuming processes are not allowed to read the message.
In order to enable the message production process and the message consumption process to better perform data communication, the storage of the message in the shared memory can be performed in the storage mode in fig. 2, and the data file represents a shared object which stores the specific content of the message. Meta metadata file indicates an address file storing respective memory addresses of a current header message and a current trailer message of message contents. The head address of the current message is indicated by a head field, the tail address of the current message is indicated by a tail field, the parameter value of the head field is the head message address of the message content storage in the data file, and the parameter value of the tail field is the tail message address of the message content storage in the data file. Each message may be stored in a data file using a fixed length, assuming a length of 1024, and the actual number of bytes of the current message that can be stored using the first 4 bytes, followed by the actual message content, then the maximum length of each message cannot exceed 1020 bytes. Messages with message lengths of 5 and 6 are shown in fig. 2, but in practical application, the fixed length data may be set according to practical requirements, and may also be set to 512, 2048, etc., and is not specifically limited herein.
The stored parameter values of the head field and the tail field in the meta metadata file are checked when the message production process and the message consumption process share data, and whether the message can be written or read is determined according to the parameter values. Assuming that the address of the preset memory space is 1-1000, and the stored parameter values of the head field and the tail field are 1 and 1000 respectively, it can be known that the message content of the data file is full, the message consumption process can read the message in the data file, the shared memory is released after the message is read, and the message production process can continue to write the message in the shared memory; the stored parameter values of the head field and the tail field are respectively 1 and 100, so that the message content of the data file stores data and has storage space, a message consumption process can read messages in the data file and release the corresponding memory space and update the stored parameter value of the head field in the meta metadata file, and a message production process can write messages in the data file and update the stored parameter value of the tail field in the meta metadata file.
In addition, assume that the operating system is a customer insurance policy compensation system, wherein the message production process is a policy to be applied for compensation filled in the insurance policy compensation system by a customer, and the message consumption process is an operation of reading compensation items of the policy and performing corresponding compensation for the staff of the insurance company. Such as: the method comprises the steps that a client 1 applies for policy and compensation, a message of the client applying for policy and compensation is written into a shared memory, a data file is updated, stored parameter values of a head field and a tail field in a meta metadata file are updated, a worker 1 of an insurance company looks up the stored parameter values of the head field and the tail field in the meta metadata file in the shared memory to find that the message of the client applying for policy and compensation exists in the shared memory, then compensation processing operation is conducted on the message of the client applying for policy and compensation, and corresponding memory space in the data file is released.
By the method, the communication between the message production process and the message consumption process can be realized, the time wasted by the message middleware for acquiring the physical interfaces corresponding to the addresses of the processes during message distribution can be avoided, the memory data can be shared only in the virtual space, and the communication efficiency of the data is improved.
Based on this, the data communication method provided by the present application may be executed through the operation steps in fig. 3, and the method is applied to communication between a message production process and a message consumption process, and may first execute step 301: a shared object is created in the shared memory.
Step 302: maintaining an address file in a shared memory in real time; the address file comprises respective memory addresses and online quantities of the current head message and the current tail message of the shared object; the online number is used for indicating whether an accessed process exists in the shared memory.
Step 303: and performing access management on the processes accessing the shared memory according to the online quantity.
The dynamic change of the shared object in the shared memory can be accurately obtained by the operating system through maintaining the address file in real time, so that the message process can be better configured to process the message, and the data communication efficiency is improved.
The message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file; and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
It should be noted that, it is assumed that, when the message production process 1 writes the message 1 in the shared memory and updates the memory address of the current tail message to be 10, the message production process 2 writes the message 2 in the shared memory and updates the memory address of the current tail message to be 15. Because the message 1 is a message written first, the message consumption process reads the message 1 written by the message production process 1 first, after the message 1 is read, the memory address of the current head message is updated, then the message 2 written by the message production process is read, and after the message 2 is read, the memory address of the current head message is updated.
By the method, the messages written first are processed first, the messages in the shared memory can be read and written in sequence, and the messages are processed in sequence between the message production process and the message consumption process, so that the messages are processed more orderly, and the efficiency of data communication is improved.
In addition, the address file maintains: the number of lines; the online number is used for indicating whether an accessed process exists in the shared memory, and the access management is carried out on the process accessed to the shared memory according to the online number, wherein in one embodiment, at any time point, the access process of the shared memory is a message production process or a message consumption process; fig. 4 is a view for adding a connectCount field for indicating the number of online on the meta metadata file on the basis of fig. 2.
If the online number is the first preset value, it indicates that there is no process accessed in the shared memory, and other processes may access the shared memory.
If the online number is a second preset value, it indicates that a process is accessed in the shared memory, and other processes cannot access the shared memory, in this application, the second preset value may be set to 1, that is, when the parameter value of the connecticcount field is 1, it may be determined that there is a message process processing message in the shared memory, and the message process processing message cannot be accessed in the shared memory, and after the message process has processed the message, the parameter value of the connecticcount field may be updated to 0, and then another message process processing message may be accessed in the shared memory.
By the method, whether the processes are processing the messages in the shared memory can be accurately known, and the execution time of the data communication among the processes can be obtained instead of waiting for the execution time of the data communication all the time, so that the data communication efficiency is improved. In addition, the shared memory is managed based on the online quantity, the value of the online quantity is only needed to be checked during data sharing, whether an access process exists in the shared memory is determined according to the value, data sharing is carried out based on the mode, locking processing does not need to be carried out in the shared memory, and the situation that a plurality of processes simultaneously process data in the shared memory cannot occur during data sharing.
In addition, when it is determined that an abnormal condition occurs in the process that has accessed the shared memory, the process that has accessed the shared memory is released in the shared memory, and the online quantity is updated from a second preset value to a first preset value, wherein the abnormal condition includes: and the process accessed to the shared memory fails to acquire the specified information.
As described above, the operating system is a customer insurance policy reimbursement system in which the designation information is the address of the user and the telephone number of the user. Accessing a message consumption process in the shared memory, finding that the address of the user and the telephone number of the user cannot be acquired when policy compensation is carried out, releasing the message consumption process in the shared memory if the policy compensation cannot be completed, informing a message production process applying the policy compensation that the claim is failed, and updating the online quantity to a first preset value.
In one embodiment, the address file further includes: memory capacity status of the shared object; the memory capacity state is used for indicating whether the process accessed to the shared memory is allowed to carry out read-write operation on the shared memory. Referring to the diagram of fig. 5, a state field is added to the meta metadata file to indicate the memory capacity status of the shared object. In addition, the messages in the shared memory are stored based on the cyclic address, as shown in fig. 6, it is assumed that the address space opened by the shared memory is 1000, and one piece of data includes 3 messages, and the storage address may start from the address space 1000, and take 1000 as the memory address of the head message of the current message, and take 2 as the memory address of the tail message of the current message.
It should be noted that the memory capacity status of the shared object includes: a first preset state, a second preset state and a third preset state; when the memory address of the current head message is the same as the memory address of the current tail message, the memory capacity state is determined to be the first preset state, that is, no message is written in the shared object.
And when the next address of the memory address of the current tail message is the memory address of the current head message, determining that the memory capacity state is a second preset state, and since the messages in the shared memory are stored based on the cyclic address, it can be known that the messages in the shared object are full.
When the memory address of the current tail message is different from the memory address of the current head message, and the next address of the memory address of the current tail message is not the memory address of the current head message, determining that the memory capacity state is a third preset state, namely that a message exists in the shared object, but the message is not written to the shared object.
After writing the message or reading the message, determining a memory capacity status based on the cyclic address, and updating the address file based on the determined memory capacity status.
If the memory capacity state of the shared object is the first preset state or the third preset state, it indicates that the message production process is allowed to write the message in the shared object, that is, the shared object has a storage space, so that the message production process can write the message.
If the memory capacity state of the shared object is the second preset state or the third preset state, it indicates that the message consumption process is allowed to read the message in the shared object, that is, the message written in the shared object already exists, so that the message consumption process can read the message.
Based on this, the message producing process and the message consuming process may perform data communication by way of data storage in the shared memory in fig. 7, and when the message producing process writes data in the shared memory, the message may be written after the memory address of the current tail message, and the parameter value of tail in the meta metadata file may be updated. When a message consuming process reads data in shared memory, the message may be read starting from the memory address of the current header message and updating the parameter value of the head in the meta metadata file.
Fig. 8 is a schematic diagram of data communication between a message production process and a message consumption process according to an embodiment of the present application, where the schematic diagram includes:
step S1 may be executed on the message production process side: when the message production process accesses the shared memory in advance to write in the message, determining a parameter value of the connecticcount field, and if the parameter value is 1, executing the step S2; if the parameter value is 0, the process proceeds to step S3.
Step S2: wait for the parameter value of the connecticcount field to be 0, go to step S3.
Step S3: determining a parameter value of the state field, and if the parameter value of the state field is in a first preset state, executing step S4; if the parameter value of the state field is in the second preset state, executing step S5; if the parameter value of the state field is the third preset state, executing step S6;
step S4: and writing a message into the data file, writing parameter values corresponding to a head address and a tail address corresponding to the message into a head field and a tail field of the meta original data file respectively, and updating the parameter values of a state field.
Step S5: waiting for the parameter value of the state field not to be in the second preset state, and executing step S4 if the parameter value of the state field is in the first preset state; if the parameter value of the state field is the third predetermined state, step S6 is executed.
Step S6: and writing the message into the data file, respectively writing the parameter values corresponding to the tail addresses corresponding to the message into the tail fields of the meta original data file, and updating the parameter values of the state fields.
Step C1 may be performed on the message consuming process side: when the message consumption process accesses the shared memory in advance to read the message, determining a parameter value of the connecticcount field, and if the parameter value is 1, executing the step C2; if the parameter value is 0, step C3 is performed.
Step C2: step C3 is executed while waiting for the parameter value of the connecticcount field to be 0.
Step C3: determining a parameter value of the state field, and if the parameter value of the state field is in a first preset state, executing step C4; if the parameter value of the state field is the second preset state or the third preset state, executing step C5;
step C4: if the parameter value of the wait state field is not in the first preset state, the step C5 is executed if the parameter value of the wait state field is in the second preset state or the third preset state.
Step C5: reading the message from the data file, writing the parameter value corresponding to the header address corresponding to the message into the head field of the meta original data file, and updating the parameter value of the state field.
The following description is given by way of a specific embodiment, and also with reference to the above operating system as a customer insurance policy reimbursement system, assuming that after a customer 1 fills in an insurance policy 1 for reimbursement on 11/00, first checking a parameter value of a connectCount field in an address file, if the parameter value is 1, a message process is processing a message in a shared memory, and waiting for the parameter value of the connectCount field in the shared memory to be 0, checking a parameter value of a state field, and if the parameter value is a first preset state or a third preset state, writing the reimbursement insurance policy in a shared object; and if the state is the second preset state, writing the indemnity insurance policy after the message in the shared object is read. If the indemnity insurance policy is the first piece of data in the shared object, updating parameter values of the head field and the tail field; if the claim insurance policy is not the first piece of data in the shared object, the parameter value in the tail field is updated to address 1, and the parameter value in the state field is updated.
If the client 2 fills in the insurance policy 2 for applying for reimbursement on 11/00, the flow is consistent with the flow of writing data in the shared memory by the client 1, if the parameter value of the state field is in the second preset state, the insurance policy for reimbursement is written in the shared object, and the memory address of the current tail message is the address 1 and is updated to the address 2.
The method comprises the steps that a worker of an insurance company firstly checks a parameter value of a connectCount field in an address file, if the parameter value of the connectCount field is 1, a message process is processing messages in a shared memory, the worker waits for the parameter value of the connectCount field in the shared memory to be 0, checks a parameter value of a state field, and if the parameter value is in a second preset state or a third preset state, reads an insurance policy 1 for indemnification in a shared object; if the status is the first preset status, after the message in the shared object is written, the compensated policy is read, the memory address of the current header message is updated, and the memory capacity status of the shared object is updated. And then reading the policy 2 in the shared memory according to the message reading process.
It should be noted that, in addition to applying the technical solutions mentioned in the present application, the present application may refer to the prior art that an CREATEFILEMAPPING () function is called first to create a named memory mapping object, the parameter value in the address file is read through the object, and then a UNMAPVIEWOFFILE () function is called to release the view mapping, thereby releasing the connection with the message production process of the shared memory.
In the application, except for applying the technical scheme mentioned in the application, the message reading in the shared memory can refer to the prior art that an OPENFILEMAPPING () function is called to open a memory mapping file object, the object reads the parameter value in the address file, and then a unmapped view file () function is called to release the view mapping and release the connection with the message consumption process of the shared memory.
By reading the parameter values in the address file, the message is processed in the shared memory, and the data communication efficiency can be improved.
Fig. 9 is a schematic structural diagram of a data communication apparatus according to an embodiment of the present application, configured to communicate between a message production process and a message consumption process, where the message production process is used to write a message, and the message consumption process is used to read the message, and the apparatus includes: a creation module 91, a maintenance module 92, and a management module 93.
A creating module 91, configured to create a shared object in the shared memory.
A maintenance module 92, configured to maintain an address file in the shared memory in real time; the address file comprises respective memory addresses of a current head message and a current tail message of the shared object, respective memory addresses of the current tail message and online quantity; the online number is used for indicating whether an accessed process exists in the shared memory.
And the management module 93 is configured to perform access management on the processes accessing the shared memory according to the online quantity.
The message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file; and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
The information is written and/or read in the shared memory through the address file, data communication is achieved, and compared with the method that data sharing is achieved through middleware distribution, the data communication efficiency is improved. In addition, because the online number is maintained in the address file, whether the access process exists in the shared memory can be determined based on the online number, the shared memory is managed based on the online number, and the shared memory does not need to be locked during data sharing.
In some possible implementations, a computing device according to the present application may include at least one processor, and at least one memory. Wherein the memory stores a computer program which, when executed by the processor, causes the processor to perform the steps of the data communication method according to various exemplary embodiments of the present application described above in the present specification. For example, the processor may perform steps 301-303 as shown in FIG. 3.
The computing device 130 according to this embodiment of the present application is described below with reference to fig. 10. The computing device 130 shown in fig. 10 is only an example and should not bring any limitations to the functionality or scope of use of the embodiments of the present application.
As shown in FIG. 10, computing device 130 is embodied in the form of a general purpose computing apparatus. Components of computing device 130 may include, but are not limited to: the at least one processor 131, the at least one memory 132, and a bus 133 that connects the various system components (including the memory 132 and the processor 131).
The memory 132 may include readable media in the form of volatile memory, such as Random Access Memory (RAM)1321 and/or cache memory 1322, and may further include Read Only Memory (ROM) 1323.
The computing device 130 may also communicate with one or more external devices 134 (e.g., keyboard, pointing device, etc.), and/or with any device (e.g., router, modem, etc.) that enables the computing device 130 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 135. Also, computing device 130 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via network adapter 136. As shown, network adapter 136 communicates with other modules for computing device 130 over bus 133. It should be understood that although not shown in the figures, other hardware and/or software modules may be used in conjunction with computing device 130, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
In some possible embodiments, the various aspects of the data communication method provided herein may also be implemented in the form of a program product comprising a computer program for causing a computer device to perform the steps of the data communication method according to various exemplary embodiments of the present application described above in this specification when the program product is run on the computer device, for example, the computer device may perform steps 301-303 as shown in fig. 3.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A 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 (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, 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.
The program product for parameter processing of the embodiments of the present application may employ a portable compact disc read only memory (CD-ROM) and include a computer program, and may be run on a computing device. However, the program product of the present application is not limited thereto, and in this document, a 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.
A readable signal medium may include a propagated data signal with a readable computer program embodied therein, either in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a 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.
A computer program embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Computer programs for carrying out operations of the present application may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The computer program may execute entirely on the target object computing device, partly on the target object apparatus, as a stand-alone software package, partly on the target object computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the target object computing device over any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., over the internet using an internet service provider).
It should be noted that although several units or sub-units of the apparatus are mentioned in the above detailed description, such division is merely exemplary and not mandatory. Indeed, the features and functions of two or more units described above may be embodied in one unit, according to embodiments of the application. Conversely, the features and functions of one unit described above may be further divided into embodiments by a plurality of units.
Further, while the operations of the methods of the present application are depicted in the drawings in a particular order, this does not require or imply that these operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having a computer-usable computer program embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
While the preferred embodiments of the present application have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all alterations and modifications as fall within the scope of the application.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.
Claims (10)
1. A data communication method for use in communication between a message producing process for writing messages and a message consuming process for reading messages, the method comprising:
creating a shared object in a shared memory; and maintaining an address file in the shared memory in real time; the address file comprises respective memory addresses and online quantities of the current head message and the current tail message of the shared object; the online number is used for indicating whether an accessed process exists in the shared memory;
performing access management on the processes accessing the shared memory according to the online quantity;
the message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file;
and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
2. The method of claim 1, wherein at any point in time, the access process to the shared memory is the message production process or the message consumption process;
if the online quantity is a first preset value, it indicates that there is no process accessed in the shared memory, and other processes can access the shared memory;
if the online quantity is a second preset value, the process is accessed in the shared memory, and other processes cannot access the shared memory.
3. The method according to claim 1 or 2, characterized in that the method further comprises:
when the abnormal condition of the process accessed to the shared memory is determined, releasing the process accessed to the shared memory in the shared memory, and updating the online quantity from the second preset value to the first preset value;
wherein the abnormal condition comprises: and the process accessed to the shared memory fails to acquire the designated information.
4. The method of claim 1, wherein the address file further comprises: memory capacity status of the shared object; and the memory capacity state is used for indicating whether the process accessed to the shared memory is allowed to carry out read-write operation on the shared memory.
5. The method of claim 4, wherein the messages in the shared memory are stored based on a cyclic address;
the maintaining the address file in the shared memory in real time includes:
a memory capacity status determined based on the cyclic address after writing or reading the message;
updating the address file based on the determined memory capacity status.
6. The method of claim 5, wherein the memory capacity state of the shared object comprises: a first preset state, a second preset state and a third preset state;
when the memory address of the current head message is the same as the memory address of the current tail message, determining that the memory capacity state is the first preset state;
when the next address of the memory address of the current tail message is the memory address of the current head message, determining that the memory capacity state is the second preset state;
and when the memory address of the current tail message is different from the memory address of the current head message, and the next address of the memory address of the current tail message is not the memory address of the current head message, determining that the memory capacity state is the third preset state.
7. The method of claim 6, further comprising:
if the memory capacity state of the shared object is the first preset state or the third preset state, indicating that a message production process is allowed to write a message in the shared object;
and if the memory capacity state of the shared object is the second preset state or the third preset state, indicating that a message consumption process is allowed to read the message in the shared object.
8. A data communication apparatus arranged for communication between a message producing process for writing a message and a message consuming process for reading the message, the apparatus comprising:
the creating module is used for creating a shared object in the shared memory;
the maintenance module is used for maintaining the address file in the shared memory in real time; the address file comprises respective memory addresses and online quantities of the current head message and the current tail message of the shared object; the online number is used for indicating whether an accessed process exists in the shared memory;
the management module is used for carrying out access management on the processes accessing the shared memory according to the online quantity;
the message production process is used for writing a new message into the shared object according to the memory address of the current tail message in the address file;
and the message consumption process is used for reading the message from the shared object according to the memory address of the current head message in the address file.
9. A computing device, comprising: a memory and a processor;
a memory for storing program instructions;
a processor for calling program instructions stored in said memory to execute the method of any one of claims 1 to 7 in accordance with the obtained program.
10. A computer storage medium storing computer-executable instructions for performing the method of any one of claims 1-7.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010463557.4A CN111651286A (en) | 2020-05-27 | 2020-05-27 | Data communication method, device, computing equipment and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202010463557.4A CN111651286A (en) | 2020-05-27 | 2020-05-27 | Data communication method, device, computing equipment and storage medium |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN111651286A true CN111651286A (en) | 2020-09-11 |
Family
ID=72344010
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202010463557.4A Pending CN111651286A (en) | 2020-05-27 | 2020-05-27 | Data communication method, device, computing equipment and storage medium |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN111651286A (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113176942A (en) * | 2021-04-23 | 2021-07-27 | 北京蓝色星云科技发展有限公司 | Method and device for sharing cache and electronic equipment |
| CN113760578A (en) * | 2021-08-28 | 2021-12-07 | 特斯联科技集团有限公司 | Method, apparatus, device and computer program for fast transmission of big data across processes |
| CN115373874A (en) * | 2022-08-24 | 2022-11-22 | 阿波罗智能技术(北京)有限公司 | Cross-process event processing method, device, electronic device, storage medium and vehicle |
| CN115840654A (en) * | 2023-01-30 | 2023-03-24 | 北京万里红科技有限公司 | Message processing method, system, computing device and readable storage medium |
| CN116225308A (en) * | 2022-11-21 | 2023-06-06 | 中科三清科技有限公司 | Data reading and writing method and device, storage medium and chip |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101105786A (en) * | 2006-07-14 | 2008-01-16 | 中兴通讯股份有限公司 | A Dual-CPU Communication Method Based on Shared Memory |
| CN101853238A (en) * | 2010-06-01 | 2010-10-06 | 华为技术有限公司 | Method and system for message communication between communication processors |
| CN102693162A (en) * | 2011-12-29 | 2012-09-26 | 中国科学技术大学苏州研究院 | Method for process communication among multiple virtual machines on multi-core platform based on shared memory and intercore interruption |
| CN107085542A (en) * | 2017-05-05 | 2017-08-22 | 深圳慧昱教育科技有限公司 | IPC communication means and server |
| CN110399229A (en) * | 2018-04-25 | 2019-11-01 | 清华大学 | Inter-process communication method, device, system, medium and terminal |
-
2020
- 2020-05-27 CN CN202010463557.4A patent/CN111651286A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101105786A (en) * | 2006-07-14 | 2008-01-16 | 中兴通讯股份有限公司 | A Dual-CPU Communication Method Based on Shared Memory |
| CN101853238A (en) * | 2010-06-01 | 2010-10-06 | 华为技术有限公司 | Method and system for message communication between communication processors |
| CN102693162A (en) * | 2011-12-29 | 2012-09-26 | 中国科学技术大学苏州研究院 | Method for process communication among multiple virtual machines on multi-core platform based on shared memory and intercore interruption |
| CN107085542A (en) * | 2017-05-05 | 2017-08-22 | 深圳慧昱教育科技有限公司 | IPC communication means and server |
| CN110399229A (en) * | 2018-04-25 | 2019-11-01 | 清华大学 | Inter-process communication method, device, system, medium and terminal |
Cited By (8)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN113176942A (en) * | 2021-04-23 | 2021-07-27 | 北京蓝色星云科技发展有限公司 | Method and device for sharing cache and electronic equipment |
| CN113176942B (en) * | 2021-04-23 | 2024-12-06 | 北京蓝色星云科技发展有限公司 | A method, device and electronic device for sharing cache |
| CN113760578A (en) * | 2021-08-28 | 2021-12-07 | 特斯联科技集团有限公司 | Method, apparatus, device and computer program for fast transmission of big data across processes |
| CN113760578B (en) * | 2021-08-28 | 2022-04-19 | 特斯联科技集团有限公司 | Method, device, equipment and computer program for cross-process rapid transmission of big data |
| CN115373874A (en) * | 2022-08-24 | 2022-11-22 | 阿波罗智能技术(北京)有限公司 | Cross-process event processing method, device, electronic device, storage medium and vehicle |
| CN116225308A (en) * | 2022-11-21 | 2023-06-06 | 中科三清科技有限公司 | Data reading and writing method and device, storage medium and chip |
| CN116225308B (en) * | 2022-11-21 | 2023-12-08 | 中科三清科技有限公司 | Data reading and writing method and device, storage medium and chip |
| CN115840654A (en) * | 2023-01-30 | 2023-03-24 | 北京万里红科技有限公司 | Message processing method, system, computing device and readable storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111651286A (en) | Data communication method, device, computing equipment and storage medium | |
| JP6799652B2 (en) | Methods and devices for processing information | |
| CN111078147B (en) | Processing method, device and equipment for cache data and storage medium | |
| US11762850B2 (en) | Content-aware node selection for container creation | |
| US8495166B2 (en) | Optimized caching for large data requests | |
| US20120079212A1 (en) | Architecture for sharing caches among multiple processes | |
| US8544094B2 (en) | Suspicious node detection and recovery in MapReduce computing | |
| WO2020181810A1 (en) | Data processing method and apparatus applied to multi-level caching in cluster | |
| US20220100372A1 (en) | Method, electronic device, and computer program product for storing and accessing data | |
| US8443154B2 (en) | Managing shared data objects to provide visibility to shared memory | |
| US10176101B2 (en) | Allocate a segment of a buffer to each of a plurality of threads to use for writing data | |
| CN112346647A (en) | Data storage method, apparatus, device and medium | |
| US11016886B2 (en) | Multi-ring shared, traversable, and dynamic advanced database | |
| CN117762898A (en) | Data migration method, device, equipment and storage medium | |
| CN109597697B (en) | Resource matching processing method and device | |
| US8886900B2 (en) | Legacy data management | |
| US20110302377A1 (en) | Automatic Reallocation of Structured External Storage Structures | |
| US8407444B2 (en) | Hardware off-load garbage collection acceleration for languages with finalizers | |
| US20170344488A1 (en) | Sharing data structures between processes by semi-invasive hybrid approach | |
| US20240086225A1 (en) | Container group scheduling methods and apparatuses | |
| US20250094050A1 (en) | Method, device, and program product for storage | |
| CN114443748B (en) | Data processing method, device, electronic device and storage medium | |
| US20140082305A1 (en) | Providing usage statistics for virtual storage | |
| US20140156908A1 (en) | Stale pointer detection with overlapping versioned memory | |
| US10678453B2 (en) | Method and device for checking false sharing in data block deletion using a mapping pointer and weight bits |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200911 |
|
| RJ01 | Rejection of invention patent application after publication |