Skip to content

Conversation

dustinblack
Copy link
Collaborator

@dustinblack dustinblack commented Sep 10, 2025

Depends on PR #68

Description

This pull request introduces CPU affinity pinning for both the client and server tasks, allowing
for more stable and repeatable benchmark results by minimizing OS scheduling noise. It also
includes a series of fixes to resolve build failures and logic errors that arose during the
implementation.

Key Changes:

  • CPU Affinity:
    • Introduced --server-affinity <CORE_ID> to pin the server task to a specific CPU core.
    • Introduced --client-affinity <CORE_ID> to pin the client task to a specific CPU core.
    • Added the core_affinity crate to manage this functionality.
  • Improved Validation: The error message for an invalid (out-of-bounds) core ID is descriptive.
  • Documentation: The README.md has been updated to include instructions on how to use the new CPU
    affinity flags.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  • Tests pass locally
  • Added tests for new functionality
  • Updated documentation

Checklist

  • Code follows style guidelines
  • Self-review completed
  • Comments added for complex code
  • Documentation updated
  • No breaking changes (or marked as breaking)

This comment was marked as outdated.

This comment was marked as outdated.

This commit introduces the ability to pin the benchmark server to a specific CPU core using the --server-affinity command-line argument.

This feature is useful for creating a more stable and repeatable testing environment by reducing performance noise from CPU context switching and cache misses.

Key changes:

- Added 'core_affinity' crate as a dependency.

- Added '--server-affinity' and '--client-affinity' CLI flags.

- Implemented the logic to spawn the server task on a dedicated thread with the specified CPU affinity.

- Added unit tests for argument parsing and the new affinity-spawning logic.

- Updated documentation and configuration display to reflect the new options.

Note: Client-side affinity is parsed but not yet implemented.

AI-assisted-by: Gemini 2.5 Pro

feat: Add client-side CPU affinity

This commit implements client-side CPU affinity and refactors the test execution logic to support it.

Key changes:

- Refactored single-threaded test functions to spawn the client logic in a separate task with the specified affinity.

- Client tasks now return raw latency data, which is then processed by the main task.

- Updated README.md to document the new --server-affinity and --client-affinity flags.

- Added documentation to the refactored functions in benchmark.rs.

AI-assisted-by: Gemini 2.5 Pro

fix(build): Correct task spawning and error handling

This commit addresses several compilation errors and warnings that arose from recent changes to the task spawning and affinity logic.

The primary issue was a 'moved value' error with the oneshot sender ('tx') used for server readiness signaling. This was resolved by refactoring the server-spawning logic to ensure the sender is only used once.

This change introduced a type mismatch in the 'match' statement handling the result of 'spawn_with_affinity', which has also been corrected.

Additionally, several instances of an erroneous double '??' operator on non-Result types were fixed, and unused imports were removed.

AI-assisted-by: Gemini 2.5 Pro
Improves the clarity of the command-line help text by moving the '--server-affinity' and '--client-affinity' flags from the 'Concurrency' heading to a more appropriate 'Affinity' heading.

AI-assisted-by: Gemini 2.5 Pro
Adds the configured server and client CPU affinity values to the benchmark configuration summary that is printed at the start of a run. This provides immediate visual confirmation that the affinity settings have been applied.

AI-assisted-by: Gemini 2.5 Pro
Resolves a race condition where `core_affinity::get_core_ids()` would intermittently report only a single available core, causing affinity validation to fail.

The fix ensures that the list of available cores is retrieved from the main thread (which has an unrestricted view) before entering the `spawn_blocking` context, where the thread's affinity might already be constrained. This makes the core ID validation robust against the race condition.

AI-assisted-by: Gemini 2.5 Pro
@dustinblack dustinblack marked this pull request as ready for review September 15, 2025 15:48
Copy link

🚨 Uncovered lines in this PR

  • src/benchmark.rs: 201-202, 326-335, 424, 426-429, 432-435, 437, 439-441, 444, 446-447, 468, 648, 650-653, 656-659, 661, 663-664, 669-671, 673-674, 678-680, 682, 685-686, 688, 693, 695-696, 706-707, 709-710, 712-714, 717-718, 720, 722-725, 728-730, 732, 734-736, 738, 741-742, 748, 750-754, 759-760, 763, 765-767, 769-773, 775, 779, 819, 821-824, 827-830, 832, 834-835, 840-842, 844-845, 849-851, 853-856, 858-859, 862, 865-866, 868, 873, 875-876, 886-887, 889-890, 892-894, 897-898, 900, 902-905, 908-910, 912, 916, 919-921, 923, 925-926, 928, 932-933, 937, 940-941, 947, 949-952, 954-955, 960-961, 964, 966-968, 970-974, 976, 980, 1198, 1200-1203, 1206-1209, 1211, 1213-1214, 1219-1221, 1223-1224, 1228-1229, 1231-1234, 1236-1237, 1239, 1242-1243, 1245, 1250, 1252-1253, 1263-1264, 1266-1268, 1270-1272, 1275-1276, 1278, 1280-1283, 1286-1288, 1290, 1293, 1296-1298, 1300, 1302-1306, 1308, 1311-1312, 1316, 1319-1320, 1326, 1328-1330, 1332-1333, 1335-1338, 1343-1344, 1347-1348, 1350-1352, 1354-1358, 1360, 1364-1365, 1368
  • src/cli.rs: 529-530, 672-679
  • src/utils.rs: 60, 66, 72-73, 77-79, 81, 83

