Skip to content

net: lib: http: allow configuring response chunk size #92971

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AndreyDodonov-EH
Copy link
Contributor

Fixes #92921

Introduce Kconfig HTTP_SERVER_STATIC_FS_RESPONSE_SIZE, size of individual chunks when serving files.

#define STATIC_FS_RESPONSE_SIZE \
COND_CODE_1( \
IS_ENABLED(CONFIG_HTTP_SERVER_COMPRESSION), \
(STATIC_FS_RESPONSE_BASE_SIZE + CONTENT_ENCODING_HEADER_SIZE), \
(STATIC_FS_RESPONSE_BASE_SIZE))
#ifdef CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be #if CONFIG_HTTP_SERVER_STATIC_FS_RESPONSE_SIZE > 0? Current #ifdef will always be true here (as we're inside #if defined(CONFIG_FILE_SYSTEM)).

The size of a single chunk when serving static files from the file system.
Please note that it is allocated on the stack of the HTTP server thread,
so CONFIG_HTTP_SERVER_STACK_SIZE has to be sufficiently large.
This config value must also be large enough to hold the headers in a single chunk.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add something like If set to 0, the server will use the minimal viable buffer size for the response. here (which accurately describes the current behavior I think).

config HTTP_SERVER_STATIC_FS_RESPONSE_SIZE
int "Size of static file system response buffer"
depends on FILE_SYSTEM
default 1024
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No stack overflow with such a large buffer? I wonder if it's needed to adjust the defaults for the server's stack size.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it is indeed too small.
My current setting (and it's enough for sending things in 2KB chunks in both direction and serving ca. 1MB files) is
CONFIG_HTTP_SERVER_STACK_SIZE=8192

I'd probably suggest a default of at least 4096 (now it is 3072)

Copy link
Contributor Author

@AndreyDodonov-EH AndreyDodonov-EH Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably go for defaults 4096 for HTTP_SERVER_STACK_SIZE and 512 for HTTP_SERVER_STATIC_FS_RESPONSE_SIZE

Copy link
Contributor

@rlubos rlubos Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could have a conditional default 4096 if FILE_SYSTEM (just make sure it's first before the unconditional one). Current stack default was fine so far I think (i've seen no issues), so if we increase the stack by 1KB, I think we could have the buffer set to 1024.

@AndreyDodonov-EH AndreyDodonov-EH force-pushed the feature/configure-static-fs-response-size branch from c562616 to 2e88910 Compare July 10, 2025 16:20
Introduce Kconfig HTTP_SERVER_STATIC_FS_RESPONSE_SIZE,
size of individual chunks when serving files.

Signed-off-by: Andrey Dodonov <Andrey.Dodonov@endress.com>
@AndreyDodonov-EH AndreyDodonov-EH force-pushed the feature/configure-static-fs-response-size branch from 2e88910 to 3d887e8 Compare July 10, 2025 17:05
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: HTTP HTTP client/server support area: Networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WebServer: improve speed of serving static files
3 participants