24.2.9. 配置 JGroups 发送和接收缓冲区

解决缓冲区大小警告

默认情况下,JGroups 配置有特定的发送和接收缓冲区值;但是,您的操作系统可能会限制可用的缓冲区大小,JBoss EAP 可能无法使用其配置的缓冲区值。在这种情况下,您将在 JBoss EAP 日志中看到类似如下的警告:

WARNING [org.jgroups.protocols.UDP] (ServerService Thread Pool -- 68)
JGRP000015: the send buffer of socket DatagramSocket was set to 640KB, but the OS only allocated 212.99KB.
This might lead to performance problems. Please set your max send buffer in the OS correctly (e.g. net.core.wmem_max on Linux)
WARNING [org.jgroups.protocols.UDP] (ServerService Thread Pool -- 68)
JGRP000015: the receive buffer of socket DatagramSocket was set to 20MB, but the OS only allocated 212.99KB.
This might lead to performance problems. Please set your max receive buffer in the OS correctly (e.g. net.core.rmem_max on Linux)

要解决这个问题,请查阅您的操作系统文档来了解如何增加缓冲区大小。对于 Red Hat Enterprise Linux 系统,以 root 用户身份编辑 /etc/sysctl.conf,为在系统重启后保留的缓冲区大小配置最大值。例如:

# Allow a 25MB UDP receive buffer for JGroups
net.core.rmem_max = 26214400
# Allow a 1MB UDP send buffer for JGroups
net.core.wmem_max = 1048576

修改 /etc/sysctl.conf 后,运行 sysctl -p 以使更改生效。

配置 JGroups 缓冲器大小

您可以通过在 UDP 和 TCP JGroups 堆栈中设置以下传输属性来配置 JBoss EAP 使用的 JGroups 缓冲区大小:

UDP Stack
  • ucast_recv_buf_size
  • ucast_send_buf_size
  • mcast_recv_buf_size
  • mcast_send_buf_size
TCP Stack
  • recv_buf_size
  • send_buf_size

可以使用管理控制台或管理 CLI 来配置 JGroups 缓冲区大小。

使用以下语法,通过管理 CLI 设置 JGroups 缓冲区大小属性:

/subsystem=jgroups/stack=STACK_NAME/transport=TRANSPORT/property=PROPERTY_NAME:add(value=BUFFER_SIZE)

以下是一个管理 CLI 命令示例,可将 tcp 堆栈上的 recv_buf_size 属性设置为 20000000

/subsystem=jgroups/stack=tcp/transport=TRANSPORT/property=recv_buf_size:add(value=20000000)

也可以使用管理控制台,从 Configuration 选项卡导航到 JGroups 子系统,单击 View,选择 Stack 选项卡,选择适当的堆栈,再单击传输,编辑 Properties 字段,以此配置 JGroups 缓冲区大小。