Automatically calculate the values for JVM parameters such as Xmx and Xms
Check Ahead
-
[x] I have searched the issues of this repository and believe that this is not a duplicate.
-
[ ] I am willing to try to implement this feature myself.
Why you need it?
Automatically calculate the values for JVM parameters such as Xmx and Xms based on the current memory value. This way, when container specs are upgraded—for example, from 2c4g to 4c8g—no manual intervention is required to modify environment variables.
How it could be?
No response
Other related information
No response
现在的distribution/bin/seata-setup.sh文件里面默认是令JVM_XMX:="2048m"的然后也可以支持JVM参数注入(PR #5529),意思是要修改一下.sh文件使得能自动获得环境的内存值然后根据某种规则来适配JVM参数吗?还是只是单纯的获得参数
The current distribution/bin/seata-setup.sh file sets JVM_XMX:="2048m" by default, and it also supports JVM parameter injection (PR #5529). Does this mean we need to modify the .sh file to automatically obtain the memory value of the environment and then adapt the JVM parameters according to some rules? Or is it just about obtaining the parameters
现在的distribution/bin/seata-setup.sh文件里面默认是令JVM_XMX:="2048m"的然后也可以支持JVM参数注入(PR #5529),意思是要修改一下.sh文件使得能自动获得环境的内存值然后根据某种规则来适配JVM参数吗?还是只是单纯的获得参数
The current distribution/bin/seata-setup.sh file sets JVM_XMX:="2048m" by default, and it also supports JVM parameter injection (PR #5529). Does this mean we need to modify the .sh file to automatically obtain the memory value of the environment and then adapt the JVM parameters according to some rules? Or is it just about obtaining the parameters
目前已经可以通过参数注入方式,但是这样不够灵活,当未设置对应参数时只能使用默认值。所以我们需要设计一个合理的xms和xmx以及堆外内存占用在不同内存规格下的百分比,比如4g以下堆内存占用70% 以上则是75%之类的,每个不同的规格有不同的算法占比。
Currently we can inject JVM parameters, but that approach isn’t flexible enough: if a specific parameter isn’t set we fall back to a fixed default. We therefore need a policy to calculate reasonable Xms/Xmx settings and off-heap (direct/native) memory shares based on the host’s total memory. For example, use a heap of about 70% of total RAM for machines under 4 GB and about 75% for larger machines. Each memory tier should have its own percentage or calculation rule so the JVM options are derived automatically and adapt to different instance sizes.
现在的distribution/bin/seata-setup.sh文件里面默认是令JVM_XMX:="2048m"的然后也可以支持JVM参数注入(PR #5529),意思是要修改一下.sh文件使得能自动获得环境的内存值然后根据某种规则来适配JVM参数吗?还是只是单纯的获得参数 The current distribution/bin/seata-setup.sh file sets JVM_XMX:="2048m" by default, 和 it also supports JVM parameter injection (PR #5529). Does this mean we need to modify the .sh file to automatically obtain the memory value of the environment and then adapt the JVM parameters according to some rules? Or is it just about obtaining the parameters
目前已经可以通过参数注入方式,但是这样不够灵活,当未设置对应参数时只能使用默认值。所以我们需要设计一个合理的xms和xmx以及堆外内存占用在不同内存规格下的百分比,比如4g以下堆内存占用70% 以上则是75%之类的,每个不同的规格有不同的算法占比。
Currently we can inject JVM parameters, but that approach isn’t flexible enough: if a specific parameter isn’t set we fall back to a fixed default. We therefore need a policy to calculate reasonable Xms/Xmx settings and off-heap (direct/native) memory shares based on the host’s total memory. For example, use a heap of about 70% of total RAM for machines under 4 GB and about 75% for larger machines. Each memory tier should have its own percentage or calculation rule so the JVM options are derived automatically and adapt to different instance sizes.
我想尝试一下,我现在的想法是通过修改seata-setup.sh文件来实现自动读取容器然后根据某些算法来分配使用的内存,当然优先使用用户输入的参数,并且加个是否使用“自动读取内存”的开关,然后我再在本地测试试验一下
I want to give it a try. My current idea is to modify the seata-setup.sh file to automatically read containers and then allocate the used memory based on certain algorithms. Of course, priority will be given to the parameters entered by the user. Additionally, I plan to add a switch to determine whether to use "automatic memory reading". After that, I will conduct some local tests
@LegendPei Maybe not only the seata-setup.sh shuold be optimized, the seata-server.bat is needed to be optimized because of the hardcode of JVM parameter
@LegendPei I believe that, by default, if a user hasn’t explicitly set JVM parameters (for example, -Xmx) those values should be automatically calculated from the host’s total memory. This auto-calculation should not be limited to containerized environments — it must also support virtual machines and bare‑metal (physical) deployments.
@LegendPei I believe that, by default, if a user hasn’t explicitly set JVM parameters (for example, -Xmx) those values should be automatically calculated from the host’s total memory. This auto-calculation should not be limited to containerized environments — it must also support virtual machines and bare‑metal (physical) deployments.
seata-server.bat作为windows物理机的启动,目前只支持-Xmx2048m -Xms2048m的硬编码启动,但是要实现自动分配内存好像有点复杂困难,因为windows批处理好像没有内置命令直接获取内存总量,我想对于这一块先做支持环境变量的内存分配吧,然后做一下测试
Currently, seata-server.bat, when launched on a Windows physical machine, only supports hard-coded startup with the options -Xmx2048m and -Xms2048m. However, achieving automatic memory allocation seems somewhat complex and challenging, as Windows batch processing does not seem to have a built-in command to directly obtain the total memory. I think for this part, we should first support memory allocation using environment variables, and then conduct some testing