- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
免责声明:这在技术上与学校项目相关,但我已经和我的教授谈过,他也对此感到困惑。
我有一个 nginx 负载均衡器反向代理到几个 uwsgi + flask 应用程序。这些应用程序旨在处理非常高的吞吐量/负载。我的 uwsgi 响应时间非常好,nginx 服务器的 CPU 使用率和平均负载都很低,但总体请求时间非常高。
我调查了这个问题,我发现的所有线程都说这总是由客户端连接速度慢引起的。但是,请求是由同一网络上的脚本发出的,并且这个问题不会影响任何其他人的设置,所以在我看来这是我的 nginx 配置的问题。这让我完全难住了,因为 nginx 成为这样的瓶颈似乎闻所未闻。
为了了解问题的严重性,存在三种主要请求类型:添加图片、搜索和添加推文(这是推文的克隆)。
对于添加图像,总体请求时间平均比上游响应时间长约 20 倍。对于搜索,它是 3 倍,加上推文 1.5。我对这里的差异的理论是,添加图像来回发送的数据量比搜索或添加推文大得多,搜索比添加推文大得多。
我的 nginx.conf 是:
user www-data;
pid /run/nginx.pid;
worker_processes auto;
worker_rlimit_nofile 30000;
events {
worker_connections 30000;
}
http {
# Settings.
sendfile on;
tcp_nopush on;
tcp_nodelay on;
client_body_buffer_size 200K;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# SSL.
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
# Logging
log_format req_time '$remote_addr - $remote_user [$time_local] '
'REQUEST: $request '
'STATUS: $status '
'BACK_END: $upstream_addr '
'UPSTREAM_TIME: $upstream_response_time s '
'REQ_TIME: $request_time s ';
'CONNECT_TIME: $upstream_connect_time s';
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log req_time;
# GZIP business
gzip on;
gzip_disable "msie6";
# Routing.
upstream media {
server 192.168.1.91:5000;
}
upstream search {
least_conn;
server 192.168.1.84:5000;
server 192.168.1.134:5000;
}
upstream uwsgi_app {
least_conn;
server 192.168.1.85:5000;
server 192.168.1.89:5000;
server 192.168.1.82:5000;
server 192.168.1.125:5000;
server 192.168.1.86:5000;
server 192.168.1.122:5000;
server 192.168.1.128:5000;
server 192.168.1.131:5000;
server 192.168.1.137:5000;
}
server {
listen 80;
server_name localhost;
location /addmedia {
include uwsgi_params;
uwsgi_read_timeout 5s;
proxy_read_timeout 5s;
uwsgi_pass media;
}
location /media {
include uwsgi_params;
uwsgi_read_timeout 5s;
proxy_read_timeout 5s;
uwsgi_pass media;
}
location /search {
include uwsgi_params;
uwsgi_read_timeout 5s;
proxy_read_timeout 5s;
uwsgi_pass search;
}
location /time-search {
rewrite /time-search(.*) /times break;
include uwsgi_params;
uwsgi_pass search;
}
location /item {
include uwsgi_params;
uwsgi_read_timeout 5s;
proxy_read_timeout 5s;
if ($request_method = DELETE) {
uwsgi_pass media;
}
if ($request_method = GET) {
uwsgi_pass uwsgi_app;
}
if ($request_method = POST) {
uwsgi_pass uwsgi_app;
}
}
location / {
include uwsgi_params;
uwsgi_read_timeout 5s;
proxy_read_timeout 5s;
uwsgi_pass uwsgi_app;
}
}
}
我的 uwsgi ini 是:
[uwsgi]
chdir = /home/ubuntu/app/
module = app
callable = app
master = true
processes = 25
socket = 0.0.0.0:5000
socket-timeout = 5
die-on-term = true
home = /home/ubuntu/app/venv/
uid = 1000
buffer-size=65535
single-interpreter = true
如能提供有关此问题原因的任何见解,我们将不胜感激。
最佳答案
所以,我想我明白了。通过阅读 nginx 文档 (https://www.nginx.com/blog/using-nginx-logging-for-application-performance-monitoring/),似乎需要注意三个指标:upstream_response_time、request_time 和 upstream_connect_time。我关注的是 upstream_response_time 和 request_time 之间的区别。
然而,upstream_response_time 是上游接受请求和返回响应之间的时间。它不包括 upstream_connect 时间,或与上游服务器建立连接所需的时间。在 uwsgi 的上下文中,这非常重要,因为如果没有可用的 worker 来接受请求,该请求将被置于积压中。我认为请求等待积压的时间可能算作 upstream_connect_time,而不是 nginx 中的 upstream_response_time,因为 uwsgi 还没有读取任何字节。
不幸的是,我不能 100% 确定,因为我从来没有在记录 upstream_connect_time 的地方运行“缓慢”。但是我改变的唯一提高我的分数的事情只是“让 uwsgi 更快”的改变(投入更多的核心来搜索,增加数据库中的复制因子以使搜索更快)......所以是的,答案只是为了增加应用程序的吞吐量。
关于nginx 和 uwsgi : large difference between upstream response time and request time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43991536/
根据这个article , git push --set-upstream 已弃用,应改用 git push --set-upstream-to。 但是当我检查 git push文档,我只能找到--s
无意中,创建了一个分支remotes/upstream/upstream/develop。上游受 GitHub 控制。标准删除命令失败: $ git fetch --all $ git branch
我的网站在端口 80 (http) 上运行,我使用 nginx 没有任何问题。下面是我在 nginx 中使用的默认文件 server { listen 80; server_name
这个问题在这里已经有了答案: Undo a Git merge that hasn't been pushed yet (35 个答案) 关闭 9 年前。 这个问题与其他问题的不同之处在于,我想在恢
我们在 NGINX 后面有带有 Jersey 服务 API 的 tomcat。我们开发的一个新的流式 API 在我们直接调用 Tomcat 时运行良好,但在通过 NGINX 调用它时开始没有响应。 查
在我的 Remote 列表中,我看到:(git branch -r) upstream/HEAD -> upstream/master 当然,我有一个 upstream/master,origin 是
git rebase upstream/master 和 git pull --rebase upstream master 之间有区别吗?如果有,那是什么?远程可以是任何远程,不一定是上游。 最佳答
我正在尝试按照一些步骤为 GitHub 上的存储库做贡献,但其中一个步骤不起作用。步骤在这里:https://github.com/wdbm/qTox/blob/master/CONTRIBUTING
我使用本教程部署了一个 Django 网站 https://jee-appy.blogspot.com/2017/01/deply-django-with-nginx.html 该网站可从互联网 ww
TL; 博士 Nginx 日志时出现什么http/tcp 现象upstream prematurely closed connection while reading response header
我有一个 Django 应用程序,用户可以使用该应用程序使用多个视频创建视频拼贴画。问题是,在生产中,当将视频上传到 amazon s3 时,我得到一个 502 错误的网关(在本地工作正常)。有谁知道
我的 rails nginx/unicorn 服务器出现上游超时错误。我已尝试解决此问题,但没有找到适合我的解决方案。 我正在粘贴我在 nginx error.log 文件中得到的确切错误: ups
我目前总是在我的用户正在执行的查询中得到 502...这通常返回 872 行并且需要 2.07 才能在 MySQL 中运行。然而,它返回了很多信息。 (每一行都包含很多东西)。有什么想法吗? 运行 D
我在错误日志中收到如下 nginx 错误: [error] 4257#0: *3470 upstream timed out (110: Connection timed out) while rea
我试图将更改从上游 pull 到我的分支中。我试过 git fetch https://github.com/someuser/someproject,但它顽固地拒绝做任何事情。它只是说了一些完全隐晦
/编辑我做了the answer to the question mentioned above的建议授予对注册表的访问权限,如下所示: sudo mkdir -p /usr/local/etc/mo
配置例子 ? 1
我用 upstream和 proxy用于负载平衡。 指令 proxy_pass http://upstream_name使用默认端口,即 80。 但是,如果上游服务器不监听此端口,则请求将失败。 如何
我使用 nginx 作为代理服务器将请求转发到我的 gunicorn 服务器。当我运行 sudo nginx -t -c/etc/nginx/sites-enabled/mysite 时,出现以下错误
我的 git 似乎一团糟。 我首先重命名了一个名为分支 Sprint/13/Story/XXX-11 的分支 使用这个: git branch -m Sprint13/Story/XXX-11 这并没
我是一名优秀的程序员,十分优秀!