-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Default setting is only 1 CPU on macOS for the QEMU machine which causes surprises on Java #17066
Comments
The problem is having a default that satisfies everyone is hard. We have no idea how users are using the VM. Although I agree that @baude @ashley-cui WDYT? |
A friendly reminder that this issue had no activity for 30 days. |
I agree two cores and allow users to set it in the containers.conf |
Two would be better than one, but why the absolute number of 2? What speaks technically against a percentage of the hardware CPUs? For example 50% would match well most desktop and notebook CPUs as those either have hyperthreads or on arm64 Macbooks 50% performance cores. The idle usage of just having the podman VM machine running without any container is barely noticeable on a Macbook, even when having set it to a number equivalent to 50% of all hardware cores. That might have been different in the past when the decision was made for the 1 default and I also remember to have seen higher idle usage in the past. The common use case from the enduser side is to run either a container without CPU limits or with CPU limits and then usually a minimum 2 are given with "podman run --cpus=2.0 ID" as example. The use case with --cpus is currently prevented to the enduser as those don't want/know how to change the backend VM machine settings. About the use case without CPU limit I'd say the enduser expectations would be to have all or at least a good fraction of the hardware CPUs available for peak loads as that's usually the use case for containers without limits. You want to run a quick configuration test or just having a container in the background for test-build purposes and then you want to have it complete it's batch jobs quickly and not being throttled by a single core. So my recommendation would be 50% of the hardware core number as default. Waiting for discussions... |
To illustrate the problem with the default 1 better, especially for Java where it is more obvious than with other applications: Here the results with podman's default of 1 machine CPU on macOS where for the enduser an unexpected 1 CPU is seen on Java while he assigns 3 CPUs to the container.
I'm installing OpenJDK 17 there and checking with the Java method Runtime.getRuntime().availableProcessors() about the available number of CPUs. That method is also used internally in Java for calculation thread pool sizes for application frameworks and JVM-internals. When only 1 CPU is available, the JVM switched to some unusual mode of SerialGC you will never see on any server system and I guess threadpool calculations of many open source frameworks will also be surprised. At the same time, the Linux cgroup shows 3 CPUs, that's visible in the cpu.max parameter read in the example above (300000 / 100000 = 3). Or on systems with the old cgroups v1 it would be cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us and When changing the podman VM machine to more CPUs, for example podman machine set --cpus=5 and then running the same 3-CPU container as in the example above, the result in Java / jshell is 3 as expected and for the cgroups also as expected 300000 / 100000. For an unlimited container the result is then 5 inside Java as expected and in cgroups max / 100000 also as expected. [updated some more details with 5 CPUs] |
A friendly reminder that this issue had no activity for 30 days. |
Sure N Cores would be fine. @ashley-cui PTAL |
Issue Description
Quick summary for those who have the same issue and need a quick workaround: Add the number of CPUs during machine init. Example: podman machine init --cpus 8
On the macOS podman where QEMU is used for the underlying Linux VM machine, the default machine size is only 1 CPU and not all CPUs of the hardware. When starting a container with podman run --cpus=4 for example, the resulting cgroups CPU quota and CPU period makes it looks like there are 4 CPUs available now, but other Linux parameters see only 1 CPU.
That causes surprises in application behavior for example for Java applications as the JVM only sees 1 CPU and the Java method Runtime.availableProcessors() returns 1 which is then used by many open source frameworks to calculate Thread pool sizes.
To check that output on the command line with Java 11 or newer:
echo 'Runtime.getRuntime().availableProcessors();/exit' | jshell -q
There may be a good reason why the choice was made originally to use 1 as default in podman on QEMU. Then please close the bug with a note about that. Otherwise if there is concern to overuse the hardware, maybe as alternative 50% of the hardware CPUs as default?
Steps to reproduce the issue
Steps to reproduce the issue
Describe the results you received
1 CPU
Describe the results you expected
podman info output
Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
Yes
Additional environment details
macOS Ventura 13.1 on intel hardware
Additional information
Only relevant for podman on QEMU, i.e. on macOS and most likely also on Windows.
The text was updated successfully, but these errors were encountered: