CN106293973A - Lock-free message queue communication means and system - Google Patents
Lock-free message queue communication means and system Download PDFInfo
- Publication number
- CN106293973A CN106293973A CN201610681120.1A CN201610681120A CN106293973A CN 106293973 A CN106293973 A CN 106293973A CN 201610681120 A CN201610681120 A CN 201610681120A CN 106293973 A CN106293973 A CN 106293973A
- Authority
- CN
- China
- Prior art keywords
- message
- queue
- lock
- free
- write
- 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.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR 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
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR 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/546—Message passing systems or structures, e.g. queues
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/543—Local
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/548—Queue
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Communication Control (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a kind of Lock-free message queue communication means and system.This Lock-free message queue communication means includes: create Lock-free message queue in shared drive, and Lock-free message queue includes at least one message body according to first in first out arrangement;Receive at least one and write into delivery message that journey sends, and according to receiving the sequencing delivering message, message body corresponding for each delivery message writing into journey is sequentially write the queue tail of Lock-free message queue;Receive the reading message that at least one reading process sends, and according to receiving the sequencing reading message, sequentially message body is sent to one by one from the queue head of Lock-free message queue each reading process.In this Lock-free message queue communication means and system, all message bodies are stored in shared drive according to first in first out, can realize carrying out between multiple processes in same equipment, by writing into journey and reading process, the concurrent secure communication that mass data is mutual.
Description
Technical field
The present invention relates to communication technical field, particularly relate to a kind of Lock-free message queue communication means and system.
Background technology
Existing interprocess communication usual way include pipeline, famous pipeline, semaphore, message queue, signal, share in
Deposit, socket.Wherein, pipeline is a kind of semiduplex communication mode, data can only one-way flow, and can only be in father and son's process
Between use.Famous pipeline is semiduplex communication mode, and famous pipeline allows the communication between affinity-less relation process.Semaphore is
One enumerator, is used for controlling the access to shared resource of multiple process;Semaphore, as a kind of lock mechanism, is used for preventing certain from entering
When journey accesses shared resource, other processes also access this resource.Signal is a kind of more complicated communication mode, is used for leading to
Know that certain event of receiving process has occurred and that.Message queue is by the chained list of message, leaves in kernel and by message queue mark
Know symbol mark.Shared drive is to map one section of internal memory that can be accessed by other processes, and this section of shared drive is created by a process
Build, but multiple process can access;Shared drive is the fastest IPC mode, is to run for other interprocess communication modes
Efficiency is low and custom-designed;Shared drive often with other communication mechanisms with the use of, to realize synchronization between process and logical
Letter.Socket is a kind of inter-process communication mechanisms, can be used for the process communication between different process, is the bottom communication of network level
Mechanism.Pipeline and famous pipeline are only limitted to the communication between father and son's process;Signal and semaphore are not suitable for mass data between process
Mutual application scenarios;Socket is the communication mechanism of Internet, and communication efficiency is lost;Message queue is equal with shared drive
There is process safety problem during multi-course concurrency read-write.
Summary of the invention
The technical problem to be solved in the present invention is, for the defect of prior art, it is provided that a kind of based on shared drive
Lock-free message queue communication means and system, existing concurrent alternately for solving to carry out between existing multiple process mass data
Safety problem.
The technical solution adopted for the present invention to solve the technical problems is: a kind of Lock-free message queue communication means, including:
Creating Lock-free message queue in shared drive, described Lock-free message queue includes arranging according to first in first out
At least one message body;
Receive at least one and write into the delivery message that journey sends, and according to receiving the sequencing delivering message, will be every
Write into message body corresponding to the delivery message of journey described in one and sequentially write the queue tail of described Lock-free message queue;
Receive the reading message that at least one reading process sends, and according to receiving the sequencing reading message, from institute
Message body is sequentially sent to each described reading process by queue head one by one that state Lock-free message queue.
Preferably, described Lock-free message queue includes the queue head memory block for storing header information, for storing
The message index memory block of message index and for storing the message content memory block of message content;
Described reception at least one write into journey send delivery message, and according to receive deliver message sequencing,
Message body corresponding for the delivery message writing into journey described in each is sequentially write the queue tail of described Lock-free message queue, bag
Include:
At least one is write into Cheng Xianhou and obtains queue write permission and seize message index write permission, and to described without lock message
Queue sends delivers message;
The sequencing of the delivery message received is determined according to each message index write permission of seizing writing into journey;
Message body corresponding for the delivery message writing into journey described in each is sequentially write the queue of described Lock-free message queue
In the described message content memory block of afterbody;
Update the message index in described message index memory block, and seize message index write permission described in release;
Update the header information in described queue head memory block, and discharge described queue write permission.
Preferably, the reading message that at least one reading process of described reception sends, and according to receiving the elder generation reading message
Rear order, is sequentially sent to each described reading process one by one from the queue head of described Lock-free message queue by message body, including:
At least one is read process and obtains queue read right, and sends reading message to described Lock-free message queue;
Based on described queue read right, travel through all message index in described message index memory block, do not read to obtain
The message content taken;
Each reading process obtains and seizes message index read right, and determines receive according to seizing message index read right
Read the sequencing of message;
Sequentially the described message content not read is sent one by one from the queue head of described Lock-free message queue and be given to rob
Account in the reading process corresponding to message index read right;
Update the message index in described message index memory block, and seize message index read right described in release;
Update the header information in described queue head memory block, and discharge described queue read right.
Preferably, write into Cheng Caiyong atom function described in and obtain queue write permission;Described reading process uses atom function to obtain
Take described queue read right.
Preferably, described message body corresponding for the delivery message writing into journey described in each is sequentially write described without lock message
The queue tail of queue, also includes: to all reading processes give out information enqueue notice;
Message body is sequentially sent to each described reading process by the described queue head from described Lock-free message queue one by one,
Also include: send message dequeue notice to all journeys of writing into.
The present invention also provides for a kind of Lock-free message queue communication system, including:
Lock-free message queue creation module, for creating Lock-free message queue in shared drive, described without lock message team
Row include at least one message body according to first in first out arrangement;
Write into journey communication module, write into, for receiving at least one, the delivery message that journey sends, and according to receiving delivery
The sequencing of message, sequentially writes described Lock-free message queue by message body corresponding for the delivery message writing into journey described in each
Queue tail;
Read process communication module, for receiving the reading message that at least one reading process sends, and according to receiving reading
The sequencing of message, sequentially message body is sent to one by one from the queue head of described Lock-free message queue each described read into
Journey.
Preferably, described Lock-free message queue includes the queue head memory block for storing header information, for storing
The message index memory block of message index and for storing the message content memory block of message content;
Described journey communication module of writing into includes:
Write permission obtains submodule, is used for making at least one write into Cheng Xianhou and obtains queue write permission and seize message index
Write permission, and send delivery message to described Lock-free message queue;
Write into journey sequencing and determine submodule, for determining connect according to each message index write permission of seizing writing into journey
The sequencing of the delivery message received;
Message body write submodule, for sequentially writing institute by message body corresponding for the delivery message writing into journey described in each
In the described message content memory block of the queue tail stating Lock-free message queue;
Message index write permission release module, for updating the message index in described message index memory block, and discharges
Described seize message index write permission;
Queue write permission release module, for updating the header information in described queue head memory block, and discharges described
Queue write permission.
Preferably, described reading process communication module includes:
Queue read right obtains submodule, is used for making at least one reading process obtain queue read right, and to described without lock
Message queue sends and reads message;
Message content obtains submodule, for based on described queue read right, travels through in described message index memory block
All message index, the message content not read with acquisition;
Reading process sequencing determines submodule, is used for making each reading process obtain and seizes message index read right, and root
According to the sequencing seizing message index read right and determining the reading message received;
Message body reading submodule, for from the queue head of described Lock-free message queue sequentially by described do not read disappear
Breath content sends one by one and is given to seize in the reading process corresponding to message index read right;
Message index read right release submodule, for updating the message index in described message index memory block, and releases
Message index read right is seized described in putting;
Queue read right release submodule, for updating the header information in described queue head memory block, and discharges institute
State queue read right.
Preferably, write into Cheng Caiyong atom function described in and obtain queue write permission;Described reading process uses atom function to obtain
Take described queue read right.
Preferably, write into journey communication module described in and also include that message enqueue notice issues submodule, for all readings
Process give out information enqueue notice;
Described reading process communication module also includes that message dequeue notice issues submodule, for sending to all journeys of writing into
Message dequeue notifies.
The present invention compared with prior art has the advantage that Lock-free message queue communication means provided by the present invention
In, by creating Lock-free message queue in shared drive so that it is can be received at least one and write into the delivery message that journey sends, complete
Become the write of message body;And the reading message that at least one reading process sends, the reading of completion message body can be received.This nothing lock disappears
In breath queue communication method, all message bodies are stored in shared drive, by writing into journey and reading process according to first in first out
Can realize same equipment is carried out between multiple processes the concurrent secure communication that mass data is mutual.
In Lock-free message queue communication system provided by the present invention, by Lock-free message queue creation module in sharing
Deposit middle establishment Lock-free message queue;And make Lock-free message queue can receive at least one to write into journey and send out by writing into journey communication module
The delivery message sent, the write of completion message body;And make Lock-free message queue can receive at least one by reading process communication module
The reading message that individual reading process sends, the reading of completion message body.In this Lock-free message queue communication system, all message bodies depend on
It is stored in shared drive according to first in first out, can realize same equipment enters between multiple processes by writing into journey and reading process
The concurrent secure communication that row mass data is mutual.
Accompanying drawing explanation
Below in conjunction with drawings and Examples, the invention will be further described, in accompanying drawing:
Fig. 1 is a schematic diagram of Lock-free message queue communication means in the embodiment of the present invention 1.
Fig. 2 is a flow chart of Lock-free message queue communication means in the embodiment of the present invention 1.
Fig. 3 is a local flow chart of Lock-free message queue communication means in the embodiment of the present invention 1.
Fig. 4 is another local flow chart of Lock-free message queue communication means in the embodiment of the present invention 1.
Fig. 5 is a theory diagram of Lock-free message queue communication system in the embodiment of the present invention 2.
Fig. 6 is the theory diagram writing into journey communication module in the embodiment of the present invention 2.
Fig. 7 is the theory diagram reading process communication module in the embodiment of the present invention 2.
In figure: 1, Lock-free message queue creation module;2, journey communication module is write into;21, write permission obtains submodule;22、
Write into journey sequencing and determine submodule;23, message body write submodule;24, message index write permission release module;25, team
Row write permission release module;26, message enqueue notice issues submodule;3, process communication module is read;31, queue read right obtains
Take submodule;32, message content obtains submodule;33, read process sequencing and determine submodule;34, submodule read by message body
Block;35, message index read right release submodule;36, queue read right release submodule;37, message dequeue notice is issued
Submodule;4, Lock-free message queue destroys module.
Detailed description of the invention
In order to be more clearly understood from the technical characteristic of the present invention, purpose and effect, now comparison accompanying drawing describes in detail
The detailed description of the invention of the present invention.
Embodiment 1
Fig. 1 and Fig. 2 illustrates a kind of Lock-free message queue communication means in the present embodiment.As depicted in figs. 1 and 2, this nothing
Lock message queue communication method includes:
S1: host process creates Lock-free message queue in shared drive, and Lock-free message queue includes according to first in first out former
At least one message body then arranged.Specifically, host process creates Lock-free message queue class (CMsgQueueShm) example, calls
OPEN operation completes the establishment of Lock-free message queue, and completes the initialization operation of queue head information.The present embodiment owns
Message body be stored in shared drive, can be by the read-write operation of the message body in shared drive be completed data interaction.
Specifically, Lock-free message queue includes the queue head memory block for storing header information, for storing disappearing of message index
Breath indexes memory block and for storing the message content memory block of message content.
Wherein, queue head memory block retains the essential information of queue, (i.e. preserves the maximum number of message including capacity of queue
Amount), currently used quantity (i.e. write number of processes and read number of processes), enter queue message quantity, dequeue message number, writeable
Message number, readable message quantity, data writing position (i.e. the writing position skew in message content district), data reading location (i.e. message
The reading location skew of content regions).Message index memory block retain each message index information, including current message the most just
(the most read or be normally written into journey write by reading process) being used, currently writing number of processes, currently read process
Quantity, the length of message content, the numbering of message index, the message original position in message content district.Message content memory block
It is the particular content of reservation message body, is made up of one piece of complete big internal memory.
S2: receive at least one and write into the delivery message that journey sends, and according to receiving the sequencing delivering message, will
Message body corresponding to each delivery message writing into journey sequentially writes the queue tail of Lock-free message queue.In the present embodiment, nothing
Lock message queue can receive at least one and write into the delivery message that journey sends, and completes at least one concurrent operations writing into journey, and
And following strictly first in first out by writing into the message body of journey write Lock-free message queue, a message body can only be by one
Write into journey write Lock-free message queue.As it is shown on figure 3, step S2 specifically includes:
S21: at least one is write into Cheng Xianhou and obtains queue write permission and seize message index write permission, and to without lock message
Queue sends delivers message.Wherein, queue write permission is to write into journey to write the authority of message body to Lock-free message queue.Seize
Message index write permission refers to write into the authority that journey seizes the priority of message index in shared drive.In the present embodiment, write
Process uses atom function to replace system critical zone lock function and obtains queue write permission, while guaranteeing data safety, can subtract
Few system is called, and improves the concurrency performance of Lock-free message queue.
S22: determine the sequencing of the delivery message received according to each message index write permission of seizing writing into journey.
If it is to be appreciated that arrive Lock-free message queue during two delivery message differences writing into journey, then message can be delivered by direct basis
The time arriving Lock-free message queue determines the sequencing delivering message.Deliver message at two or more to arrive simultaneously
During Lock-free message queue, can determine that according to the priority seizing message index write permission the priority of the delivery message received is suitable
Sequence.
S23: message body corresponding for each delivery message writing into journey is sequentially write the queue tail of Lock-free message queue
Message content memory block in.Specifically, message body corresponding for each delivery message writing into journey is determined according in step S22
Delivery message sequencing write Lock-free message queue queue tail Lock-free message queue in, completion message write
(PUT) operation.Step S23 follows strictly first in first out and the message body writing into journey is write in Lock-free message queue, and one
Individual message body can only be write in journey write Lock-free message queue by one.It is to be appreciated that each delivery message pair writing into journey
The indefinite length of the message body answered is long, as long as the free memory length that the length of message body is not more than in message content memory block is i.e.
Can.
S24: update the message index in message index memory block, and message index write permission is seized in release.
S25: updating the header information in queue head memory block, and discharge queue write permission, write operation terminates so that write
Process can not send to Lock-free message queue again and deliver message and message body, so that it is guaranteed that one write into journey can only be to without lock message team
Row write one message body.
S26: give out information enqueue notice to reading process, so that all reading processes read in Lock-free message queue new in time
The message body joined the team, is greatly promoted the concurrency performance of Lock-free message queue, reduces what message body preserved in Lock-free message queue
Time, greatly reduce the time of message body turnover queue, it is achieved high concurrent, the low delay of Lock-free message queue, the most applicable
The scene of the mass data interactive communication between server application multi-process.
S3: receive the reading message that at least one reading process sends, and according to receiving the sequencing reading message, from
Message body is sequentially sent to each reading process by the queue head of Lock-free message queue one by one.In the present embodiment, without lock message team
Row can receive the reading message that at least one reading process sends, and completes at least one reading process and reads the concurrent operations of message body,
And following strictly first in first out by the message body in the Lock-free message queue that reading process reads, reading process for one can only
From Lock-free message queue, read each message body in a message body, and Lock-free message queue to be read by one reading process
Take.As shown in Figure 4, step S3 specifically includes:
S31: at least one is read process and obtains queue read right, and sends reading message to Lock-free message queue.Wherein, team
Row read right refers to the reading message that reading process can send the message receiving Lock-free message queue transmission to Lock-free message queue
The authority of body.In the present embodiment, process of reading uses atom function to replace system critical zone lock function and obtains queue read right, really
While protecting data safety, system can be reduced and call, improve the concurrency performance of Lock-free message queue.
S32: based on queue read right, all message index in traversal message index memory block, do not read with acquisition
Message content.Specifically, Lock-free message queue receives the reading message of each reading process, is both needed to travel through message index memory block
In all message index, to determine the message index not read, so that it is determined that corresponding with the message index not read does not reads
The message content taken.It is to be appreciated that for each reading process read in message traverses message index memory block all disappear
In breath Index process, do not obtain the message index read, thus arbitrary disappearing of ensureing to be read in Lock-free message queue
Breath body is not read by another reading process.
S33: each reading process obtains and seizes message index read right, and determines reception according to seizing message index read right
The sequencing of the reading message arrived.Wherein, seize message index read right and refer to that reading process seizes the message in shared drive
The authority of the priority of index.If it is to be appreciated that arriving Lock-free message queue during two reading message differences reading process, then
The sequencing reading message can be determined according to the time reading message arrival Lock-free message queue.Read at two or more
When cancelling breath arrival Lock-free message queue simultaneously, can determine according to the priority seizing message index read right of each reading process
The sequencing of the reading message received.
S34: sequentially send one by one to be given to seize by the message content not read from the queue head of Lock-free message queue and disappear
In breath index reading process corresponding to read right.Time concrete, according to the sequencing of the reading message that step S33 determines, from without lock
The message content not read is sent and is given to seize the reading corresponding to message index read right by the queue head of message queue one by one
In process, completion message reads (GET) operation.This step follows strictly appointing in first in first out, and Lock-free message queue
One message body can only be read by a reading process.
S35: update the message index in message index memory block, and message index read right is seized in release.
S36: updating the header information in queue head memory block, and discharge queue read right, read operation terminates so that read
Process can not send to Lock-free message queue again and read message, and receives the message content not read that Lock-free message queue sends
(message body i.e. do not read).
S37: to all write into journey give out information dequeue notice so that all journeys of writing into are write to Lock-free message queue in time
Enter new message body, be greatly promoted the concurrency performance of Lock-free message queue, reduce what message body preserved in Lock-free message queue
Time, greatly reduce the time of message body turnover queue, it is achieved high concurrent, the low delay of Lock-free message queue, be applied to clothes
The scene of the mass data interactive communication between business device application multi-process.
S4: host process destroys the Lock-free message queue in shared drive so that queue head memory block release header information,
Message index memory block release message indexes, message memory block release message content.
In the Lock-free message queue communication means that the present embodiment is provided, by creating in shared drive without lock message team
Row so that it is can be received at least one and write into the delivery message that journey sends, the write of completion message body;And at least one reading can be received
The reading message that process sends, the reading of completion message body.In this Lock-free message queue communication means, all message bodies are according to first
Enter first to go out principle to be stored in shared drive, can realize same equipment being carried out between multiple processes greatly by writing into journey and reading process
The concurrent secure communication of amount data interaction.
Embodiment 2
Fig. 5 illustrates a kind of Lock-free message queue communication system in the present embodiment.As it is shown in figure 5, this Lock-free message queue
Communication system include Lock-free message queue creation module 1, write into journey communication module 2, read process communication module 3 and without lock message team
Charge off ruins module 4.
Lock-free message queue creation module 1, creates Lock-free message queue for host process in shared drive, without lock message
Queue includes at least one message body according to first in first out arrangement.Specifically, host process creates Lock-free message queue class
(CMsgQueueShm) example, calls OPEN operation and completes the establishment of Lock-free message queue, and complete at the beginning of queue head information
Beginningization operates.In the present embodiment, all of message body is stored in shared drive, can be by the message body in shared drive
Read-write operation complete data interaction.Specifically, Lock-free message queue includes the queue head internal memory for storing header information
Block, for storing the message index memory block of message index and for storing the message content memory block of message content.
Wherein, queue head memory block retains the essential information of queue, (i.e. preserves the maximum number of message including capacity of queue
Amount), currently used quantity (i.e. write number of processes and read number of processes), enter queue message quantity, dequeue message number, writeable
Message number, readable message quantity, data writing position (i.e. the writing position skew in message content district), data reading location (i.e. message
The reading location skew of content regions).Message index memory block retain each message index information, including current message the most just
(the most read or be normally written into journey write by reading process) being used, currently writing number of processes, currently read process
Quantity, the length of message content, the numbering of message index, the message original position in message content district.Message content memory block
It is the particular content of reservation message body, is made up of one piece of complete big internal memory.
Write into journey communication module 2, write into, for receiving at least one, the delivery message that journey sends, and according to receiving delivery
The sequencing of message, sequentially writes the rear of queue of Lock-free message queue by message body corresponding for each delivery message writing into journey
Portion.In the present embodiment, Lock-free message queue can receive at least one and write into the delivery message that journey sends, and completes at least one and writes into
The concurrent operations of journey, and follow strictly first in first out by writing into the message body of journey write Lock-free message queue, one
Message body can only be write into journey write Lock-free message queue by one.As shown in Figure 6, write into journey communication module 2 to specifically include:
Write permission obtains submodule 21, is used for making at least one write into Cheng Xianhou and obtains queue write permission and seize message rope
Draw write permission, and send delivery message to Lock-free message queue.Wherein, queue write permission be write into journey can be to Lock-free message queue
The authority of write message body.Seize message index write permission and refer to that writing into journey seizes the priority of the message index in shared drive
Authority.In the present embodiment, write into Cheng Caiyong atom function and replace system critical zone lock function acquisition queue write permission, guaranteeing
While data safety, system can be reduced and call, improve the concurrency performance of Lock-free message queue.
Write into journey sequencing and determine submodule 22, for determining according to each message index write permission of seizing writing into journey
The sequencing of the delivery message received.If disappearing it is to be appreciated that arrive during two delivery message differences writing into journey without lock
Breath queue, then can direct basis deliver message arrive Lock-free message queue time determine deliver message sequencing.Two
Individual or two or more delivers message when arriving Lock-free message queue simultaneously, can be true according to the priority seizing message index write permission
The sequencing of the delivery message surely received.
Message body write submodule 23, for sequentially writing message body corresponding for each deliverys message writing into journey without locking
In the message content memory block of the queue tail of message queue.Specifically, by message corresponding for each delivery message writing into journey
Body foundation is write into journey sequencing and is determined that the sequencing of the delivery message determined in submodule 22 writes Lock-free message queue
In the Lock-free message queue of queue tail, completion message write (PUT) operation.Message body write submodule 23 follows strictly advanced person
First go out principle the message body writing into journey to be write in Lock-free message queue, and a message body can only be write into journey write nothing by one
In lock message queue.It is to be appreciated that the indefinite length of message body corresponding to each delivery message writing into journey is long, as long as message
The length of body is not more than the free memory length in message content memory block.
Message index write permission release module 24, for updating the message index in message index memory block, and release is robbed
Account for message index write permission.
Queue write permission release module 25, for updating the header information in queue head memory block, and discharges queue and writes
Authority, write operation terminates so that writes into Cheng Buke and sends delivery message and message body to Lock-free message queue again, so that it is guaranteed that one
Write into journey and can only write a message body to Lock-free message queue.
Message enqueue notice issues submodule 26, for giving out information enqueue notice to reading process, so that all readings
Process reads the message body newly joined the team in Lock-free message queue in time, is greatly promoted the concurrency performance of Lock-free message queue, reduces
The time that message body preserves in Lock-free message queue, greatly reduce the time of message body turnover queue, it is achieved without lock message
High concurrent, the low delay of queue, the scene of the mass data interactive communication being highly suitable between server application multi-process.
Read process communication module 3, for receiving the reading message that at least one reading process sends, and according to receiving reading
The sequencing of message, is sequentially sent to each reading process one by one from the queue head of Lock-free message queue by message body.This reality
Executing in example, Lock-free message queue can receive the reading message that at least one reading process sends, and completes at least one reading process and reads
It is former that message body in the concurrent operations of message body, and the Lock-free message queue read by reading process follows strictly first in first out
Then, a reading process can only read each message body in a message body, and Lock-free message queue from Lock-free message queue
Process can only be read by one to read.Specifically include as it is shown in fig. 7, read process communication module 3:
Queue read right obtains submodule 31, is used for making at least one reading process obtain queue read right, and disappears to without lock
Breath queue sends reads message.Wherein, queue read right refers to that reading process can to the reading message of Lock-free message queue transmission also
Receive the authority of the message body that Lock-free message queue sends.In the present embodiment, it is critical that process of reading uses atom function to replace system
District's lock function obtains queue read right, while guaranteeing data safety, can reduce system and call, improve Lock-free message queue
Concurrency performance.
Message content obtains submodule 32, and for based on queue read right, all in traversal message index memory block disappear
Breath index, the message content not read with acquisition.Specifically, Lock-free message queue receives the reading message of each reading process,
Be both needed to travel through all message index in message index memory block, to determine the message index not read, so that it is determined that with do not read
The message content not read that the message index that takes is corresponding.It is to be appreciated that the reading message traverses for each reading process disappears
During all message index in breath index memory block, do not obtain the message index read, thus ensure without lock message
The arbitrary message body being read in queue is not read by another reading process.
Reading process sequencing determines submodule 33, is used for making each reading process obtain and seizes message index read right, and
According to the sequencing seizing message index read right and determining the reading message received.Wherein, message index read right is seized
Refer to that reading process seizes the authority of the priority of the message index in shared drive.If it is to be appreciated that two readings reading process
Cancellation breath arrives Lock-free message queue time different, then can determine that reading disappears according to the time reading message arrival Lock-free message queue
The sequencing of breath.When two or more reading message arrive Lock-free message queue simultaneously, can be according to each reading process
The priority seizing message index read right determine the sequencing of the reading message received.
Message body reading submodule 34, for the message content that sequentially will not read from the queue head of Lock-free message queue
Send one by one and be given to seize in the reading process corresponding to message index read right.Time concrete, determine son according to reading process sequencing
The sequencing of the reading message that module 33 determines, from the queue head of Lock-free message queue by the message content that do not reads one by one
Sending and be given to seize in the reading process corresponding to message index read right, completion message reads (GET) operation.This step is strictly abided by
Follow any one message body in first in first out, and Lock-free message queue to be read by a reading process.
Message index read right release submodule 35, for updating the message index in message index memory block, and discharges
Seize message index read right.
Queue read right release submodule 36, for updating the header information in queue head memory block, and discharges queue
Read right, read operation terminates so that process of reading can not send to Lock-free message queue again and read message, and receives without lock message team
The message content (message body i.e. do not read) not read that row send.
Message dequeue notice issues submodule 37, for giving out information dequeue notice, so that institute to all journeys of writing into
Have and write into journey in time to the message body that Lock-free message queue write is new, be greatly promoted the concurrency performance of Lock-free message queue, reduce
The time that message body preserves in Lock-free message queue, greatly reduce the time of message body turnover queue, it is achieved without lock message
High concurrent, the low delay of queue, the scene of the mass data interactive communication being applied between server application multi-process.
Lock-free message queue destroys module 4, for making host process destroy the Lock-free message queue in shared drive so that team
Row head memory block release header information, message index memory block release message indexes, message memory block release message content.
In the Lock-free message queue communication system that the present embodiment is provided, by Lock-free message queue creation module 1 altogether
Enjoy establishment Lock-free message queue in internal memory;And make Lock-free message queue can receive at least one to write by writing into journey communication module 2
The delivery message that process sends, the write of completion message body;And make Lock-free message queue to receive by reading process communication module 3
At least one reads the reading message that process sends, the reading of completion message body.All in this Lock-free message queue communication system disappear
Breath body is stored in shared drive according to first in first out, by write into journey and reading process can realize in same equipment multiple enter
The concurrent secure communication that mass data is mutual is carried out between journey.
The present invention is illustrated by above-mentioned specific embodiment, it will be appreciated by those skilled in the art that, without departing from
In the case of the scope of the invention, it is also possible to the present invention is carried out various conversion and equivalent substitutes.It addition, for particular condition or tool
Body situation, can make various amendment, without deviating from the scope of the present invention to the present invention.Therefore, the present invention is not limited to disclosed
Specific embodiment, and the whole embodiments fallen within the scope of the appended claims should be included.
Claims (10)
1. a Lock-free message queue communication means, it is characterised in that including:
Creating Lock-free message queue in shared drive, described Lock-free message queue includes arranging extremely according to first in first out
A few message body;
Receive at least one and write into the delivery message that journey sends, and according to receiving the sequencing delivering message, by each institute
State and write into message body corresponding to the delivery message of journey and sequentially write the queue tail of described Lock-free message queue;
Receive the reading message that at least one reading process sends, and according to receiving the sequencing reading message, from described nothing
Message body is sequentially sent to each described reading process by the queue head of lock message queue one by one.
Lock-free message queue communication means the most according to claim 1, it is characterised in that described Lock-free message queue includes
For storing the queue head memory block of header information, for storing the message index memory block of message index and disappearing for storage
The message content memory block of breath content;
Described reception at least one write into the delivery message that journey sends, and according to receiving the sequencing delivering message, will be every
Write into message body corresponding to the delivery message of journey described in one and sequentially write the queue tail of described Lock-free message queue, including:
At least one is write into Cheng Xianhou and obtains queue write permission and seize message index write permission, and to described Lock-free message queue
Send and deliver message;
The sequencing of the delivery message received is determined according to each message index write permission of seizing writing into journey;
Message body corresponding for the delivery message writing into journey described in each is sequentially write the queue tail of described Lock-free message queue
Described message content memory block in;
Update the message index in described message index memory block, and seize message index write permission described in release;
Update the header information in described queue head memory block, and discharge described queue write permission.
Lock-free message queue communication means the most according to claim 2, it is characterised in that described reception at least one read into
The reading message that journey sends, and according to receiving the sequencing reading message, from the queue head of described Lock-free message queue
Sequentially message body is sent to one by one each described reading process, including:
At least one is read process and obtains queue read right, and sends reading message to described Lock-free message queue;
Based on described queue read right, travel through all message index in described message index memory block, do not read with acquisition
Message content;
Each reading process obtains and seizes message index read right, and determines, according to seizing message index read right, the reading received
The sequencing of message;
Sequentially send one by one to be given to seize by the described message content not read from the queue head of described Lock-free message queue and disappear
In breath index reading process corresponding to read right;
Update the message index in described message index memory block, and seize message index read right described in release;
Update the header information in described queue head memory block, and discharge described queue read right.
Lock-free message queue communication means the most according to claim 3, it is characterised in that described in write into Cheng Caiyong atom letter
Number obtains queue write permission;Described reading process uses atom function to obtain described queue read right.
Lock-free message queue communication means the most according to claim 1, it is characterised in that described write into journey described in each
Message body corresponding to delivery message sequentially write the queue tail of described Lock-free message queue, also include: to all reading processes
The enqueue that gives out information notifies;
Message body is sequentially sent to each described reading process by the described queue head from described Lock-free message queue one by one, also wraps
Include: send message dequeue notice to all journeys of writing into.
6. a Lock-free message queue communication system, it is characterised in that including:
Lock-free message queue creation module, for creating Lock-free message queue, described Lock-free message queue bag in shared drive
Include at least one message body according to first in first out arrangement;
Write into journey communication module, write into, for receiving at least one, the delivery message that journey sends, and according to receiving delivery message
Sequencing, message body corresponding for the delivery message writing into journey described in each is sequentially write the team of described Lock-free message queue
Row afterbody;
Read process communication module, for receiving the reading message that at least one reading process sends, and according to receiving reading message
Sequencing, sequentially message body is sent to one by one each described reading process from the queue head of described Lock-free message queue.
Lock-free message queue communication system the most according to claim 6, it is characterised in that described Lock-free message queue includes
For storing the queue head memory block of header information, for storing the message index memory block of message index and disappearing for storage
The message content memory block of breath content;
Described journey communication module of writing into includes:
Write permission obtains submodule, is used for making at least one to write into Cheng Xianhou and obtains queue write permission and seize message index and write power
Limit, and send delivery message to described Lock-free message queue;
Write into journey sequencing and determine submodule, for determining receive according to each message index write permission of seizing writing into journey
The sequencing of delivery message;
Message body write submodule, for sequentially writing described nothing by message body corresponding for the delivery message writing into journey described in each
In the described message content memory block of the queue tail of lock message queue;
Message index write permission release module, for updating the message index in described message index memory block, and discharges described
Seize message index write permission;
Queue write permission release module, for updating the header information in described queue head memory block, and discharges described queue
Write permission.
Lock-free message queue communication system the most according to claim 7, it is characterised in that described reading process communication module bag
Include:
Queue read right obtains submodule, is used for making at least one reading process obtain queue read right, and to described without lock message
Queue sends reads message;
Message content obtains submodule, for based on described queue read right, traveling through owning in described message index memory block
Message index, the message content not read with acquisition;
Reading process sequencing determines submodule, is used for making each reading process obtain and seizes message index read right, and according to robbing
Account for message index read right and determine the sequencing of the reading message received;
Message body reading submodule, is used for from the queue head of described Lock-free message queue sequentially by the described message not read
Hold to send one by one and be given to seize in the reading process corresponding to message index read right;
Message index read right release submodule, for updating the message index in described message index memory block, and discharges institute
State and seize message index read right;
Queue read right release submodule, for updating the header information in described queue head memory block, and discharges described team
Row read right.
Lock-free message queue communication system the most according to claim 8, it is characterised in that described in write into Cheng Caiyong atom letter
Number obtains queue write permission;Described reading process uses atom function to obtain described queue read right.
Lock-free message queue communication system the most according to claim 6, it is characterised in that described in write into journey communication module
Also include message enqueue notice issue submodule, for all reading processes give out information enqueue notice;
Described reading process communication module also includes that message dequeue notice issues submodule, for sending message to all journeys of writing into
Dequeue notifies.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610681120.1A CN106293973B (en) | 2016-08-17 | 2016-08-17 | lock-free message queue communication method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201610681120.1A CN106293973B (en) | 2016-08-17 | 2016-08-17 | lock-free message queue communication method and system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106293973A true CN106293973A (en) | 2017-01-04 |
CN106293973B CN106293973B (en) | 2019-12-13 |
Family
ID=57678405
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201610681120.1A Active CN106293973B (en) | 2016-08-17 | 2016-08-17 | lock-free message queue communication method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106293973B (en) |
Cited By (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108153596A (en) * | 2017-12-15 | 2018-06-12 | 珠海金山网络游戏科技有限公司 | A kind of message treatment method and device based on lock-free queue |
CN108959032A (en) * | 2018-06-29 | 2018-12-07 | 北京金山安全软件有限公司 | Real-time monitoring method and device for server service index and electronic equipment |
CN109376020A (en) * | 2018-09-18 | 2019-02-22 | 中国银行股份有限公司 | Data processing method, device and the storage medium multi-tiling chain interaction and given |
CN110046047A (en) * | 2019-04-15 | 2019-07-23 | Oppo广东移动通信有限公司 | A kind of inter-process communication methods, device and computer readable storage medium |
CN110362348A (en) * | 2018-04-09 | 2019-10-22 | 武汉斗鱼网络科技有限公司 | A kind of method, apparatus and electronic equipment of queue access data |
CN111143079A (en) * | 2019-12-24 | 2020-05-12 | 浪潮软件股份有限公司 | Method for realizing multi-read multi-write lock-free queue |
CN111797497A (en) * | 2020-05-21 | 2020-10-20 | 中国电力科学研究院有限公司 | Communication method and system for electromagnetic transient parallel simulation |
CN112559196A (en) * | 2019-09-10 | 2021-03-26 | 航天科工惯性技术有限公司 | Transmission method for interprocess communication data sharing |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100337205C (en) * | 2004-06-22 | 2007-09-12 | 国际商业机器公司 | Method and system for facilitating communication within shared memory environments using lock-free queues |
US7533221B1 (en) * | 2004-12-30 | 2009-05-12 | Sun Microsystems, Inc. | Space-adaptive lock-free free-list using pointer-sized single-target synchronization |
CN103164267A (en) * | 2013-03-29 | 2013-06-19 | 汉柏科技有限公司 | Lock-free message queue implementation method |
CN103514053A (en) * | 2013-09-22 | 2014-01-15 | 中国科学院信息工程研究所 | Shared-memory-based method for conducting communication among multiple processes |
CN105487933A (en) * | 2015-11-24 | 2016-04-13 | 无锡江南计算技术研究所 | Inter-kernel asynchronous message queue and shared memory based inter-domain communication method |
-
2016
- 2016-08-17 CN CN201610681120.1A patent/CN106293973B/en active Active
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN100337205C (en) * | 2004-06-22 | 2007-09-12 | 国际商业机器公司 | Method and system for facilitating communication within shared memory environments using lock-free queues |
US7533221B1 (en) * | 2004-12-30 | 2009-05-12 | Sun Microsystems, Inc. | Space-adaptive lock-free free-list using pointer-sized single-target synchronization |
CN103164267A (en) * | 2013-03-29 | 2013-06-19 | 汉柏科技有限公司 | Lock-free message queue implementation method |
CN103514053A (en) * | 2013-09-22 | 2014-01-15 | 中国科学院信息工程研究所 | Shared-memory-based method for conducting communication among multiple processes |
CN105487933A (en) * | 2015-11-24 | 2016-04-13 | 无锡江南计算技术研究所 | Inter-kernel asynchronous message queue and shared memory based inter-domain communication method |
Non-Patent Citations (1)
Title |
---|
BUNTINAS D,ET AL.,: "Design and Evaluation of Nemesis, a Scalable, Low-Latency, Message-Passing Communication Subsystem", 《IEEE INTERNATIONAL SYMPOSIUM ON CLUSTER COMPUTING & THE GRID》 * |
Cited By (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108153596A (en) * | 2017-12-15 | 2018-06-12 | 珠海金山网络游戏科技有限公司 | A kind of message treatment method and device based on lock-free queue |
CN110362348A (en) * | 2018-04-09 | 2019-10-22 | 武汉斗鱼网络科技有限公司 | A kind of method, apparatus and electronic equipment of queue access data |
CN108959032A (en) * | 2018-06-29 | 2018-12-07 | 北京金山安全软件有限公司 | Real-time monitoring method and device for server service index and electronic equipment |
CN109376020A (en) * | 2018-09-18 | 2019-02-22 | 中国银行股份有限公司 | Data processing method, device and the storage medium multi-tiling chain interaction and given |
CN109376020B (en) * | 2018-09-18 | 2021-02-12 | 中国银行股份有限公司 | Data processing method, device and storage medium under multi-block chain interaction concurrence |
CN110046047A (en) * | 2019-04-15 | 2019-07-23 | Oppo广东移动通信有限公司 | A kind of inter-process communication methods, device and computer readable storage medium |
CN112559196A (en) * | 2019-09-10 | 2021-03-26 | 航天科工惯性技术有限公司 | Transmission method for interprocess communication data sharing |
CN112559196B (en) * | 2019-09-10 | 2024-03-26 | 航天科工惯性技术有限公司 | Transmission method for sharing communication data between processes |
CN111143079A (en) * | 2019-12-24 | 2020-05-12 | 浪潮软件股份有限公司 | Method for realizing multi-read multi-write lock-free queue |
CN111143079B (en) * | 2019-12-24 | 2024-04-16 | 浪潮软件股份有限公司 | Multi-read multi-write lock-free queue implementation method |
CN111797497A (en) * | 2020-05-21 | 2020-10-20 | 中国电力科学研究院有限公司 | Communication method and system for electromagnetic transient parallel simulation |
CN111797497B (en) * | 2020-05-21 | 2024-05-17 | 中国电力科学研究院有限公司 | Communication method and system for electromagnetic transient parallel simulation |
Also Published As
Publication number | Publication date |
---|---|
CN106293973B (en) | 2019-12-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106293973A (en) | Lock-free message queue communication means and system | |
CN110691062B (en) | Data writing method, device and equipment | |
CN103150220B (en) | Communication means between process and communication system | |
JP6238898B2 (en) | System and method for providing and managing message queues for multi-node applications in a middleware machine environment | |
US7813342B2 (en) | Method and apparatus for writing network packets into computer memory | |
CN105224692A (en) | Support the system and method for the SDN multilevel flow table parallel search of polycaryon processor | |
CN107771332A (en) | The fast read/write between Net-connected computer is asked via the RPC based on RDMA | |
CN104394096A (en) | Multi-core processor based message processing method and multi-core processor | |
CN108234348A (en) | A kind of processing method and processing device in queue operation | |
CN111209228B (en) | Method for accelerating storage of multi-path on-board load file | |
EP3077914A1 (en) | System and method for managing and supporting virtual host bus adaptor (vhba) over infiniband (ib) and for supporting efficient buffer usage with a single external memory interface | |
CN108153596A (en) | A kind of message treatment method and device based on lock-free queue | |
CN102420771A (en) | Method for increasing concurrent transmission control protocol (TCP) connection speed in high-speed network environment | |
CN108874555A (en) | A kind of method and device for writing message to message-oriented middleware | |
US20150212795A1 (en) | Interfacing with a buffer manager via queues | |
CN108664335A (en) | The method and apparatus of queue communication is carried out by agency | |
CN103064749B (en) | Inter-process communication method | |
JPH11312141A (en) | Bus bridge | |
CN110990169B (en) | Structure and method for inter-process byte stream communication by using shared memory | |
CN103677971B (en) | Multithreaded processing system and method | |
CN103220230A (en) | Dynamic sharing buffering method supporting message across storage | |
CN105955711A (en) | Buffering method capable of supporting non-blocking missing processing | |
CN109508241B (en) | Interprocess data exchange method | |
CN106372013B (en) | Long-distance inner access method, device and system | |
US8972623B2 (en) | Efficient complex network traffic management in a non-uniform memory system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |