Backport of scheduler: don't sort reserved port ranges before adding to bitmap into release/1.10.x #26725
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport
This PR is auto-generated from #26712 to be assessed for backporting due to the inclusion of the label backport/1.10.x.
The below text is copied from the body of the original PR.
During a large volume dispatch load test, I discovered that a lot of the total scheduling time is being spent calling
structs.ParsePortRangesrepeatedly, in order to parse the reserved ports configuration of the node (ex. converting"80,8000-8001"to[]int{80, 8000, 8001}). A close examination of the profiles shows that the bulk of the time is being spent hashing the keys for the map of ports we use for de-duplication, and then sorting the resulting slice.The
(*NetworkIndex) SetNodemethod that calls the offendingParsePortRangesmerges all the ports into theUsedPortsmap of bitmaps at scheduling time. Which means the consumer of the slice is already de-duplicating and doesn't care about the order. The only other caller ofParsePortRangesis when we validate the configuration file, and that throws away the slice entirely.By skipping de-duplication and not sorting, we can cut down the runtime of this function by 30x and memory usage by 4x.
See my comment here for why memoizing the result proved to be impractical. This changeset also deletes the unused
ParseReservedHostPortsmethod and moves its tests into the tests forParsePortRanges(which is really what it was testing anyways).Ref: https://github.com/hashicorp/nomad/blob/v1.10.4/nomad/structs/network.go#L201
Fixes: #26654
I'm going to reproduce the test I ran that I've described in #26654 but in the meantime, here's a microbenchmark:
Contributor Checklist
changelog entry using the
make clcommand.ensure regressions will be caught.
and job configuration, please update the Nomad website documentation to reflect this. Refer to
the website README for docs guidelines. Please also consider whether the
change requires notes within the upgrade guide.
Reviewer Checklist
backporting document.
in the majority of situations. The main exceptions are long-lived feature branches or merges where
history should be preserved.
within the public repository.
Changes to Security Controls
Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
Overview of commits