jgiam.com

Just another WordPress weblog

128MB wasn’t enough

with 3 comments

128MB wasn’t enough for me. My VPS struggled to serve my sites, and too many simultaneous connections caused the server to swap wildly, bringing up CPU and disk usage. My VPS got suspended once for over usage of resources. Despite more tweaking, the server was still too slow for my liking.

I wanted to upgrade to a plan with more RAM, but the plans on RapidXen were beyond my budget. I looked around and found VirtuallyDedicated. Their 640MB (with 1.25GB swap) was still reasonably affordable for me, and I decided to take that plan. I did not regret my decision. The extra RAM really does help, and my sites load faster, and handle more connections. Even compiling PHP for LiteSpeed took a fraction of the time. Network connectivity is much better, especially in terms of bandwidth. A tip if you’re buying hosting in another country: make sure you do latency and bandwidth tests. Not all datacentres are made equal. 10-20KB/s is really bad.

So far, so good with this VPS. My only issue right now is the lack of a control panel (for Xen VPSes), which means things like reboots have to be requested and done by staff. They keep telling me a control panel is launching soon, but I have not received any word.

Written by Jon G

January 4th, 2010 at 11:43 am

Posted in Techie Corner

Tagged with

Backing up my VPS: Settings, websites and MySQL

without comments

I’ve seen the painful lessons many times: lazy website owners thinking their webhost would last forever, and neglecting to save their own backups. But really, you learn a lesson the best when you actually feel the pain. And I sure did.

To prevent this, I decided to automatically, and regularly backup my VPS and store them on my computer. I searched Google a bit, and found two typical approaches: a simple shell script, or a full-fledged backup solution. I decided that I didn’t need something like Amanda or Bacula. I didn’t feel too inclined to messing with scripts though. However, I found this nifty tutorial to backup web server files and MySQL databases. The tutorial came complete with a script generator, which was really handy.

I made some changes to the generated script though:

  1. I prefer the yyyy-mm-dd date format for easier (and natural) file name sorting. I also changed the timestamp of the MySQL dumps to match the file dump timestamp format. 
  2. Because I’m not running large websites, I decided to change the script so that the full backup  is only run once a month instead of once a week, to save on resources.

With this script running, I should not have to encounter another situation where I lose months of data. Well, unless the backups stop running without me realising. :P

Written by Jon G

November 2nd, 2009 at 5:22 pm

Posted in Techie Corner

Tagged with , ,

Optimising LiteSpeed Web Server: 30 seconds to less than 1 second

with 3 comments

I chose to use the LiteSpeed Web Server over Apache HTTP Server because of the low memory footprint, as well as better performance for PHP. The GUI admin interface is also a big plus point, making it easy to administer the server.

As I was adding sites and working to bring them online, I realised that my sites were loading very slowly. I installed WP Tuner, a WordPress plugin, to try and see if the bottleneck was on LiteSpeed or MySQL. From the statistics, the delay occurred at the very first “Start” marker, taking 30 seconds, or even as long as 60 seconds. This wasn’t a problem with MySQL then. Next, I used top to monitor CPU and memory usage. It turns out that each PHP process took up 20MB of memory. With a VPS of only 128MB memory, and each site load using multiple processes, this was a huge problem. I was quickly running out of memory, and there was a lot of swapping. A quick search on Google, and I found this page of documentation, which states:

There are two ways to let PHP handle multiple requests concurrently, Server Managed Mode and Self Managed Mode. In Server Managed Mode, LiteSpeed web server dynamically spawn/stop PHP processes, in this mode “Instances” should match “Max Connections” configuration for PHP external application. To start PHP in Self Managed Mode, “Instances” should be set to “1″, while “LSAPI_CHILDREN” environment variable should be set to match the value of “Max Connections” and >1. Web Server will start one PHP process, this process will start/stop children PHP processes dynamically based on on demand. If “LSAPI_CHILDREN” <=1, PHP will be started in server managed mode.
Self Managed Mode is preferred because all PHP processes can share one shared memory block for the opcode cache.

I configured LiteSpeed to use Self Managed Mode as described, and restarted the server. I then loaded my sites in my browser, and just like that, my websites loaded in under a second. Just to make sure it wasn’t due to caching, I browsed several pages of the sites, and everything worked perfectly. It certainly pays to spend a bit of time analysing performance, reading documentation and tuning the server. :)

Written by Jon G

October 29th, 2009 at 11:47 am

Posted in Techie Corner

Tagged with , ,

Webhosts come and go

without comments

This is a very important lesson: Webhosts come and go. One commonly-cited criteria for a good webhost is how long it has been in business. This, however, is hardly fool-proof. I had been with my previous host since 2003, I believe, which is six years or so of hosting. Two weeks ago, the server my website was on went down, and stayed down. No replies to tickets, no live chat, no answers to their phone (see this thread on WebHostingTalk). There were tell-tale signs of its impending doom: even before this incident, the server had gone down for one to two days at a time, and my tickets were not getting responded to. But I’d been lazy (and caught up with real life), and neglected to making a backup of my hosting account. My last full backup was from May, five months ago.

On the positive side, I am now a proud owner of a VPS. I decided to go with a VPS because I loved the flexibility and customisability of a VPS, and not be tied down to the quirks and limitations of shared hosting. A dedicated server is way over budget, so I decided to go with a small, cheap VPS instead. After much reading up, I decided to sign up with RapidXen, and purchased a 128MB VPS. Since I had a coupon for 20% off, I decided to get a slightly higher spec’ed VPS, 128MB RAM with 384MB swap and 10GB disk space.

Over the past few days, I have had fun setting up my VPS, and have just put this website back online (though restored from the May backup). Setting up a VPS requires Linux knowledge though, so this is definitely not for a Linux-newbie. There are a quite a few guides, and I found these particularly useful:

The VPS seems to be running well at the moment, and I hope this will be a long-term host :)

Written by Jon G

October 27th, 2009 at 4:10 pm

Posted in Techie Corner

Using Zebra for batch processing

without comments

As mentioned in my previous post, Zebra, more specifically, zebraimg, the barcode recognition component, is fast and rather accurate. However, the program isn’t really made for batch processing of barcodes. Yes, you can execute zebraimg *.jpg, but the problem is that it is difficult to extract information on which barcodes were successfully recognised, which were ambiguous, and which failed. I initially ran this command to process my barcodes, but ended up having to cross-check the results, which wasted quite a bit of time. I wanted some formatting of results to make it easier to identify problematic barcodes.

A simple script would be able to format the recognition results. Because I am not familiar with shell scripting, I wrote one in PHP instead.

The gist of the script is that it scans the working directory for all JPEGs, runs zebraimg and writes the result to a file. The result is saved in a CSV format with the filename and zero or more recognised barcodes.

Read the rest of this entry »

Written by Jon G

January 13th, 2009 at 4:10 pm

Posted in Techie Corner

Tagged with