Skip to content

Improve I/O performance by not writing placeholder files when they already exist #17870

@localcryptosMichael

Description

@localcryptosMichael

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

Metadata

Metadata

Labels

BugFor errors / faults / flaws / inconsistencies etc.Help wantedBeginner friendly issues or issues where we'd highly appreciate community's help and involvement.c: PerformanceFor when we could improve the performance / speed of Matomo.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions