We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 15075
    • 6 Posts
    For everybody using HTTP/2 and investigating occasional severe overload when using Media Browser on back-end, here is what's going on and what can be done.
    Recently we have started using HTTP/2 for several MODx installations, configured as Linux/Apache 2.4 and PHP over FCGI. Normally the server is under 20% CPU load and 50% free memory (running very stable for several years). Now we started to have occasional CPU overload and out-of-memory with consecutive problems. Always when editors were adding images using Media Browser.

    What is happening: Media browser is the only component that is simultaneously requesting phpthumb for every image in current folder. Using HTTP/1.x, the browser is limiting number of concurrent reqests to the same server. Using HTTP/2 there is no such limit (some browsers are using 100 as limit for HTTP/2). So a single user can request tens or even hundred phpthumbs on server. In our case this spawns tens of PHP-FCGI processes, easily overloading CPU and consuming entire free memory. In a bad case this can leed to kernel out-of-memory action killing some processes, e.g. mysql (!). In simple installation mysql won't restart itself. And it seems that some browsers are periodically trying to load resources on failed requests, making the situation even worse.

    This is only about Media Browser on backend. Normal front-end page using phpthumbof for image rescaling is processed in a single request together with rescaling images. And everything is cached after that. Normal visitor can't directly call phpthumb if it's setup correctly.

    What can't be done:
    - limit number of connections per session using firewall or apache: bad idea. Normally you don't mind tens of requests to static files and a few PHP, server is optimized for this
    - limit per-process memory in PHP config: bad idea. This would prevent most of normal images from rescaling

    What we've done: we have separeted webs to separate users (using FCGIWrapper and SuexecUserGroup) and limited FcgidMaxProcessesPerClass. This will limit number of PHP processes to N for that web. Media Browser will display images in batches of N images. On the other hand this is also slightly slowing other backend tasks, where a number of connectors and processors is called for manager pages.
    Not sure how this works for non-FCGI configs.

    What would be the best: lazy-load of images in Media Browser, limiting simultaneous requests with some system variable or at least pagination of thumbnails in Media Browser.