Skip to content

cmd-compress: Use multithreading for xz#632

Merged
cgwalters merged 1 commit intocoreos:masterfrom
jlebon:pr/compress-multi-threads
Jul 19, 2019
Merged

cmd-compress: Use multithreading for xz#632
cgwalters merged 1 commit intocoreos:masterfrom
jlebon:pr/compress-multi-threads

Conversation

@jlebon
Copy link
Copy Markdown
Member

@jlebon jlebon commented Jul 18, 2019

xz compression is notoriously slow. Fortunately, it supports a
multi-threaded mode. The compression ratio is affected by this, but not
really in any significant way (see [1]).

On k8s though, we have to make sure to respect any cgroup limits set on
the CPU. (Though in CentOS right now, we run without any limits set at
all, so this will make a huge dent in our build times).

[1] https://yeah.nah.nz/misc/xz-thread/

Comment thread src/cmd-compress
in_k8s = re.search(r'.*kubepods.*', f.read())
if in_k8s:
quota = get_cpu_param('cfs_quota_us')
# are k8s limits enforced?
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you invent this code or take it from somewhere else?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, threw a link to that and added a check for the period.

I also found https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/resource_management_guide/sec-cpu really useful. Essentially though, I'm trying to avoid xz scheduling e.g. 20 threads because it sees 20 CPUs when really it'd be throttled at e.g. 200m.

xz compression is notoriously slow. Fortunately, it supports a
multi-threaded mode. The compression ratio is affected by this, but not
really in any significant way (see [1]).

On k8s though, we have to make sure to respect any cgroup limits set on
the CPU. (Though in CentOS right now, we run without any limits set at
all, so this will make a huge dent in our build times).

[1] https://yeah.nah.nz/misc/xz-thread/
@jlebon jlebon force-pushed the pr/compress-multi-threads branch from 0f054e9 to 82b9705 Compare July 18, 2019 23:01
@cgwalters
Copy link
Copy Markdown
Member

OK, thanks for the links - I think the context here will be really useful for someone reading this later.

@cgwalters cgwalters merged commit 62dc473 into coreos:master Jul 19, 2019
jlebon added a commit to jlebon/fedora-coreos-pipeline that referenced this pull request Jul 19, 2019
xz compression should be much faster now with:
[1] coreos/coreos-assembler#632

So let's drop the hack and always use xz. For the developer use case,
the MINIMAL parameter means there's only really the `qcow2` to compress.
jlebon added a commit to coreos/fedora-coreos-pipeline that referenced this pull request Jul 19, 2019
xz compression should be much faster now with:
[1] coreos/coreos-assembler#632

So let's drop the hack and always use xz. For the developer use case,
the MINIMAL parameter means there's only really the `qcow2` to compress.
@jlebon jlebon deleted the pr/compress-multi-threads branch July 6, 2020 20:32
jlebon added a commit to jlebon/rpm-ostree that referenced this pull request Jan 21, 2021
Otherwise, it defaults to `_SC_NPROCESSORS_ONLN` (via `%make_build` ->
`%_smp_mflags` -> `%_smp_build_ncpus` -> `%{getncpus}` ->
https://github.com/rpm-software-management/rpm/blob/48c0f28834eb377a54f27ee0b6950af7e6d537b8/rpmio/macro.c#L583).
And that's going to be wrong in Kubernetes because we're constrained via
cgroups.

The `%_smp_build_ncpus` macro allows overriding this logic via
`RPM_BUILD_NCPUS`.

See: coreos/coreos-ci#23
See: coreos/coreos-assembler#632
See: coreos/coreos-assembler#1287
openshift-merge-robot pushed a commit to coreos/rpm-ostree that referenced this pull request Jan 21, 2021
Otherwise, it defaults to `_SC_NPROCESSORS_ONLN` (via `%make_build` ->
`%_smp_mflags` -> `%_smp_build_ncpus` -> `%{getncpus}` ->
https://github.com/rpm-software-management/rpm/blob/48c0f28834eb377a54f27ee0b6950af7e6d537b8/rpmio/macro.c#L583).
And that's going to be wrong in Kubernetes because we're constrained via
cgroups.

The `%_smp_build_ncpus` macro allows overriding this logic via
`RPM_BUILD_NCPUS`.

See: coreos/coreos-ci#23
See: coreos/coreos-assembler#632
See: coreos/coreos-assembler#1287
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants