Commit 3898cea
authored
Fix/core latency measurement (#104)
* fix: BenchmarkResults::new() correctly sets one_way/round_trip flags
- Added one_way and round_trip parameters to BenchmarkResults::new()
- Updated TestConfiguration initialization to use passed parameters
instead of hardcoded false values
- Updated all call sites in benchmark.rs, benchmark_blocking.rs,
main.rs, results.rs, results_blocking.rs to pass config.one_way
and config.round_trip (or true, true in test code)
- This ensures JSON output test_config correctly reflects actual
test configuration
Cherry-picked from container-to-container-ipc branch (f6783d8).
AI-assisted-by: Claude claude-4.6-opus-high-thinking (Anthropic)
Made-with: Cursor
* fix: Fix timestamp and payload validation bugs across IPC mechanisms
- SHM blocking: update timestamp immediately before ring buffer write
to prevent stale timestamps when backpressure delays writes
- SHM blocking: add write_data_polling fallback with timestamp_offset
support for accurate timing under fallback conditions
- SHM blocking: replace pthread_cond_wait with timed variant (500us)
and add broken-condvar detection with polling fallback
- PMQ blocking: validate payload size against queue capacity before
sending to prevent silent truncation
- IPC mod: add one_way_latency_ns field to Message struct for
carrying server-measured latency in responses
Cherry-picked from container-to-container-ipc branch (6e2d41b).
SHM-direct changes excluded (require futex/cross-container
infrastructure not present in standalone mode).
AI-assisted-by: Claude claude-4.6-opus-high-thinking (Anthropic)
Made-with: Cursor
* perf: Optimize async SHM and PMQ timestamp accuracy
- Async SHM: replace byte-by-byte ring buffer copy with bulk memcpy
for 100x+ speedup on large messages (4KB-64KB now achieve 3-25us
vs previous 1-3ms)
- Async SHM: update timestamp immediately before IPC write for
accurate latency measurement (excludes async scheduling overhead)
- Async PMQ: capture timestamps inside spawn_blocking (immediately
before/after syscalls) to exclude async scheduling overhead from
measured latency
- Async PMQ: pre-compute timestamp offset for efficient in-place
updates
Note: Reverted adaptive spin optimization (spin_loop + yield_now)
back to sleep(10us) as it caused cross-process SHM round-trip
failures. The spin loop doesn't yield to the OS scheduler, starving
the server process.
Cherry-picked from container-to-container-ipc branch (8217998).
AI-assisted-by: Claude claude-4.6-opus-high-thinking (Anthropic)
Made-with: Cursor
* docs: Improve documentation for latency measurement changes
- BenchmarkResults::new(): document all 10 parameters including
new one_way/round_trip flags, and explain JSON propagation
- write_data_blocking(): update doc to reflect pthread_cond_timedwait
(was incorrectly referencing pthread_cond_wait), document
timestamp_offset parameter and broken-condvar fallback behavior
- write_data_polling(): add parameter docs and explain polling
interval and timeout
- read_data_blocking(): minor doc clarification
- send_message() in async SHM: fix duplicate summary line, replace
incorrect "adaptive spinning" with actual "poll-and-sleep" behavior
- receive_message() in async SHM: same adaptive spinning correction
- PMQ receive(): fix missing blank line between doc sections
All 254 tests passing, clippy clean on Rust 1.94.0.
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* fix: Address code review findings from latency measurement changes
Critical fix:
- write_data_polling() in shared_memory_blocking.rs was missing
pthread_cond_signal after writing data. A reader blocked on the
condvar path would never be woken when the writer used the
polling fallback, causing a potential deadlock.
Dead code removal:
- Remove unused _receive_time_ns capture in shared_memory.rs
receive_message() and posix_message_queue.rs receive().
Latency is computed by the benchmark caller, not inside the
transport layer.
Documentation fixes:
- shared_memory.rs receive_message(): remove inaccurate claim
that receive timestamp is used for latency calculation
- posix_message_queue.rs receive(): remove incorrect claim that
latency is stored in message's one_way_latency_ns field;
replace with accurate polling strategy description
- main.rs: restore buffer_size=0 comments in failure handlers
- mod.rs: remove println! calls from timestamp_offset test
All 254 tests passing, clippy clean on Rust 1.94.0.
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* test: Add config flag propagation tests for BenchmarkResults
- Add assertions to test_benchmark_results_new verifying one_way_enabled
and round_trip_enabled reflect constructor arguments
- Add test_benchmark_results_config_flags_false verifying flags are
correctly set to false (not hardcoded to true)
- Add test_benchmark_results_config_flags_mixed verifying one_way-only
and round_trip-only combinations propagate correctly
- Total test count: 256 passed, 0 failed
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* test: Add ring buffer wrap-around and config flag coverage tests
- Add test_ring_buffer_wrap_around to exercise the two-part
copy_nonoverlapping code path when data wraps past the end
of the shared memory ring buffer
- Add test_benchmark_results_config_flags_false verifying
one_way/round_trip flags correctly set to false
- Add test_benchmark_results_config_flags_mixed verifying
one_way-only and round_trip-only combinations
- Add flag propagation assertions to test_benchmark_results_new
- Total test count: 257 passed, 0 failed
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* test: Add write_data_polling coverage test for blocking SHM
- Add test_write_data_polling_and_read exercising the polling-based
write fallback path directly:
- Validates basic write + read round-trip via polling path
- Validates in-place timestamp update when timestamp_offset is
provided
- Validates shutdown detection when buffer is full
- Total test count: 258 passed, 0 failed
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* fix: Fix Windows CI build errors in new tests
- Add #[cfg(unix)] to test_write_data_polling_and_read since
write_data_polling() is unix-only (uses pthread primitives)
- Replace IpcMechanism::UnixDomainSocket with SharedMemory in
test_benchmark_results_config_flags_mixed since UDS variant
is #[cfg(unix)] only
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* fix: Remove container-IPC scope creep from blocking SHM write path
- Revert write_data_blocking() to simple pthread_cond_wait, removing
timed condvar, broken-condvar detection, and polling fallback logic
that was intended for container-to-container IPC support
- Remove write_data_polling() method and associated #[allow(dead_code)]
- Remove test_write_data_polling_and_read test covering the removed
polling fallback
- Retain timestamp_offset parameter in write_data_blocking() for
accurate latency measurement (core to this PR)
- Apply cargo fmt whitespace fixes
- All tests passing (257 passed, 0 failed), clippy clean
AI-assisted-by: Claude claude-4.6-opus-high-thinking
Made-with: Cursor
* fix: Remove out-of-scope write_data_polling test
- Remove test_write_data_polling_and_read from blocking SHM tests
- This test exercises write_data_polling() which is a container-specific
fallback path and does not belong in this PR (per reviewer feedback)
- The function and test will be reintroduced in the container-to-container
IPC branch where it is needed
AI-assisted-by: Claude Sonnet 4 (claude-sonnet-4-20250514)
Made-with: Cursor
* docs: Document why TCP/UDS skip timestamp refresh before send
- Add doc comments to write_message() in tcp_socket.rs and
unix_domain_socket.rs explaining that the timestamp is not
refreshed after serialization (unlike SHM and PMQ)
- The gap between to_bytes() and the kernel write_all() is only
nanoseconds of CPU work with no userspace backpressure loop or
async scheduling hop, making timestamp error negligible
- Addresses reviewer feedback on PR #104 regarding TCP/UDS
timestamp handling relative to issue #98
AI-assisted-by: Claude Sonnet 4 (claude-sonnet-4-20250514)
Made-with: Cursor1 parent c4a7962 commit 3898cea
12 files changed
Lines changed: 420 additions & 73 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
494 | 494 | | |
495 | 495 | | |
496 | 496 | | |
| 497 | + | |
| 498 | + | |
497 | 499 | | |
498 | 500 | | |
499 | 501 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
720 | 720 | | |
721 | 721 | | |
722 | 722 | | |
| 723 | + | |
| 724 | + | |
723 | 725 | | |
724 | 726 | | |
725 | 727 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1574 | 1574 | | |
1575 | 1575 | | |
1576 | 1576 | | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
527 | 533 | | |
| 534 | + | |
528 | 535 | | |
529 | 536 | | |
530 | 537 | | |
| |||
538 | 545 | | |
539 | 546 | | |
540 | 547 | | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
541 | 551 | | |
542 | 552 | | |
543 | 553 | | |
544 | 554 | | |
545 | 555 | | |
546 | 556 | | |
547 | 557 | | |
548 | | - | |
| 558 | + | |
| 559 | + | |
549 | 560 | | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
550 | 568 | | |
551 | 569 | | |
552 | 570 | | |
| |||
649 | 667 | | |
650 | 668 | | |
651 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
652 | 675 | | |
653 | 676 | | |
654 | 677 | | |
| |||
657 | 680 | | |
658 | 681 | | |
659 | 682 | | |
660 | | - | |
661 | | - | |
662 | | - | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
663 | 687 | | |
664 | 688 | | |
665 | 689 | | |
| |||
682 | 706 | | |
683 | 707 | | |
684 | 708 | | |
685 | | - | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
686 | 712 | | |
687 | 713 | | |
688 | 714 | | |
| |||
692 | 718 | | |
693 | 719 | | |
694 | 720 | | |
695 | | - | |
696 | | - | |
697 | | - | |
698 | | - | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
699 | 724 | | |
700 | 725 | | |
701 | 726 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
395 | | - | |
396 | | - | |
| 394 | + | |
397 | 395 | | |
398 | | - | |
399 | 396 | | |
400 | | - | |
| 397 | + | |
401 | 398 | | |
402 | 399 | | |
403 | 400 | | |
404 | 401 | | |
405 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
| |||
415 | 418 | | |
416 | 419 | | |
417 | 420 | | |
418 | | - | |
| 421 | + | |
419 | 422 | | |
420 | 423 | | |
421 | 424 | | |
| |||
0 commit comments