Skip to content

tcp nodelay to avoid batching TCP packets, handle multi-frame messages/packets#15

Merged
davidt315 merged 12 commits into
mainfrom
david1244-tcp-nodelay
May 21, 2026
Merged

tcp nodelay to avoid batching TCP packets, handle multi-frame messages/packets#15
davidt315 merged 12 commits into
mainfrom
david1244-tcp-nodelay

Conversation

@davidt315
Copy link
Copy Markdown
Contributor

@davidt315 davidt315 commented May 19, 2026

Fix 1: Add the TCP Nodelay- batching the TCP packets with the default behavior of the TCP socket resulted in many dropped packets (see comment).

Fix 2: Handle multiple protocol messages in the TCP buffer - the driver's receive callback on the TCP stream made an assumption that there would only be a single AXIO protocol message within a single receive buffer from the TCP message. After this fix, it iterates through the TCP buffer to find any additional AXIO prefixed protocol messages

Fix 3: Handle multiple CAN Frames within a single AXIO Protocol message. Each AXIO prefixed protocol message can have more than a single CAN Frame packed inside of it. The previous iteration of the driver ignored any frames beyond the first one. This fix iterates through all the possible CAN Frames

Potential Fix 4: Increase the buffer size to prevent any chance of overflow on the receive buffer reaching the end. Not observed but a cautious forward looking fix. Also sets the buffer once as a member variable instead of creating a new buffer on the heap per-receive for minor efficiency boost

Known Remaining Issues:

  1. Not handling axiomatic-generated heartbeats or sending heartbeats to the axiomatic to keep connection live, which has not been a problem as they are silently skipped and TCP doesn't require sending the heartbeats from the documentation
  2. Not handling axiomatic status messages or CAN FD streams, which has not been a problem in current usage
  3. No UDP support

@davidt315
Copy link
Copy Markdown
Contributor Author

davidt315 commented May 19, 2026

With fix:

automat@robot01:~$ python3 ~/can_compare.py --duration 10 --gap 1 --rx-iface can0 --tx-iface vcan0 --data DEDEDEDEDEDEDEDE --load 90
Output directory: /tmp/can_compare
Duration:         10s
Senders:          4x  (estimated load 80%)

Running... 1s remaining  
                        Draining pipeline... done
                                                 WARNING: bus load 100.2% exceeded 95% — results may be affected by TX queue overflow.

Results
  Sent    (vcan0):  37607
  Received (can0): 37607
  Delta:                    0
  Loss:                     0.00%
  Bus load:                 100.2%

Inter-frame timing
  TX candump (vcan0): avg=0.266ms  min=-0.002ms  max=1.067ms
  RX candump (can0): avg=0.266ms  min=0.098ms  max=0.751ms
  pcap       (br0): avg=0.308ms  min=0.008ms  max=0.998ms

Data comparison
  Corrupted frames (same position, different content): 0
  All frame data matches.

Output files:
  TX candump: /tmp/can_compare/candump_vcan0.log
  RX candump: /tmp/can_compare/candump_can0.log
  pcap:       /tmp/can_compare/axiomatic_capture.pcap

Before Fix:

automat@robot01:~$ python3 ~/can_compare.py --duration 10 --gap 1 --rx-iface can0 --tx-iface vcan0 --data DEDEDEDEDEDEDEDE --load 60
Output directory: /tmp/can_compare
Duration:         10s
Senders:          3x  (estimated load 60%)

Running... 1s remaining  
                        Draining pipeline... done

Results
  Sent    (vcan0):  28178
  Received (can0): 26965
  Delta:                    1213
  Loss:                     4.30%
  Bus load:                 75.1%

Inter-frame timing
  TX candump (vcan0): avg=0.355ms  min=-0.006ms  max=1.073ms
  RX candump (can0): avg=0.377ms  min=0.125ms  max=148.078ms
  pcap       (br0): avg=12.805ms  min=0.014ms  max=243.582ms
  note: pcap shows TCP segment intervals — bridge is batching ~4.8 frames/segment (779 segments, 3771 frames)

Data comparison
  Corrupted frames (same position, different content): 0
  All frame data matches.

Output files:
  TX candump: /tmp/can_compare/candump_vcan0.log
  RX candump: /tmp/can_compare/candump_can0.log
  pcap:       /tmp/can_compare/axiomatic_capture.pcap

@davidt315 davidt315 changed the title tcp nodelay to avoid batching TCP packets tcp nodelay to avoid batching TCP packets, handle multi-frame messages/packets May 20, 2026
Comment thread axiomatic_adapter/src/axiomatic_adapter.cpp
Comment thread axiomatic_adapter/src/axiomatic_adapter.cpp
Comment thread axiomatic_adapter/src/axiomatic_adapter.cpp Outdated
@davidt315 davidt315 merged commit 78c0a8f into main May 21, 2026
4 of 5 checks passed
@davidt315 davidt315 deleted the david1244-tcp-nodelay branch May 21, 2026 22:01
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