python - (502 Bad Gateway) Handle load on uwsgi_server + flask + nginx -
we serving flask using uwsgi. seems work fine till tried load test on site.
on increased load site went down , started giving 502 - bad gateway.
errors:
2017/08/17 15:22:57 [error] 1209#1209: *2394 connect() unix:/home/ubuntu/opt/myproject/app/myproject.sock failed (11: resource temporarily unavailable) while connecting upstream, client: ip_address_here, server: ads.myproject.co, request: "get /app_wall?aff_id=2&google_aid=&ios_ifa_md5=&ios_ifa=&mac_address=&device_id=&device_os_version=4.1&device_os=android&device_model=gt-i9082&device_brand=samsung&country_code=mu&city=port louis&referer=&user_agent=dalvik%2f1.6.0+%28linux%3b+u%3b+android+4.1.2%3b+gt-i9082+build%2fjzo54k%29&ip=105.235.159.208&datetime=2017-08-17+15%3a22%3a57&affiliate_sub5=15343&affiliate_sub4=&affiliate_sub3=&affiliate_sub2=56292544&affiliate_sub1=6ac48ae370ec4e30b942aac4c7d1e127&affiliate_source=1252_15343&creative_url_id=0&host_offer_id=325771&transaction_id=102a553241d652c43754314686378d&mobile_carrier=%3f®ion_code=pu http/1.1", upstream: "uwsgi://unix:/home/ubuntu/opt/myproject/app/myproject.sock:", host: "nativeads.mobilepad.co" 2017/08/17 15:25:19 [error] 1212#1212: *2525 upstream timed out (110: connection timed out) while reading response header upstream, client: xxx.yyy.zz.aza, server: ads.myproject.co, request: "get /app_wall?params=params http/1.1", upstream: "uwsgi://unix:/home/ubuntu/opt/myproject/app/myproject.sock", host: "nativeads.mobilepad.co" 2017/08/17 15:25:36 [error] 1212#1212: *2530 upstream timed out (110: connection timed out) while reading response header upstream, client: ipaddress_here, server: sync.myproject.co.uk, request: "get /login/ http/1.1", upstream: "uwsgi://unix:/home/ubuntu/opt/myproject/app/myproject.sock", host: "sync.myproject.co.uk"
following details of our architecture: (sorry long details)
nginx (/etc/nginx/sites-available/file.conf) :
# upstream component nginx needs connect upstream flask { server unix:///home/ubuntu/opt/app/myproject.sock fail_timeout=0; # file socket } # configuration of server server { server_name sync.myproject.co.uk; listen 80; client_max_body_size 2000m; proxy_read_timeout 6000; location / { include uwsgi_params; uwsgi_pass unix:/home/ubuntu/opt/myproject/app/myproject.sock; } } server { server_name ads.myproject.co; listen 80; client_max_body_size 2000m; location / { return http://myproject.co.uk; } location ~ ^/(some_endpoint|someendpoint)/*{ include uwsgi_params; uwsgi_pass unix:/home/ubuntu/opt/myproject/app/myproject.sock; } location /static/ { include uwsgi_params; uwsgi_pass unix:/home/ubuntu/opt/myproject/app/myproject.sock; } error_page 404 = @foobar; location @foobar { return 301 http://myproject.co.uk; } } server { server_name cdn.myproject.co.uk; listen 80; client_max_body_size 2000m; location / { include uwsgi_params; uwsgi_pass unix:/home/ubuntu/opt/myproject/app/myproject.sock; } }
project.ini
[uwsgi] module = wsgi master = true processes = 16 socket = myproject.sock chmod-socket = 660 vacuum = true die-on-term = true env = production_environment=true logto = logs/%n.log enable-threads = true
please let me know if anymore details needed.
i not able understand problem nginx, flask app or aws instance size application hosted. using m4.2xlarge instance of now.
also if tell me how check count of number of requests/sec give stats too.
p.s: have tried increasing server instance size m4.4xlarge
same issue.
Comments
Post a Comment