-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientConnection uses too much heap when streaming files #2871
Comments
Actually it will not pull the whole file into memory. It should never allocate more than 2 * TCP_MSS bytes at a time (that's 2920 bytes). |
I see. Still that's quite a bit of memory for an embedded system. It caused my application to break. There's very little benefit to using a larger block size (see https://github.com/pellepl/spiffs/wiki/Performance-and-Optimizing) for the SPIFFS case. |
This optimization is mainly for TCP throughput, not for SPIFFS performance. I'll see if there is a nice way to configure TCP window size individually for each WifiClient connection, so that you can dial down buffer size of the application requires that. |
Is that really a necessary optimization for TCP throughput? The tcp_write documentation has this to say:
So shouldn't one just write in smaller chunks until MSS is reached and then call tcp_output to flush?
I actually want both good throughput and tight memory use, so I'd hate to configure a smaller TCP window size. |
Like this:
|
What throughput do you get with this change, compared to the version in the master branch? |
With a chunk size of 128 I get ~290 kb/s when curling a 1mb file. Chunk size 256 or the old code both achieve about 330kb/s. |
Looks good, if you can put up a pull request with this change that would be great. Thanks. |
It should be possible to stream arbitrary large files to a ClientContext. However this is done via a BufferedStreamDataSource which allocates a buffer in RAM to keep the whole memory chunk requested in get_buffer. These requests can ask for > 2800 bytes at a time.
To preserve memory the size of the chunk requested should be limited. The following patch achieves that:
diff --git a/libraries/ESP8266WiFi/src/include/ClientContext.h b/libraries/ESP8266WiFi/src/include/ClientContext.h
index d2ee090..df12760 100644
--- a/libraries/ESP8266WiFi/src/include/ClientContext.h
+++ b/libraries/ESP8266WiFi/src/include/ClientContext.h
@@ -346,6 +346,7 @@ protected:
can_send = 0;
}
size_t will_send = (can_send < left) ? can_send : left;
The text was updated successfully, but these errors were encountered: