From a236030e4d2aaa23cfaa0b501a6c567c31c6ff98 Mon Sep 17 00:00:00 2001 From: otto Date: Tue, 16 Mar 2021 06:44:14 +0000 Subject: [PATCH] A socket buffer is not the best size to read from a disk. Use st_blksize to set high water mark; florian@ --- usr.sbin/httpd/server_file.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/usr.sbin/httpd/server_file.c b/usr.sbin/httpd/server_file.c index d62590037ae..6b01ba7f3d6 100644 --- a/usr.sbin/httpd/server_file.c +++ b/usr.sbin/httpd/server_file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server_file.c,v 1.68 2020/05/22 07:18:17 bentley Exp $ */ +/* $OpenBSD: server_file.c,v 1.69 2021/03/16 06:44:14 otto Exp $ */ /* * Copyright (c) 2006 - 2017 Reyk Floeter @@ -224,6 +224,7 @@ server_file_request(struct httpd *env, struct client *clt, char *path, struct media_type *media; const char *errstr = NULL; int fd = -1, ret, code = 500; + size_t bufsiz; if ((ret = server_file_method(clt)) != 0) { code = ret; @@ -269,9 +270,10 @@ server_file_request(struct httpd *env, struct client *clt, char *path, goto fail; } - /* Adjust read watermark to the socket output buffer size */ + /* Adjust read watermark to the optimal file io size */ + bufsiz = MAXIMUM(st->st_blksize, 64 * 1024); bufferevent_setwatermark(clt->clt_srvbev, EV_READ, 0, - clt->clt_sndbufsiz); + bufsiz); bufferevent_settimeout(clt->clt_srvbev, srv_conf->timeout.tv_sec, srv_conf->timeout.tv_sec); @@ -304,7 +306,7 @@ server_partial_file_request(struct httpd *env, struct client *clt, char *path, struct media_type *media, multipart_media; struct range_data *r = &clt->clt_ranges; struct range *range; - size_t content_length = 0; + size_t content_length = 0, bufsiz; int code = 500, fd = -1, i, nranges, ret; char content_range[64]; const char *errstr = NULL; @@ -403,9 +405,10 @@ server_partial_file_request(struct httpd *env, struct client *clt, char *path, goto fail; } - /* Adjust read watermark to the socket output buffer size */ + /* Adjust read watermark to the optimal file io size */ + bufsiz = MAXIMUM(st->st_blksize, 64 * 1024); bufferevent_setwatermark(clt->clt_srvbev, EV_READ, 0, - clt->clt_sndbufsiz); + bufsiz); bufferevent_settimeout(clt->clt_srvbev, srv_conf->timeout.tv_sec, srv_conf->timeout.tv_sec); -- 2.20.1