Joomla, Varnish Caching, Cookies and Heavy Server Load

Posted at: 3:43 pm by Timothy Haroutunian
Categories: Tech and Web

Recently, we (my company) took over web hosting for one of our clients. On average, they get 500,000 visits per month and a high profile suite of sites. I setup a Cloud Server Farm for the client. One of their sites, is the biggest of the group and their flagship site. This site was built 2 years ago using Joomla, a Content Management System, by a third-party company. I am not an advocate of Joomla because of the trouble that we have had with it. It is a very resource heavy CMS and for me, the problems outweigh the benefits.

While setting up this site, everything was working great until I started to test the server under high stress using “Siege”. After running the test with 50 requests/second, the server started to buckle and after 15 seconds, Apache became unavailable. I spent about 2 weeks trying to figure out what could cause this problem, but until today, I have been unsuccessful. I will first explain what I tried and how each change I made, either did nothing or caused different problems making them not a viable solution.

My first thought was to optimize Apache to handle more connections at one time. Apache’s HTTP Server website has a Performance Tuning section. After making these changes and restarting Apache, the Stress Test still caused the server to die.

Next, I thought it might have been the mysql server that was the issue. Even though, the mysql server wasn’t getting high load, I decided to fine-tune mysql as well. Since we have a dedicated mysql server, I used the configuration that was located in mysql-huge.cnf. This configuration is designed for servers that are just used for mysql. These changes seemed to help, but it wasn’t even close to what the site should be performing at.

I then thought it might be the amount of RAM on the server. I resized the cloud server to 4G of memory, but there was still no change. I resized it back down to 1G of memory which is what we thought it should be at.

After looking into more server configurations as the problem and getting nowhere, I decided that I would see if Joomla was causing the issues. You should know that this is all being done on a development server. I started by removing the Javascript files that were being included to display the client’s Ads. They have a total of 32 JavaScript calls and takes 10 seconds to just load the Ads. Removing them helped speed up the site, but the high load server failures were still happening and I added their Ads back in.

Now, the server is using Varnish for caching the content. It should be holding onto a static version of the site for 2 minutes (what it defaults to), but it wasn’t keeping the cache. Apache was still getting called every time you load the site. Varnish was still pulling the page through cache, but it was not keeping the cache. I have Varnish running on all of our servers including my personal server farm, however, I couldn’t figure out why this site was not keeping cache.

I tried removing some of the third-party modules that could have been incorrectly programmed and causing serious performance issues. After removing all of the modules on the homepage, the problems still existed. I got to the point where I didn’t think that it was anything to do with the server or how the site was pulling its content through Joomla, but I felt that there was something on the Joomla Core that was the problem.

I spent the next few hours researching what Joomla could be doing that was making the server die. After finding this blog article, I had an idea. His problem wasn’t my problem, but something that he wrote got me thinking. What if, the problem is with the Joomla Cookies. I did a few more Google searches and found that Joomla does not handle cookies very well it uses cookies for everything Joomla does.

*Please read the rest of this before trying the following as this configuration did not work even though it was performing the way I thought it should.

This site is on a dedicated server and no other traffic will be going to it. It is a 64-bit Quad Core Centos Server with 1G of ram. In Varnish, I added the following to the VLC file.

sub vcl_fetch {
   set beresp.ttl = 5m; # Time that the cache should be kept for.
   unset beresp.http.set-cookie; # Unset all cookies on the site
}

I “sieged” the server again at 50 requests/second and sure enough, Varnish was keeping the cache and serving it out of Varnish and not hitting apache at all. I then proceeded to stress the server at 500 requests/second and still the server was holding strong. Finally, I stressed it at 800 requests/second and it was still functioning properly. This is more than what the client would receive for traffic on an average day and I was confident that this had solved the problem….read on!

I then tried to log into Joomla on the front-end and on the administrative side. As it turns out, removing the cookies was a serious problem for the functionality of Joomla and would not let me login. I then removed the change that I made to the VLC, restarted Varnish and tried to login again. This time it worked.

I thought about how I could work around this issue, but nothing was coming to me. I did more research and came across this blog article. It is a little bit hard to read, but once you make the configuration readable, I found this code. *Note that I changed the obj.http.set-cookie to beresp.http.set-cookie to account for the new version of the Varnish 3.0 language.

sub vcl_fetch {
        set beresp.ttl = 5m;
        if( req.request != "POST" ) {
                unset beresp.http.set-cookie;
        }
}

Once I added this code to the VLC and restarted Varnish, not only could I login to Joomla on the front-end and administrative side, but the server was still holding strong at 800 requests/second.

