• 13

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

VPS hosting is very slow. What's the bottleneck?

I've setup a new VPS hosting, to run a Drupal website but it is extremely slow.

It is Ubuntu 10, Apache, php5.2

I've enabled Multi-Processing Module (MPM) module and configured it as follows:

StartServers 4 MinSpareServers 2 MaxSpareServers 10 ServerLimit 20 MaxClients 20 MaxRequestsPerChild 200

But it is still too slow... it is a VPS slice: RAM 256MB BW 150GB

what could be the reason ? thanks

Update (Swaps)

             total       used       free     shared    buffers     cached
Mem:           245        220         24          0          1         26
-/+ buffers/cache:        192         52
Swap:          511        110        401

Make certain you are not regularly accessing swap space for anything - disk I/O is a very common bottleneck, particularly on Xen VPS' with relatively small RAM allocations (assuming you're at Slicehost, given your mention of using a "slice").

While having swap space seems like a plus (particularly because your VPS doesn't sputter and die when you try to run multiple memory-hungry applications like Apache w/dynamic PHP content and MySQL) it will quickly lead to substandard performance, particularly if you're on a VPS host node full of others doing the same thing.

Edit: I would highly recommend the LowEndBox Wiki (LowEndBox focuses upon virtual environments with memory allocations in the same neighborhood as your own) for optimization tips to get Apache and MySQL running smoothly within your virtual environment.

  • 3
Reply Report
      • 2
    • @Patrick - It appears as though swap space is being allocated, though it may be held without being used. Run vmstat -a 1 and watch the si and so values while you request a page on your site to see how heavily swap is being relied upon (si and so will remain at 0 if your server is not actively using swap).
    • @danlefree So, they are usually 0, but when I visit a page they both change (i.e. 0 0, 312 0, 324 1516, 36 6768, 0 0). So I guess the server is using swap.

It's almost definitely not an Apache configuration issue, but you need to profile your application to find out where its time is being spent instead of blindly guessing at what the problem is. Xdebug is a popular tool for PHP profiling, and turning on the MySQL slow query log may help if MySQL is running inside your VPS.

Part of the problem with VPS environments is that since your VM doesn't really know what it's getting in terms of resources, it's practically impossible to determine if your server hardware is heavily oversubscribed. That makes things trickier.

  • 2
Reply Report
      • 2
    • Code isn't magic, it does things. The entire point is to figure out where it's running slow so you can figure out why it's running slow. As you said, you have absolutely nothing else to go on.
      • 1
    • uhm ok thanks. But the point is that I've just setup the VPS, installed everything.. so there is not a lot to investigate. What could be the reason of php running slow.. or maybe Drupal running slow on a server ?

First try the standard mpm settings:

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0

Maybe you should also have a look at this: http://articles.slicehost.com/2010/5/20/configuring-the-apache-mpm-on-debian You should also reduce the KeepAlive settings.

What about the RAM? Are you sure you have enough and the server is not swapping? (free -m)

You should also check your database, it's relative easy with the Tuning Primer script: http://www.day32.com/MySQL/

Btw. on a Server with just 256MB RAM i would advise you to use a other Webserver like Lighttpd or Nginx (with PHP-FPM).

  • 1
Reply Report
      • 1
    • I've changed the values, but it is still the same. The server is fast if I visit a html page. It is a php/mysql problem I guess
    • As you can see your Server is swapping, try to disable Apache modules which you don't need. However i think that 256MB RAM are not enough to run a well performing LAMP-setup. Databases need cache and Apache also isn't a saveaholic. You should think about switching to Lighttpd, it's easy to setup and works well with less RAM. You don't need to worry about the rewrite-stuff, there are enough examples on the internet. I can't tell you why the same setup works on a other VPS, maybe different virtualisation or other hardware (faster harddrives ;) )

I'm thinking it might be your database layer, does this connect to a shared database somewhere or is the database local to the server?

  • 0
Reply Report

Make sure that localhost refers to the same vhost configured for external access and try some measurements against urls within http://localhost/ (e.g. browser over ssh tunnel, browser running on virtual server, or just write a php script to grab some urls) that should allow you to identify if there is throttling being applied outside your virtual server or whether the problem is with your server.

  • 0
Reply Report

Trending Tags