[uwsgi-body-read] Error reading 65536 bytes. Content-Length: 560903 consumed: 0 left: 560903 message

当使用uwsgi遇到Error reading 65536 bytes错误时,原因是文件上传超时或缓冲区溢出。可以通过设置`socket-timeout`以增加上传超时时间,以及调整`post-buffering`和`post-buffering-bufsize`来控制缓冲区大小,避免内存溢出。设置这两个参数可以有效解决大文件上传问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用uwsgi报以上错误,原因是上传文件是,文件稍大,首先上传时间长会引起timeout,然后上传文件需要保存到uwsgi的缓冲区,缓冲区超大小,解决方法是设置两个参数.

1.socket-timeout

上传文件时接收文件的超时时间,也就是说如果你设置socket-timeout为10s, 而10s到了文件还没有上传完,就会timeout的错.
socket-timeout
argument: required_argument
shortcut: -z
parser: uwsgi_opt_set_int
help: set internal sockets timeout

2.post-buffering

argument: required_argument
parser: uwsgi_opt_set_64bit
help: enable post buffering

参数解释:
enable http body buffering. uWSGI will save to disk all HTTP body bigger than the limit specified
post-buffering = 8192
will save to disk all the HTTP body bigger than 8K. This option is required for Rack applications as they require a rewindable input stream.

3.post-buffering-bufsize

argument: required_argument
parser: uwsgi_opt_set_64bit
help: set buffer size for read() in post buffering mode

参数解释:
set the internal buffer size during post buffering (this is the memory allocated to read chunks of the socket stream)
post-buffering-bufsize 65536
will allocate 64k as the buffer for socket recv(). For a 128k body two cycle/syscall will be used.
This is a very advanced option you will probably never need to touch

Refs:
1.http://simple-is-better.com/news/301
2.http://pythonic.zoomquiet.io/data/20110523113355/index.html
3.https://github.com/unbit/uwsgi/issues/363

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值