Commit 87bf05a
committed
networking: don't sort reserved port ranges before adding to bitmap
During a large volume dispatch load test, I discovered that a lot of the total
scheduling time is being spent calling `structs.ParsePortRanges` repeatedly, 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) SetNode` method that calls the offending `ParsePortRanges`
merges all the ports into the `UsedPorts` map 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 of `ParsePortRanges` is 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 3x.
Ref: https://github.com/hashicorp/nomad/blob/v1.10.4/nomad/structs/network.go#L201
Fixes: #266541 parent 1916a16 commit 87bf05a
File tree
5 files changed
+47
-78
lines changed- .changelog
- nomad/structs
5 files changed
+47
-78
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
493 | 493 | | |
494 | 494 | | |
495 | 495 | | |
496 | | - | |
| 496 | + | |
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| |||
507 | 507 | | |
508 | 508 | | |
509 | 509 | | |
510 | | - | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
511 | 513 | | |
512 | 514 | | |
513 | 515 | | |
514 | | - | |
| 516 | + | |
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
| |||
526 | 528 | | |
527 | 529 | | |
528 | 530 | | |
529 | | - | |
| 531 | + | |
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
533 | 535 | | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
534 | 539 | | |
535 | 540 | | |
536 | 541 | | |
537 | 542 | | |
538 | 543 | | |
539 | | - | |
| 544 | + | |
540 | 545 | | |
541 | 546 | | |
542 | 547 | | |
543 | 548 | | |
544 | 549 | | |
545 | 550 | | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
| 551 | + | |
561 | 552 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
966 | 966 | | |
967 | 967 | | |
968 | 968 | | |
969 | | - | |
| 969 | + | |
| 970 | + | |
970 | 971 | | |
971 | 972 | | |
972 | 973 | | |
973 | 974 | | |
974 | | - | |
975 | | - | |
976 | | - | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
977 | 979 | | |
978 | 980 | | |
979 | 981 | | |
| |||
995 | 997 | | |
996 | 998 | | |
997 | 999 | | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
998 | 1020 | | |
999 | 1021 | | |
1000 | 1022 | | |
1001 | 1023 | | |
1002 | 1024 | | |
1003 | 1025 | | |
1004 | | - | |
1005 | | - | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
1006 | 1033 | | |
1007 | 1034 | | |
1008 | 1035 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3739 | 3739 | | |
3740 | 3740 | | |
3741 | 3741 | | |
3742 | | - | |
3743 | | - | |
3744 | | - | |
3745 | | - | |
3746 | | - | |
3747 | 3742 | | |
3748 | 3743 | | |
3749 | 3744 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7283 | 7283 | | |
7284 | 7284 | | |
7285 | 7285 | | |
7286 | | - | |
7287 | | - | |
7288 | | - | |
7289 | | - | |
7290 | | - | |
7291 | | - | |
7292 | | - | |
7293 | | - | |
7294 | | - | |
7295 | | - | |
7296 | | - | |
7297 | | - | |
7298 | | - | |
7299 | | - | |
7300 | | - | |
7301 | | - | |
7302 | | - | |
7303 | | - | |
7304 | | - | |
7305 | | - | |
7306 | | - | |
7307 | | - | |
7308 | | - | |
7309 | | - | |
7310 | | - | |
7311 | | - | |
7312 | | - | |
7313 | | - | |
7314 | | - | |
7315 | | - | |
7316 | | - | |
7317 | | - | |
7318 | | - | |
7319 | | - | |
7320 | | - | |
7321 | | - | |
7322 | | - | |
7323 | | - | |
7324 | | - | |
7325 | | - | |
7326 | | - | |
7327 | | - | |
7328 | | - | |
7329 | | - | |
7330 | | - | |
7331 | | - | |
7332 | | - | |
7333 | 7286 | | |
7334 | 7287 | | |
7335 | 7288 | | |
| |||
0 commit comments