@localcryptosMichael opened this Issue on August 10th 2021

I noticed that Matomo was doing a large amount of disk writes. Looking into it, I found that on every API request, Matomo was recreating index files for a number of directories in tmp/ even though these files already exist. These unnecessarily writes are causing high disk I/O wait when under heavy load.

Expected Behavior

Perform a Live.getVisitorProfile API call (it might apply to other methods -- I haven't checked).

Current Behavior

On every call:

  • Piwik\Filechecks::dieIfDirectoriesNotWritable() is invoked
  • This calls Filechecks::mkdir() with these directories:
    • tmp/
    • tmp/tcpdf/
    • tmp/logs/
    • tmp/cache/
    • tmp/assets/
  • Filechecks::createIndexFilesToPreventDirectoryListing() is invoked on each directory, writing a new index.htm and index.php each time (even though they already exist)
  • API operation is actioned

Possible Solution

I think the code should be optimised so that it doesn't perform these unnecessary writes. At the very least, check that these index files don't exist before writing to them.

Steps to Reproduce (for Bugs)

  1. Get /?module=API&method=Live.getVisitorProfile&idSite=X&visitorId=XXXXXXXXXXXXXXXX&format=JSON&token_auth=XXX.

Your Environment

  • Matomo Version: 4.4.1
  • PHP Version: 7.2.34
  • Server Operating System: RHEL
@tsteur commented on August 10th 2021 Member

Thanks for creating this issue @localcryptosMichael 👍 Great find! Makes sense to first check if these files exist and only then write them.

Note: See https://github.com/matomo-org/matomo/issues/16552 we'd likely want to use is_file() here.

This Issue was closed on August 10th 2021
Powered by GitHub Issue Mirror