[关闭]
@bergus 2017-01-05T02:31:27.000000Z 字数 4238 阅读 1925

flask 优化

优化


  1. 并发4个线程:
  2. uwsgi -s :9090 -w myapp -p 4
  3. 主控制线程+4个线程:
  4. uwsgi -s :9090 -w myapp -M -p 4
  5. 执行超过30秒的client直接放弃:
  6. uwsgi -s :9090 -w myapp -M -p 4 -t 30
  7. 限制内存空间128M
  8. uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128
  9. 服务超过10000req自动respawn
  10. uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128 -R 10000
  11. 后台运行等:
  12. uwsgi -s :9090 -w myapp -M -p 4 -t 30 --limit-as 128 -R 10000 -d uwsgi.log
  1. 命令行参数 uwsgigevent做为模块uwsgi -s 127.0.0.1:8080 --processes 4 --loop gevent --enable-threads --async 128 --disable-logging --wsgi-file test.pyuwsgigevent内置uwsgi --http :8080 --file test.py --gevent 2000 -l 1000 -p 1 -L 参数解释
  2. uwsgigevent做为模块
  3. uwsgi -s 127.0.0.1:8080 --processes 4 --loop gevent --enable-threads --async 128 --disable-logging --wsgi-file test.py
  4. 如题谁有 uwsgi 的配置文件让我参考一下,我的配置老是出现 upstream prematurely closed connection while reading response header from upstream, client 这样的错误。 以下是我自己的配置: [uwsgi] #coding:utf-8
  5. uwsgi 启动时所使用的地址与端口
  6. socket = 127.0.0.1:8001
  7. master = true
  8. 指向网站目录
  9. chdir = /obj1/wechat/
  10. profiler = true
  11. enable-threads = true
  12. logdate = true
  13. memory-report=true
  14. limit-as = 6048
  15. daemnize = /obj1/wechat.log
  16. python 启动程序文件
  17. wsgi-file = manage.py
  18. python 程序内用以启动的 application 变量名
  19. callable = app
  20. 处理器数
  21. processes = 4
  22. 线程数
  23. threads = 2
  24. #状态检测地址 stats = 127.0.0.1:9191
  25. uwsgi_read_timeout = 600
  26. harakiri = 1200
  27. gevent = 100
  28. ./uwsgi -w tests.cpubound_green -s :3031 --async 30 --ugreen
  29. ./uwsgi -s :3031 -w simple_app --daemonize /tmp/mylog.log
  30. ./uwsgi -s :3031 -w simple_app --logto /tmp/mylog.log
  31. # logto2 only opens the log file after privileges have been dropped to the specified uid/gid.
  32. ./uwsgi -s :3031 -w simple_app --uid 1001 --gid 1002 --logto2 /tmp/mylog.log
  33. uwsgi --gevent 100 --gevent-monkey-patch --http :9090 -M --processes 4 --wsgi-file wsgi.py
  34. %(uri) -> REQUEST_URI
  35. %(method) -> REQUEST_METHOD
  36. %(user) -> REMOTE_USER
  37. %(addr) -> REMOTE_ADDR
  38. %(host) -> HTTP_HOST
  39. %(proto) -> SERVER_PROTOCOL
  40. %(uagent) -> HTTP_USER_AGENT (starting from 1.4.5)
  41. %(referer) -> HTTP_REFERER (starting from 1.4.5)
  1. # report uwsgi配置
  2. [uwsgi]
  3. base = /opt/report/dimension_report
  4. app = api.api_listener
  5. module = %(app)
  6. home = /opt/report/venv
  7. pythonpath = %(base)
  8. # processes = 16
  9. workers=16
  10. # lazy=True
  11. socket = /opt/report/dimension_report/%n.sock
  12. #socket = 127.0.0.1:1234
  13. chmod-socket = 644
  14. callable = app
  15. logto = /var/log/uwsgi/%n.log
  16. # report nginx 配置
  17. user centos;
  18. worker_processes 4;
  19. pid /var/run/nginx.pid;
  20. events {
  21. worker_connections 1024;
  22. }
  23. http {
  24. include mime.types;
  25. default_type application/octet-stream;
  26. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  27. # '$status $body_bytes_sent "$http_referer" '
  28. # '"$http_user_agent" "$http_x_forwarded_for"';
  29. #access_log logs/access.log main;
  30. access_log /var/log/nginx/access.log;
  31. error_log /var/log/nginx/error.log;
  32. sendfile on;
  33. #tcp_nopush on;
  34. #keepalive_timeout 0;
  35. keepalive_timeout 65;
  36. gzip on;
  37. gzip_disable "msie6";
  38. server {
  39. listen 80;
  40. server_name localhost;
  41. charset utf-8;
  42. client_max_body_size 75M;
  43. location / { try_files $uri @api_listener; }
  44. location @api_listener {
  45. include uwsgi_params;
  46. uwsgi_pass unix:/opt/report/dimension_report/app_uwsgi.sock;
  47. # uwsgi_pass 127.0.0.1:1234;
  48. }
  49. }
  50. }
  1. # report service uwsgi
  2. [uwsgi]
  3. base = /opt/services/services
  4. app = api.service_rest_api
  5. module = %(app)
  6. home = /opt/services/venv
  7. pythonpath = %(base)
  8. # processes = 16
  9. workers=12
  10. enable-threads=true
  11. # lazy=True
  12. # socket = /opt/services/services/%n.sock
  13. uwsgi-socket = 127.0.0.1:1122
  14. uwsgi-socket = 127.0.0.1:1123
  15. uwsgi-socket = 127.0.0.1:1124
  16. uwsgi-socket = 127.0.0.1:1125
  17. uwsgi-socket = 127.0.0.1:1126
  18. uwsgi-socket = 127.0.0.1:1127
  19. uwsgi-socket = 127.0.0.1:1128
  20. uwsgi-socket = 127.0.0.1:1129
  21. chmod-socket = 644
  22. callable = app
  23. logto = /var/log/uwsgi/%n.log
  24. # report service nginx
  25. user centos;
  26. worker_processes 4;
  27. pid /var/run/nginx.pid;
  28. events {
  29. worker_connections 1024;
  30. }
  31. http {
  32. include mime.types;
  33. default_type application/octet-stream;
  34. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  35. # '$status $body_bytes_sent "$http_referer" '
  36. # '"$http_user_agent" "$http_x_forwarded_for"';
  37. #access_log logs/access.log main;
  38. access_log /var/log/nginx/access.log;
  39. error_log /var/log/nginx/error.log;
  40. sendfile on;
  41. #tcp_nopush on;
  42. #keepalive_timeout 0;
  43. keepalive_timeout 65;
  44. gzip on;
  45. gzip_disable "msie6";
  46. upstream uwsgicluster {
  47. server 127.0.0.1:1122;
  48. server 127.0.0.1:1123;
  49. server 127.0.0.1:1124;
  50. server 127.0.0.1:1125;
  51. server 127.0.0.1:1126;
  52. server 127.0.0.1:1127;
  53. server 127.0.0.1:1128;
  54. server 127.0.0.1:1129;
  55. }
  56. server {
  57. listen 80;
  58. server_name localhost;
  59. charset utf-8;
  60. client_max_body_size 75M;
  61. location / { try_files $uri @api_listener; }
  62. location @api_listener {
  63. include uwsgi_params;
  64. # uwsgi_pass unix:/opt/services/services/app_uwsgi.sock;
  65. uwsgi_pass uwsgicluster;
  66. }
  67. }
  68. }

快速部署Python应用:Nginx+uWSGI配置详解
nginx+uwsgi+flask配置记录
Managing the uWSGI server
在 Linux 下生成高强度密码的四种方法

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注