Files @ 11cae16e5a5d
Branch filter:

Location: kallithea/docs/usage/performance.rst - annotation

11cae16e5a5d 4.9 KiB text/prs.fallenstein.rst Show Source Show as Raw Download as Raw
mads
setup: use old importlib_metadata version to fix kombu failing on python < 3.8

Many libraries use the importlib_metadata library as fallback when running on
Python versions older than 3.8 . For example setuptools when easy_install is
used for install the Kallithea console_scripts entrypoints in the bin folder.
The dependencies on importlib_metadata were indirect and without constrains on
version number.

The problem is that Celery uses Kombu, which (on Python < 3.8) uses
importlib_metadata in a way that is incompatible with importlib_metadata > 5.

Most obvious, building docs failed as:
Running Sphinx v5.1.1

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
File ".../kallithea/venv/lib64/python3.7/site-packages/sphinx/config.py", line 347, in eval_config_file
exec(code, namespace)
File ".../kallithea/docs/conf.py", line 17, in <module>
import kallithea
File ".../kallithea/kallithea/__init__.py", line 45, in <module>
CELERY_APP = celery.Celery() # needed at import time but is lazy and can be configured later
File ".../kallithea/venv/lib64/python3.7/site-packages/celery/local.py", line 492, in __getattr__
[name])
File ".../kallithea/venv/lib64/python3.7/site-packages/celery/app/__init__.py", line 2, in <module>
from celery import _state
File ".../kallithea/venv/lib64/python3.7/site-packages/celery/_state.py", line 15, in <module>
from celery.utils.threads import LocalStack
File ".../kallithea/venv/lib64/python3.7/site-packages/celery/utils/__init__.py", line 16, in <module>
from .nodenames import nodename, nodesplit, worker_direct
File ".../kallithea/venv/lib64/python3.7/site-packages/celery/utils/nodenames.py", line 6, in <module>
from kombu.entity import Exchange, Queue
File ".../kallithea/venv/lib64/python3.7/site-packages/kombu/entity.py", line 7, in <module>
from .serialization import prepare_accept_content
File ".../kallithea/venv/lib64/python3.7/site-packages/kombu/serialization.py", line 440, in <module>
for ep, args in entrypoints('kombu.serializers'): # pragma: no cover
File ".../kallithea/venv/lib64/python3.7/site-packages/kombu/utils/compat.py", line 82, in entrypoints
for ep in importlib_metadata.entry_points().get(namespace, [])
AttributeError: 'EntryPoints' object has no attribute 'get'

That made readthedocs builds fail, when it in the default web configuration
used Python 3.7 .

Fixed by introducing an explicit dependency on importlib_metadata < 5.
fa88997aa421
fa88997aa421
fa88997aa421
22a3fa3c4254
fa88997aa421
fa88997aa421
d02c715e2805
d02c715e2805
d02c715e2805
d02c715e2805
d02c715e2805
5d12768a0aa1
d02c715e2805
d02c715e2805
fa88997aa421
d02c715e2805
d02c715e2805
d02c715e2805
6afa528ee30e
d02c715e2805
d02c715e2805
fa88997aa421
d02c715e2805
d02c715e2805
d02c715e2805
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fb0417c65c64
fa88997aa421
d02c715e2805
d02c715e2805
8b8edfc25856
d02c715e2805
d02c715e2805
d02c715e2805
8b8edfc25856
b688a2a1b189
d02c715e2805
d02c715e2805
d02c715e2805
fa88997aa421
d02c715e2805
d02c715e2805
d6942b2b421c
933d25793167
933d25793167
933d25793167
933d25793167
933d25793167
49c82acd30b2
933d25793167
d02c715e2805
933d25793167
933d25793167
d6942b2b421c
933d25793167
933d25793167
933d25793167
d6942b2b421c
933d25793167
d02c715e2805
d02c715e2805
d79f3505549e
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
d442d8395b75
778f7ae3b6eb
d02c715e2805
d02c715e2805
d02c715e2805
61954577a0df
61954577a0df
692dddf298e2
692dddf298e2
61954577a0df
692dddf298e2
692dddf298e2
692dddf298e2
692dddf298e2
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
61954577a0df
692dddf298e2
61954577a0df
61954577a0df
61954577a0df
692dddf298e2
692dddf298e2
692dddf298e2
692dddf298e2
692dddf298e2
692dddf298e2
692dddf298e2
fbbe80e3322b
778f7ae3b6eb
933d25793167
933d25793167
933d25793167
.. _performance:

================================
Optimizing Kallithea performance
================================

When serving a large amount of big repositories, Kallithea can start performing
slower than expected. Because of the demanding nature of handling large amounts
of data from version control systems, here are some tips on how to get the best
performance.


Fast storage
------------

Kallithea is often I/O bound, and hence a fast disk (SSD/SAN) and plenty of RAM
is usually more important than a fast CPU.


Caching
-------

Tweak beaker cache settings in the ini file. The actual effect of that is
questionable.

.. note::

    Beaker has no upper bound on cache size and will never drop any caches. For
    memory cache, the only option is to regularly restart the worker process.
    For file cache, it must be cleaned manually, as described in the `Beaker
    documentation <https://beaker.readthedocs.io/en/latest/sessions.html#removing-expired-old-sessions>`_::

        find data/cache -type f -mtime +30 -print -exec rm {} \;


Database
--------

SQLite is a good option when having a small load on the system. But due to
locking issues with SQLite, it is not recommended to use it for larger
deployments.

Switching to PostgreSQL or MariaDB/MySQL will result in an immediate performance
increase. A tool like SQLAlchemyGrate_ can be used for migrating to another
database platform.


Horizontal scaling
------------------

Scaling horizontally means running several Kallithea instances (also known as
worker processes) and let them share the load. That is essential to serve other
users while processing a long-running request from a user. Usually, the
bottleneck on a Kallithea server is not CPU but I/O speed - especially network
speed. It is thus a good idea to run multiple worker processes on one server.

.. note::

    Kallithea and the embedded Mercurial backend are not thread-safe. Each
    worker process must thus be single-threaded.

Web servers can usually launch multiple worker processes - for example ``mod_wsgi`` with the
``WSGIDaemonProcess`` ``processes`` parameter or ``uWSGI`` or ``gunicorn`` with
their ``workers`` setting.

Kallithea can also be scaled horizontally across multiple machines.
In order to scale horizontally on multiple machines, you need to do the
following:

- Each instance's ``data`` storage needs to be configured to be stored on a
  shared disk storage, preferably together with repositories. This ``data``
  dir contains template caches, sessions, whoosh index and is used for
  task locking (so it is safe across multiple instances). Set the
  ``cache_dir``, ``index_dir``, ``beaker.cache.data_dir``, ``beaker.cache.lock_dir``
  variables in each .ini file to a shared location across Kallithea instances
- If using several Celery instances,
  the message broker should be common to all of them (e.g.,  one
  shared RabbitMQ server)
- Load balance using round robin or IP hash, recommended is writing LB rules
  that will separate regular user traffic from automated processes like CI
  servers or build bots.


Serve static files directly from the web server
-----------------------------------------------

With the default ``static_files`` ini setting, the Kallithea WSGI application
will take care of serving the static files from ``kallithea/public/`` at the
root of the application URL.

The actual serving of the static files is very fast and unlikely to be a
problem in a Kallithea setup - the responses generated by Kallithea from
database and repository content will take significantly more time and
resources.

To serve static files from the web server, use something like this Apache config
snippet::

        Alias /images/ /srv/kallithea/kallithea/kallithea/public/images/
        Alias /css/ /srv/kallithea/kallithea/kallithea/public/css/
        Alias /js/ /srv/kallithea/kallithea/kallithea/public/js/
        Alias /codemirror/ /srv/kallithea/kallithea/kallithea/public/codemirror/
        Alias /fontello/ /srv/kallithea/kallithea/kallithea/public/fontello/

Then disable serving of static files in the ``.ini`` ``app:main`` section::

        static_files = false

If using Kallithea installed as a package, you should be able to find the files
under ``site-packages/kallithea``, either in your Python installation or in your
virtualenv. When upgrading, make sure to update the web server configuration
too if necessary.

It might also be possible to improve performance by configuring the web server
to compress responses (served from static files or generated by Kallithea) when
serving them. That might also imply buffering of responses - that is more
likely to be a problem; large responses (clones or pulls) will have to be fully
processed and spooled to disk or memory before the client will see any
response. See the documentation for your web server.


.. _SQLAlchemyGrate: https://github.com/shazow/sqlalchemygrate
.. _mod_wsgi: https://modwsgi.readthedocs.io/
.. _uWSGI: https://uwsgi-docs.readthedocs.io/
.. _gunicorn: http://pypi.python.org/pypi/gunicorn