Now, I can only stress the server to the point where I think it will hold its own in a real life scenario, but that doesn’t mean other steps may need to be implemented if the site gets picked up by Digg or Google (Google is what took down this clients server last month). Until that happens, we can’t account for the amount of traffic the site will receive. One additional step you can take is to add a Load Balancer into the mix and allow for the additional traffic and relive some of the stress on the sole server. This however, will be a separate blog entry as this one is already long enough.

In closing, I hope this article helps you to save weeks of performance testing, server changes and headaches.


ArmenianEagle.com is on a New Server

Posted at: 8:37 am by Timothy Haroutunian
Categories: Tech and Web

Actually, it has been on a new server for 6 months but since I haven’t blogged in about 1 1/2 years, it isn’t that bad. :)

I switched from Dreamhost (Shared hosting) which was great for my “own” server, but it was very restricting. I didn’t have root access and I couldn’t expand my sites performance. I moved to Linode.com and it was a great decision. If you have the skills, having full control of your server is awesome, but you need to beware of the following. If you break your server/websites/email (if app) somehow, you need to fix it. No support to call or email. Trust me on that one! Since I moved all my sites to this server, I learned very quickly about aspects of server administration that I wasn’t familiar with.

I have a configuration running CentOS, nginx and php 5.3.2 that includes svn (version control), varnish (caching), siege (stress testing), urchin (Traffic Analytics), nagios (resource monitoring) and more.

I am running all of my domains and a few of my friends websites and it works awesome. I am so excited to learn more server administration as I go so that I can be a more knowledgeable employee at my job. My work recently moved to RackSpace Cloud Servers from RackSpace Managed Hosting. I (+1) currently maintain 8 servers at work and we are adding another 8 servers over the next few months. The more I can learn on my own for selfish reasons (resume), the more I can bring to work and help them as well, which in turn will help me. Over the past 6 months,

I have learned so many exciting linux commands and processes that I feel very comfortable in command line. I know I still have A LOT to learn and ways to improve on already existing knowledge, but I am more confident now than I ever was. I added another set of skills that will greatly help my career. I am now not just a Web Developer, but a Server Admin as well.


Scammers On Craigslist Are Fun To Mess With

Posted at: 11:41 pm by Timothy Haroutunian
Categories: Tech and Web

Don’t be fooled by scammers on Craigslist. I was selling my 1987 Jeep Wrangler hard top on Craigslist and got a reply back from someone interested. When I sent him a reply, this is what I got.

Hello,
  Thanks for your mail and i will like to affirm that i am really interested in your items and will like to inform you that my only mode of paying you is by mailing you certified bank check and if you are ok with that… you can get back to me with your home address.. Payee name that will be on check and a valid phone number ( no voice mail number) … and as soon as you receive the check and it goes through then i will now send my shipper for the pickup of the item asap….
thanks

First of all, he said “items” and I was only talking about one thing. Second, if his only way to pay you is a certified check, there is something wrong. I may be mean to telemarketers and scammers, but it is fun sometimes. This is my exact response to his reply.

My response

No. Cash or no deal. Don’t even get me started on how this is fraud. If you send me anything, I will send it right back. If I get spam from you, let me inform you that I am a technology freak and will use it to my advantage.  Nice try, but you didn’t get me. So if you are paying me in cash, is it going to be $300 in pounds or US dollars considering I tracked this back to an IP address in the UK. Just wondering how you would pick it up and mail it. Seems like it would be easier just to give me $5000 in cash and I can punch you in the face for being an idiot.


Post-Commit Hooks With Subversion On Dreamhost

Posted at: 10:03 pm by Timothy Haroutunian
Categories: Tech and Web

When I was working at my old job, we started using Subversion (SVN) as our versioning software which I really enjoyed. Now that I am working on my own web application, I am using SVN as well. Currently I am using Dreamhost for my hosting and they have SVN pre-installed on their servers, all you need to do is activate it. The installation is very easy through the web panel, however, if you want to get more advanced, you will need to know basic command line.

I wanted to setup SVN so that when I commit to the server, it automatically updates the site with the newest content. Normally you have to manually go in and update the site to the latest revision. After reading through the Dreamhost Wiki, I found out how to accomplish this in only about 5-6 quick steps. I say quick in the fact that if you do it right it is quick. I had a few issues based on false information in the wiki, but I finally got it working and they updated the article.

Read the article here.

Once I got it working, I tested it out and it worked wonders. It made my life a lot easier because not only was it one less step, but I didn’t have to go into command line after every save and commit. If you are using SVN, I would highly recommend establishing a post-commit hook so that you can save time and energy.

Reblog this post [with Zemanta]

« Previous entries Next Page » Next Page »