I am python user and tried to make python REST API to run a service.
Yet, the stress test showed that the python cannot handle even just 50 users per second!
I guess the error comes out when the nginx cannot assign requested address while the gunicorn workers restarts, but the max time states that such simple function takes 674ms.
I think such high request time is caused by the bottleneck from request queue, but wonder my setting is that much wrong for such simple programme. \
The dummy function code is
@application.route('/dummy', methods = ['POST'])
def helloworldmaker():
return jsonify('Hello World')
With the function I ran Jmeter test and the settings, results and environments are:
SETTING
Number of Threads: 50
Ramp-up priod: 1
Loop count: 1000
Result
Average(ms): 13
Min(ms): 2
Max(ms): 674
Error(%): 4.36% (99: Cannot assign requested address)
Throughput: 2531.8/sec
my server specification
server name: HPE ProLiant DL360 Gen10
Number of CPU: 40
Number of Cores per CPU: 10
Total Memory/Free Memory: 62G/22G
Total Swap Memory/Free Swap Memory: 15/7.8G
I think the server is not that bad to yield such performance.
Briefly explain the structure, I made Hello World printing API using flask which are passed to wsgi.py.
The wsgi.py passed to my gunicorn service file, where the code is
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=root
Group=root
WorkingDirectory=/MycodeFolder
ExecStart=/usr/local/bin/gunicorn --config /etc/systemd/system/myGunicorn.config.py --bind '0.0.0.0:7211' -m 007 wsgi:application
[Install]
WantedBy=multi-user.target
where the gunicorn configuration is
import multiprocessing
workers = multiprocessing.cpu_count() * 2 1
worker_class = 'gevent'
timeout = 300
max_requests = 1000
max_requests_jitter = 50
errorlog = '/var/log/gunicorn_error.log'
accesslog = '/var/log/gunicorn_access.log'
My gunicorn is inside Docker container, and is connected to outer(host) Nginx via proxy pass.
My outer Nginx settings are
SERVER Block
server {
listen 18445;
#for dummy test
location /dummy {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://dockers/dummy;
}
}
HTTP Block
user nginx;
worker_processes 10;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 3096;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" $request_time';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream dockers {
server 127.0.0.1:7211;
}
include /etc/nginx/conf.d/*.conf;
}
Would like to know whether my settings are wrong, or just the python or middleware is not good for real time webserving purpose....
I reckon, because there are some companies which operate services using python, there must be an answer or I made fundamental mistake...
Hope to know the right setting, or check if the whole system is not suitable for webserving purpose!
CodePudding user response:
