Campsite and Server Overload Notice
  • Hi,

    I am using campsite for over a year now. Yesterday,  my shared plan hosting provider, send me a server overload notice and told me that the script get_img.php is overloading server's cpu. For the first 15 days of the January they recorder 888973 hits in this specific script. They advice me to optimize the script and use a cache mechanism. The only cache mechanism i see in the System Preference is the APC Cache but I can not enable it.

    What are my options and what seems to be the problem here ?

    George
  • 3 Comments sorted by
  • Vote Up1Vote Down Martin SaturkaMartin Saturka
    Posts: 40Member, Sourcefabric Team
    Hi, George,
    the get_img.php script is used for image loading - thus it gets many hits if many images are served.

    It looks if requested sizes of images are cached at server (images are cached), and just presents those images if available. If some image size is not stored, the image is re-sized first - it can take an amount of cpu resources.

    The re-sized images are cached at server, with cache time set at system preferences: "Imagecache Lifetime". May be you should set a greater time there. And if you store images at those sizes that are used for front-end (template based) display, you skip the re-size phase automatically.

    If you would like to play with PHP code, you can look at the template_engine class file "CampGetImage.php" where the "PushImage" and "sendCachedImage" methods deal with clients. You can try to put greater time for "Cache-Control" there (or even take the time from system preferences for that).

    Another thing could be to omit the "readfile" function, using server-specific headers for letting the web server to know that it shall plain serve a file. This in fact can save an amount of server load if you display many images. Those headers are "X-Accel-Redirect" for Nginx, "X-Sendfile" for Apache. By the way, I would vote for putting this into the Newscoop code.

    Martin

  • Thank you Martin for your reply.

    I have traced back all those tips before the answer you gave to me and the only I thing I thought it was to change the ImageCache LifeTime to about 10 days.

    But I found really really interesting the last paragraph about the X-Sendfile. Unfortunately it needs Apache 2.x while I am running 1.3.x. So my options are very limited !!!

    Regards,
    George


    Post edited by sdancer75 at 2012-01-17 13:27:38
  • Vote Up0Vote Down Martin SaturkaMartin Saturka
    Posts: 40Member, Sourcefabric Team
    First, X-Sendfile can save reasonable amount of loading if your site is heavy on image serving. And second, I do not know about Apache 1.3 way for this. Plus it needs some configuration tweaking even for Apache 2.x. Still, if your hosting provider is serious about performance, they should try the next, with Apache 2.x.

    What I've just tested on our development Newscoop server running Apache 2.x on Ubuntu, is as follows:

    1) Install the xsendfile module
    > apt-get install libapache2-mod-xsendfile

    2) put into /etc/apache2/sites-enabled/your_site.conf
    <IfModule mod_xsendfile.c>
        XSendFilePath /your_newscoop_path/
    </IfModule>

    3) put into the main Newscoop .htaccess
    <IfModule mod_xsendfile.c>
        XSendFile on
    </IfModule>

    4) put into CampGetImage.php at two places (just above "readfile" calls) next two parts, respectively
    if (true) {

        header('X-Sendfile: ' . $this->getSourcePath());

        return true;

    }

    if (true) {

        header('X-Sendfile: ' . $this->getTargetPath());

        return true;

    }

    Generally, there should be some reasonable checking instead of "if (true)", but I just tested if it works at all.

    Martin