Maximum number of Message Queues

Source: Internet
Author: User

Message Queue:

1. one message per msgrcv, 1. the message will be removed from the kernel. each time msgrcv is sent to only one message, no matter how big a Buf your RCV uses to receive it, it is okay. If the bufsize of msgrcv is smaller than the actual size of the message, you can set a flag to indicate truncation. If this parameter is not set, an error is returned. Cannot be retrieved.

2. When the message is full, 0 is blocked by default. snd messages can enter the kernel only when the space is available.

If the message is empty, the default value is 0. The RCV message enters the process memory only when a message location exists.

3. If msgflg: msg_noerror is specified, if the message length obtained by the function is greater than msgsz, only msgsz length information is returned, and the remaining part is discarded. If this parameter is not specified, e2big will be returned, and the message will not be taken out in the queue. After a message is removed from the queue, the message is deleted from the queue.

 

Almost all Linux releases contain the IPCS command, which provides
IPC resource information. You can use IPCS to determine the current IPC restrictions of the system, and check the preceding
Status of the three types of IPC resources. For example, if the application fails to start, you can check the IPC usage on the system.
Determine if an IPC limit is exceeded. To determine the status of the system's IPC resources, you can
Run the IPCS command with the-u option.
# IPCS-u

------ Shared memory status --------
Segments allocated 32
Pages allocated 2361
Pages resident 253
Page swapped 982
Swap performance: 0 attempts 0 successes

------ Semaphore status --------
Used arrays = 128
Allocated semaphores = 256

------ Messages: Status --------

Allocated queues = 0
Used headers = 0
Used space = 0 bytes
For the IPC Resources Displayed by the "IPCS-U" command, you can use the "IPCS-L" command to determine its limits:
# IPCS-l

------ Shared memory limits --------
Max number of segments = 4096
Max seg size (Kbytes) = 32768
Max total shared memory (Kbytes) = 8388608
Min seg size (bytes) = 1

------ Semaphore limits --------
Max number of arrays = 128
Max semaphores per array = 250
Max semaphores system wide = 32000
Max ops per semop call = 32
Semaphore max value = 32767

------ Messages: Limits --------
Max queues system wide = 16 [maximum number of message queues in the system (up to 16 message queues are supported at the same time )]
Max size of message (bytes) = 8192 [maximum number of bytes for a single message]
Default Max size of queue (bytes) = 16384 [the default size of a single queue is 16384]
The above output indicates that the system has reached the upper limit of the number of semaphores array (or semaphores set. This restriction is acceptable.
This parameter is solved by adding the value of the Kernel Parameter semmni, which defines the set of semaphores that the system can possess.
Total number. In Linux, You can dynamically adjust the value of most kernel IPC parameters, or modify it statically.

 

Message Queue provides a way for processes to pass messages asynchronously. Creates a Message Queue using msgget ().
The sending and receiving processes can exchange messages through this message queue. The sending process sends messages
The specified message queue, and the receiver tries to get the message from the specified message queue. If there is no message in the queue
Then, the receiver blocks or returns a flag based on whether or not they want to wait.
Table 13-2 briefly describes the three Message Queue parameters provided in the current Linux 2.4/2.6 kernel implementation.
Table 13-2 kernel parameters related to message queues
Name: Describe the maximum value of the default value
Msgmni maximum number of message queues 16 2 GB
Msgmax maximum message length (in bytes) 8192 2 GB
Maximum number of bytes in msgmnb Message Queue: 16384 2 GB

Note that the maximum value given in Column 4th depends on the data type. The preceding three kernel parameters are of the int type.
On 32-bit Intel machines, the hard limit is 2 GB.
Linux also defines other parameters related to the currently unused message queue.
The following sections analyze the parameters related to message queue

 

13.5.1 msgmni
Msgmni defines the maximum number of message queues in the system. Like semaphores, message queues also have a correlation
. During system initialization, the kernel creates a pointer array pointing to the Message Queue identifier structure. The
The number of items in the array is determined by msgmni. For each message queue, the Linux kernel allocates 44B for the identifier to the message queue.
The column data structure is allocated 96 B. To obtain more message queue resources, you can dynamically increase the value of msgmni. And
The maximum number of Message Queue identifiers is limited by ipcmni. Msgmni has a default ceiling of 16 B.
It may not be enough to ensure smooth operation of some large database applications. If you want to run a database application on the system,
The default upper limit is B.
13.5.2 msgmax
Msgmax limits the message length that a process can send. This parameter is applied by the msgsnd () function. If you want to send
If the length of the sent message exceeds this value, an error is returned. This parameter can be adjusted at runtime.

13.5.3 msgmnb
Msgmnb determines the capacity of a message queue. The value of this parameter is stored in a message queue identifier structure.
Domain used to determine whether there is a space to queue new messages. The msgmnb value can be dynamically modified. The default value is
16384. Modifying the value affects the capacity of all new message queues. You can use the msgctl () system to call
Increase the capacity of existing message queues

Modify Message Queue Parameters

1. Permanent modification
Modify the/etc/sysctl. conf file under the root user.

The msgmax, msgmni, and msgmnb parameters have all been successfully modified: In the configuration file/etc/sysctl. add kernel in Conf. msgmax = value kernel. msgmni = value kernel. msgmnb = value and then run sysctl-P to modify

Max queues system wide = // msgmni
Max size of message (bytes) = // msgmax
Default Max size of queue (bytes) = // msgmnb

2. Temporary Modification
Root User sysctl-W kernel. msgmnb = 1048576

 

The message queue does not find any asynchronous information in linuxc/C ++, but java..net does. In addition, Windows message queues are implemented asynchronously.

Http://hi.baidu.com/yelangdefendou/item/410e5a13b61b33038ebde4e9

Http://hi.baidu.com/w_empty/item/467c004fa0b2460ac116132b

Http://wenku.baidu.com/view/96c978dd360cba1aa811dac5.html

Http://hi.baidu.com/w_empty/item/467c004fa0b2460ac116132b

Http://hi.baidu.com/yelangdefendou/item/410e5a13b61b33038ebde4e9

Http://blog.csdn.net/goodluckwhh/article/details/8841999

Http://www.jb51.net/article/37412.htm

Contact Us

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

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

A Free Trial That Lets You Build Big!

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

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

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