大网数据广告活动
服务器运维问答

Centos System V IPC message queue limits

· 52CE 我爱测

[Although I'm working in perl I believe that this question relate to Linux System V IPC APIs and limits rather that the anything perl-specific.] I have two Centos machines, each at CentOS Linux release 7.9.2009 (Core). I have a p…

问题原文

原帖链接 · djna · CC BY-SA 4.0

[Although I'm working in perl I believe that this question relate to Linux System V IPC APIs and limits rather that the anything perl-specific.]

I have two Centos machines, each at CentOS Linux release 7.9.2009 (Core).

I have a program that forks a child and then uses System V IPC messages to communicate with the child, the child prepares answers ands sends them to the parent.

On one machine we see expected behaviour. The child produces batches of messages, the parent consumes them. Occasionally the child works a little faster than the parent, and so may fill the queue, the child then waits until the parent consumes some messages and proceeds.

We can inspect the queue sizes with ipcs -q and see that the default limit of 10 messages per queue is occasionally reached, the child pauses, and then we see the queue empty as expected.

We believe that the queue limits are specified in files in /proc/sys/fs/mqueue/ and for example msg_max is seen to be the expected 10. These values are identical on both machines.

We also can view user ulimits relating to queue using ulimit -q and see a value in excess of 800,000 bytes on both machines.

The puzzle is that on our second machine we see the child write three messages to the queue and attempt to write the fourth and wait - we deliberately set no timeout. It is as though the writer believes that the queue is full, even though ipcs -q shows only 3 items in the queue. At this point in time the parent is not yet attempting to read the messages.

------ Message Queues --------
key        msqid      owner      perms      used-bytes   messages    
0x0000002a 1474560    dave      600        15020        3  

The question: what, other than the queue being full, would cause msgsnd() to pause? The pause seems to continue indefinitely, the child proceeds when the parent becomes active and reads some messages.

We have many machines running this code without issue. It fails on three new machines. Presumably there is some environment-specific feature that interacts with our code?

The perl code uses a thin library above the system calls (details elided)

$mQueue = msgget(IPC_PRIVATE, IPC_CREAT | S_IRUSR | S_IWUSR);
msgsnd( $mQueue, pack("l! a*", length($msg), $msg);

已采纳解答

原帖链接 · djna · CC BY-SA 4.0

The problem was that the default max size of queue kernel setting was set to a low value.

This cal be viewed using the -l option to ipcs.

ipcs -q -l

------ Messages Limits --------
max queues system wide = 3671
max size of message (bytes) = 8192
default max size of queue (bytes) = 16384

The kernel setting in question is stored in

/proc/sys/kernel/msgmnb

and can be changed (as root) using the command

 sysctl -w kernel.msgmnb=65536
 kernel.msgmnb = 65536

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-11-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。