📊 Code Coverage Summary

File Line Coverage Uncovered Lines
src/benchmark.rs 7.12% 163, 165-166, 168, 175, 182, 186-187, 189, 192-202, 305, 309, 311-312, 314, 317-322, 324, 326-336, 340-345, 349-351, 354, 358-360, 363-369, 372-377, 381-386, 390-391, 412-414, 417, 420-429, 432-435, 437, 439-441, 444, 446-447, 454-455, 458, 460-463, 467-468, 470-471, 496, 501-502, 507-509, 512-515, 517-522, 524, 526-529, 531, 534, 558, 564-565, 569-571, 574-577, 579-584, 586, 588-591, 593, 596, 630, 636-637, 640, 643-653, 656-659, 661, 663-664, 669-671, 673-674, 678-680, 682, 685-686, 688, 693, 695-696, 703-704, 706-707, 709-710, 712-714, 717-718, 720, 722-725, 728-730, 732, 734-736, 738, 741-742, 748, 750-754, 759-760, 763, 765-767, 769-773, 775, 779, 781, 801, 807-808, 811, 814-824, 827-830, 832, 834-835, 840-842, 844-845, 849-851, 853-856, 858-859, 862, 865-866, 868, 873, 875-876, 883-884, 886-887, 889-890, 892-894, 897-898, 900, 902-905, 908-910, 912, 916, 919-921, 923, 925-926, 928, 932-933, 937, 940-941, 947, 949-952, 954-955, 960-961, 964, 966-968, 970-974, 976, 980, 982, 1004, 1014, 1016-1017, 1020-1022, 1026-1027, 1031-1032, 1034, 1039-1040, 1044-1046, 1051-1052, 1055-1056, 1070, 1079, 1081-1082, 1085-1087, 1092-1093, 1098-1099, 1101, 1106-1107, 1111-1113, 1118-1119, 1122-1123, 1141, 1146-1147, 1149-1150, 1154-1156, 1161-1165, 1167, 1169-1171, 1179, 1186-1187, 1190, 1193-1203, 1206-1209, 1211, 1213-1214, 1219-1221, 1223-1224, 1228-1229, 1231-1234, 1236-1237, 1239, 1242-1243, 1245, 1250, 1252-1253, 1260-1261, 1263-1264, 1266-1268, 1270-1272, 1275-1276, 1278, 1280-1283, 1286-1288, 1290, 1293, 1296-1298, 1300, 1302-1306, 1308, 1311-1312, 1316, 1319-1320, 1326, 1328-1330, 1332-1333, 1335-1338, 1343-1344, 1347-1348, 1350-1352, 1354-1358, 1360, 1364-1365, 1368, 1370, 1435, 1449, 1465-1466, 1476
src/cli.rs 39.05% 498, 500-501, 503, 508, 510, 514, 520-521, 524-530, 600, 613, 615, 620-622, 624, 627-629, 631-632, 634, 638-640, 645, 647, 650-651, 654-655, 657, 659, 662-663, 665, 668-669, 672-679, 682-683, 686-687, 690-691, 694-695, 697-699
src/ipc/mod.rs 27.50% 250, 252-255, 558-559, 574-575, 593-594, 625, 628, 631, 636, 663-664, 678, 680, 700, 702, 816, 819, 821-823, 825-827
src/ipc/posix_message_queue.rs 51.81% 131-132, 204-206, 208, 215, 220, 317-320, 322, 327, 330, 340, 413, 416, 420, 422, 425, 433, 448, 511, 540-543, 549, 556, 569-570, 575, 658-659, 666-668, 676-677, 682, 732-733, 741, 758-759, 770-771, 782-783, 800-801, 849, 851, 853-855, 857-859, 861-862, 865-870, 872-874, 878, 880-884, 886-888, 892-894, 896-898, 904, 933-934, 945-946, 968-969
src/ipc/shared_memory.rs 51.85% 61, 72, 130, 134, 211-212, 222-223, 254, 287, 294, 323-324, 350-352, 354, 372-374, 376-377, 379, 390, 396, 400, 407, 413, 416-418, 421, 425, 429-430, 435-436, 449, 471, 477, 495, 507-511, 513, 521-522, 528, 531, 537, 542, 548, 570-571, 574-575, 578, 580, 585-586, 593-594, 598-601, 604, 610-614, 617-618, 625-627, 629, 631-636, 638-639, 642-643, 645-649, 656, 660-661, 669-671, 674-677, 680, 682, 686, 688-689, 691, 695-696, 698-700, 702
src/ipc/tcp_socket.rs 48.85% 31-32, 61, 66, 89, 106-108, 111, 117-119, 122, 129-131, 134, 140-142, 145, 160, 164, 168-170, 177-178, 181, 200, 203, 215, 220, 227, 237, 241-243, 245, 250-254, 256, 271-273, 279, 284-286, 292, 295, 301, 309, 316, 325, 328, 351-352, 355-356, 359-360, 365-366, 383, 400, 425-426, 442, 444-447, 450, 452, 456, 458-460, 462, 465-466, 468-470, 472
src/ipc/unix_domain_socket.rs 47.85% 29-30, 58, 63, 86, 96, 115-117, 120, 126-128, 131, 138-140, 143, 149-151, 154, 169, 173, 177-179, 186-187, 190, 198, 213, 219, 231, 241, 245-247, 260-265, 271, 277-278, 284, 287, 293, 305, 308, 328, 335-336, 339-340, 343-344, 349-350, 358, 371, 388, 401-402, 418, 420-423, 426, 428, 432, 434-436, 438, 441-442, 444-446, 448, 457
src/logging.rs 0.00% 63, 69-70, 72, 74-75, 78-83, 87
src/main.rs 0.00% 54, 56, 63-66, 74, 76-80, 83-86, 88-89, 91-92, 94, 96-102, 108, 110-113, 116, 121-123, 128, 130, 136, 139, 144-147, 152-153, 158-160, 165, 167-169, 171, 176-178, 184, 189, 192-193, 197, 199-201, 204-205, 207, 213, 217-218, 220-222, 224-225, 228, 237, 240-241, 244-245, 268, 276, 281, 286-287
src/metrics.rs 32.56% 455-460, 493-494, 552, 558, 579-582, 649-651, 653, 656-659, 681, 683, 686-687, 690, 705, 707-708, 710, 713, 718, 732-734, 736, 763, 767-768, 773, 777, 779, 782-785, 788, 791-794, 814, 817-818, 822, 824, 829-831, 833, 835-836, 838, 876, 880-881, 884-885, 888-889, 896-899, 901-902, 904, 915, 917-918, 920-921, 923-924, 926-927, 930-932, 937, 939-940, 944-947, 949-950, 952, 955-964, 980, 984, 1005, 1007-1008, 1013
src/results.rs 4.75% 110-117, 122, 127, 130-131, 137-138, 140-142, 144, 158, 165-168, 170-173, 197, 204-207, 214-215, 223, 225-226, 230-231, 233-234, 568-572, 575, 579, 582-585, 587-588, 591, 606, 611-612, 614-615, 618, 642-644, 646-647, 650, 654, 657-658, 660-661, 681-683, 687-688, 692, 699-700, 702, 704, 707-708, 711-713, 717, 720, 726-728, 731-732, 735, 739-742, 744, 748-753, 757, 765, 769-770, 773, 795-796, 799-800, 803-804, 824-826, 829-830, 834-836, 839, 859-860, 863, 866, 869, 872-873, 876, 884-888, 890-891, 893, 895-897, 899-900, 903, 911-914, 917, 926-930, 934-935, 937-938, 941, 944, 967-968, 970, 976-977, 980-983, 1007-1011, 1014-1017, 1020-1027, 1037-1038, 1057-1058, 1060-1064, 1066, 1083-1084, 1086-1091, 1093, 1111, 1113-1118, 1136, 1139, 1155-1156, 1162-1163, 1171-1173, 1175-1177, 1179-1180, 1182-1183, 1185-1186, 1188, 1190-1191, 1193-1196, 1198-1200, 1202-1204, 1207, 1211-1212, 1220-1225, 1227-1228, 1232-1234, 1237-1239, 1241-1242, 1245-1246, 1255-1258, 1262-1264, 1268, 1270, 1273-1274, 1278-1280, 1284, 1291-1295, 1297, 1484-1485, 1501-1503, 1519-1521, 1542-1546, 1549-1552, 1554-1555, 1560-1563, 1565-1566, 1571-1574, 1577, 1579-1580, 1582-1592, 1610-1612, 1615-1618, 1623-1626, 1630-1631, 1633, 1656-1659, 1662-1664, 1666, 1669, 1671, 1673, 1678, 1680-1685, 1687-1688, 1691-1692, 1697, 1699-1700, 1702-1706, 1708-1709, 1712, 1714, 1717
src/utils.rs 48.15% 60, 66, 72-73, 77-79, 81, 83, 113-117
Total 26.22%

@dustinblack dustinblack marked this pull request as draft September 16, 2025 12:08
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.

1 participant