Improve response time on tryton client after idle time.

Hi,

I would like to know how to improve response time on tryton after idle time.

I recorded a video of what happends when I use tryton again after 30 minuts idle (some case could be less)

I run tryton using nginx with uwsgi3.

[uwsgi]
socket=/tmp/%n.sock
virtualenv = /opt/bosque
wsgi=app
module=trytond.application:app
env = TRYTOND_CONFIG=/opt/bosque/tr.conf
processes = 1
threads = 4
check-static = /opt/bosque/sao

In nginx config I use something it:

upstream bosquesup {
    server unix:/tmp/bsqs.sock; # for a file socket
}

# configuration of the server
server {
    # the port your site will be served on the domain name it will serve for
    server_name mydomain.io;     # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location /static {
        alias /opt/bosques/sao; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the uwsgi server.
    location / {
        uwsgi_pass bosquesup;
        include /etc/nginx/uwsgi_params;
        uwsgi_read_timeout 300;
    }
}

I also use a proxy

# configuration of the server
server {
    # the port your site will be served on
    listen 8000 default_server;
    listen [::]:8000 default_server;

    # the domain name it will serve for
    server_name _;     # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    location / {
        proxy_pass         http://127.0.0.1:80/;

        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_connect_timeout      1200;
        proxy_send_timeout         1200;
        proxy_read_timeout         1200;
        send_timeout               1200;
        client_body_timeout        1200;
        keepalive_timeout          1200;

        proxy_buffer_size          4k;
        proxy_buffers              4 32k;
        proxy_busy_buffers_size    64k;
        proxy_temp_file_write_size 64k;
    }
}

I noticed in uwsgi log it is updated only after 40 seconds (the time for tryton take to response) with an entry similar to these.
Apr 23 15:15:28 ip-172-31-35-117 uwsgi[512]: {address space usage: 400MB} {rss usage: 87281664 bytes/83MB} [pid: 3942|app: 0|req: 294/294] 127.0.0.1 () {46 vars in 709 bytes} [Thu Apr 23 21:15:28 2020] POST /bosquedb/ => generated 20 bytes in 18 msecs (HTTP/1.0 200) 2 headers in 71 bytes (2 switches on core 1)

I’m using trytond 5.0.14 and tryton 5.0.15. Tryton under windows 10. SAO work very well and fast.

By last, I run it on a AWS instance t2.xlarge, so I don’t think it is for a lack of resources.

Thanks in advance.

1 Like

I guess it is because the master µwsgi process does not create the pool for the database at startup. So each time a new worker is needed, it has to query the database and load the activated modules. This can take times is there are a lot of modules.
So you can fill in the environment variable TRYTOND_DATABASE_NAMES with the name of the database.

1 Like

I can activate it on trytond 5.0 and 5.2, but not in trytond 5.4.

In 5.4, after a long time without response uwsgi log is the follow (can not connect the database):

Apr 24 03:52:24 localhost systemd[1]: /etc/systemd/system/emperor.uwsgi3.service:3: Failed to add dependency on network.targe, ignoring: Unknown error -22

In tryton I receive the follow message:

Traceback (most recent call last):
  File "C:\msys64\home\ced\tryton-5.4/tryton/gui/main.py", line 279, in do_activate
  File "C:\msys64\home\ced\tryton-5.4/tryton/common/common.py", line 900, in __init__
  File "C:\msys64\home\ced\tryton-5.4/tryton/rpc.py", line 87, in login
  File "C:/msys64/mingw32/lib/python3.8/xmlrpc/client.py", line 1109, in __call__
  File "C:\msys64\home\ced\tryton-5.4/tryton/jsonrpc.py", line 306, in __request
tryton.jsonrpc.Fault: 'res.user'

Fault: 'res.user'

In sao I receive the follow message:

Traceback (most recent call last):
  File "/opt/tryton/lib/python37/site-packages/trytond/wsgipy", line 107, in dispatch_request
    selfcheck_request_size(request, max_request_size)
  File "/opt/tryton/lib/python37/site-packages/trytond/wsgipy", line 87, in check_request_size
    if requestuser_id:
  File "/opt/tryton/lib/python37/site-packages/werkzeug/utilspy", line 90, in __get__
    value = selffunc(obj)
  File "/opt/tryton/lib/python37/site-packages/trytond/protocols/wrapperspy", line 73, in user_id
    context=context)
  File "/opt/tryton/lib/python37/site-packages/trytond/securitypy", line 86, in check
    Session = poolget('irsession')
  File "/opt/tryton/lib/python37/site-packages/trytond/poolpy", line 179, in get
    return self_pool[selfdatabase_name][type][name]
KeyError: 'irsession'

Response time improved considerably in trytond 5.0 and 5.2

THis sound like and error on your systemd setup.
From the error message I guess that you added network as dependency of the emperor.uswgi3 service but this service is not started. So it fails.

With this setup uwsgi will wait until the network is started to start. Normally it will start after some timeout is passed. This timeout is what it takes to start replying to client request.

You should fix this dependency to remove the timeout.

Hi,

I update my systemd config and modified the dependency, but the same error log is given. These config works on trytond 5.0 and 5.2 but not with 5.4.

[Unit]
Description=uWSGI Emperor service
After=syslog.target

[Service]
ExecStartPre=/bin/bash -c 'mkdir -p /run/uwsgi; chown www-data:www-data /run/uwsgi'
ExecStart=/usr/local/bin/uwsgi --emperor /etc/uwsgi/vassals --uid=www-data --gid=www-data
RuntimeDirectory=uwsgi
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Without TRYTOND_DATABASES_NAMES it start fine on trytond 5.4