Portenta H7 TCP Latency Issue #13518
-
Hello, I ran into a weird problem with TCP Connections on the Portenta H7 and I couldn't find any mention of it online Here are some measurements that should make it clear >>> measure_rtt()
Received b'Hello, server'
Round-trip time: 511.019 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 306.276 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 408.367 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 508.853 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 512.186 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 73.175 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 510.502 ms
>>> measure_rtt()
Received b'Hello, server'
Round-trip time: 512.188 ms
>>> The code I used: def measure_rtt(host='address', port=21212):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
start_time = time.ticks_us()
s.sendall(b'Hello, server')
data = s.recv(13)
end_time = time.ticks_us()
print('Received', repr(data))
print('Round-trip time:', time.ticks_diff(end_time, start_time) / 1000, 'ms')
s.close() Server (on a PC): def start_server(host='0.0.0.0', port=21212):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((host, port))
s.listen()
while True:
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data:
break
conn.sendall(data) Has anyone else run into this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 18 comments 14 replies
-
Beta Was this translation helpful? Give feedback.
-
@IHOXOHI Did you run |
Beta Was this translation helpful? Give feedback.
-
Hi Robert, |
Beta Was this translation helpful? Give feedback.
-
During the time that I have your attention, |
Beta Was this translation helpful? Give feedback.
-
INFO: this build requires mboot to be installed first |
Beta Was this translation helpful? Give feedback.
-
Yes, I think. The led change of state... The ACM0 is present. |
Beta Was this translation helpful? Give feedback.
-
So the board isn't. |
Beta Was this translation helpful? Give feedback.
-
I have pressed twice the reset button, the led has changed of color and rythme, and the ACM0 is still present. |
Beta Was this translation helpful? Give feedback.
-
The first one is after double press the reset button. |
Beta Was this translation helpful? Give feedback.
-
YES! |
Beta Was this translation helpful? Give feedback.
-
The board is impressive! |
Beta Was this translation helpful? Give feedback.
-
So, with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
Beta Was this translation helpful? Give feedback.
-
Hey, |
Beta Was this translation helpful? Give feedback.
-
Yo, |
Beta Was this translation helpful? Give feedback.
-
Getting back on topic here, I can reproduce the original reported latency issue of around 500ms. It occurs on any MicroPython port that uses lwIP (which includes the Portenta H7). The reason is because of this lwIP code in #ifndef TCP_TMR_INTERVAL
#define TCP_TMR_INTERVAL 250 /* The TCP timer interval in milliseconds. */
#endif /* TCP_TMR_INTERVAL */
#ifndef TCP_FAST_INTERVAL
#define TCP_FAST_INTERVAL TCP_TMR_INTERVAL /* the fine grained timeout in milliseconds */
#endif /* TCP_FAST_INTERVAL */
#ifndef TCP_SLOW_INTERVAL
#define TCP_SLOW_INTERVAL (2*TCP_TMR_INTERVAL) /* the coarse grained timeout in milliseconds */
#endif /* TCP_SLOW_INTERVAL */ Data that's written to the TCP socket is not actually committed to the wire (sent as an ETH packet) until Sending lots of data through a TCP socket has relatively high bandwidth, because this 500ms timeout is only used for small, on-off writes of data. You can try rebuilding the Portenta firmware with this interval changed. In #define TCP_TMR_INTERVAL 50 |
Beta Was this translation helpful? Give feedback.
-
Hey, |
Beta Was this translation helpful? Give feedback.
Getting back on topic here, I can reproduce the original reported latency issue of around 500ms. It occurs on any MicroPython port that uses lwIP (which includes the Portenta H7).
The reason is because of this lwIP code in
src/include/lwip/priv/tcp_priv.h
: