salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] Performance Bottleneck in FileServer, removing old Python 2 Code

Open twangboy opened this issue 5 months ago • 1 comments

Description There is a performance bottleneck in salt/fileserver/__init__.py.

In check_file_list_cache, the loaded cache file is passed through salt.utils.data.decode(). This was necessary on Python 2, but the decoded file list cache contains no bytestrings. So this call is a costly no-op, on larger file_roots/gitfs deployments, but it results in a lot of extra work that is repeated for each fileclient request.

A community member reports that removing that call to salt.utils.data.decode() sped up loading the file list cache 80-90x. However, this can get overshadowed by more CPU or I/O-intensive work, like overuse of Pillar data, so alone it won't give you a major performance bump... but every little bit helps.

In general the use of salt.utils.data.decode() should be audited... There are a lot of places we had to have this code to get Unicode to work on Python 2, and my guess would be that the vast majority of places we use it (and the other decode_* funcs in that module) can be removed.

Steps to Reproduce the behavior (Include debug logs if possible and relevant)

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Versions Report

salt --versions-report (Provided by running salt --versions-report. Please also mention any differences in master/minion versions.)
Salt Version:
          Salt: 3006.9+53.g9176d6030d

Python Version:
        Python: 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]

Dependency Versions:
          cffi: 1.14.6
      cherrypy: 18.6.1
  cryptography: 42.0.5
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: 4.0.7
     gitpython: 3.1.41
        Jinja2: 3.1.4
       libgit2: Not Installed
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 22.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: Not Installed
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 25.0.2
        relenv: Not Installed
         smmap: 4.0.0
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist:
        locale: utf-8
       machine: AMD64
       release: 2022Server
        system: Windows
       version: 2022Server 10.0.20348 SP0 Multiprocessor Free

twangboy avatar Aug 26 '24 16:08 twangboy