Archive for February, 2007

Some obvious MySql tuning.

February 23, 2007

I was reading my hoster’s member forums recently and one topic there mentioned that normally the default installation of MySql database on our virtual servers doesn’t have cache enabled. As I didn’t look deep into those things yet, and on my home PC I just take the defaults and don’t care, I did a quick search on the Internet, which took me to the standard MySql documentation and a short article explaining the basics. Then, as suspected, the checks of MySql settings on the Kyusl.com server has shown that the cache is really not enabled. It looks like the hosting company provides a “minimum” install, assuming that folks who purchase virtual server hosting with almost root access will do the tuning on their own.

The whole thing doesn’t take long. I just had to ssh to my server and add three lines to /etc/my.cnf (it’s on RedHat, on Debian-based systems like Ubuntu it should be /etc/mysql/my.cnf). They have to be placed somewhere under [mysqld] section:

query_cache_limit = 1048576
query_cache_size = 16777216
query_cache_type = 1

After that, you need either restart MySql daemon (mysqld stop then mysqld start) or, if you don’t mind, the PC or VPS server. When you log into the mysql client after restart, do a quick check if your changes are active now:

mysql> SHOW VARIABLES LIKE ‘query_cache%’;

NOTE: both quotes in the statement above should be the same “normal” single quote. Don’t copy-paste – this won’t work. Just type it yourself.

The result should report something like:

+------------------------------+----------+
| Variable_name                | Value    |
+------------------------------+----------+
| query_cache_limit            | 1048576  |
| query_cache_min_res_unit     | 4096     |
| query_cache_size             | 16777216 |
| query_cache_type             | ON       |
| query_cache_wlock_invalidate | OFF      |
+------------------------------+----------+

By the way, the default installation that you get with Ubuntu Linux has the cache enabled by default.

Choices – Part II. PHP.

February 17, 2007

Long before starting Kyusl, I was asked, during a job interview, what platform (or language) would I use for a project if I was free to choose? It sounded funny first because we are never free and that’s what I said first. I remember that then I finally answered “.NET” because at that time it was still new and I wanted to learn it. Microsoft provides the best documentation when compared to anyone else, but unfortunately, .NET locks you into one OS. Yes, I know what Mono is, but it’s not 1:1 port.

With Kyusl, I don’t remember having any problem to make up my mind. I didn’t use PHP and MySQL at the time for anything bigger than “Hello world”, and had to learn starting from basics. For simple scripts at work and at home, Python is my favourite, but to create a Web application, the choice of PHP was almost obvious.

One of the main questions that you have to answer is what kind of hosting plan can you afford. You can always find a niche company offering support for the most exotic software, for a reasonable price, but what if you are going to move? Actually, those days you can easily get a virtual private server and install any software you want. It’s how Kyusl.com is hosted, but doing things, say, in beautiful Python would be a pain because most of Web libraries it offers are developed and supported by small communities and most of them are moving too slow. So, unless you commit to the workload of maintaining the software on VPS all by yourself, you have to choose among “standard” offers. They are normally ASP.NET for Windows-based or Perl/PHP (plus MySQL) for Linux/UNIX/BSD-based hosting, plus Java. The latter has normally higher price tag, though, and even JSP, if you count all the works behind (the created servlets), looks too heavy. All of them, however, are widely and wildly supported, with huge communities and huge choice of libraries and tools.

So, after calming any political thoughts about choosing the language, I started with PHP. The first couple of months were hard because I never used those languages full of dollars. Now I can easily produce dollars when they needed, though I will probably never get the idea why using them in (originally) Perl and (in Perl’s descendant to some extent) PHP to indicate your intent and distinguish between different way of interpreting data is sooooo important in our life.

Another (less important) reason to choose PHP over overhyped things like Java was its “environment friendly” system requirements. Even if you don’t use any IDEs, running a heavy tool plus a Web server in background would bring my then four year old home computer to a complete halt. Forget the modern IDEs wasting 200 megs of memory right after start, even without doing anything useful! I coded the HTML layout myself simply to have more flexibility and control and without having to learn yet another library just to hit the wall of its bugs and limitations several months later. This way, all that you need is a decent editor (the choice is also almost obvious) and probably a couple of scripts to manage tasks like backups until you grow to the point where the real version control is needed.

Now, when the first version is running, it seems like I have made a right decision. The most important thing is that even if you are completely free in your choice, you have to take a pragmatic approach, even if it will result in starting from basics.

Mysterious progressive JPEG.

February 13, 2007

There is something new to learn every day. I have never paid any attention to the “progressive” checkbox in the JPEG options dialog of GIMP. It turned out that this special (see description here) JPEG is a kind of better known to me interlaced GIFs. Interesting is that it’s only Internet Explorer who marks JPEGs, probably all JPEGs, not only those that are really progressive, as MIME type “image/pjpeg”. The card upload script was not ready to accept those but it’s fixed now. And I’m waiting for something like “regressive PNG” MIME type from the “market leader”.

Choices – Part I. Ubuntu Linux.

February 5, 2007

Those days the development of Kyusl is done entirely on Ubuntu Linux 5.10. It’s not the first Linux-based OS that is running on my PC, and as the choice is big today, I wanted to share some ideas on selecting the right system.

The first one (after Windows and FreeBSD at home, and many many others at work) was the RedHat Linux 9.0, which I decided to install in the days of late 2004 when the JPEG Windows library flaw was being exploited by bad guys. In comparison with other systems that I have tried later, the main point about the RedHat it gives you a feeling of a highly refined product. Really, you get exactly the same system that RedHat sold and supported commercially. The only problem with RedHat 9 is that it’s not supported anymore, so that you don’t get the important security upgrades and installing the latest software can be a pain.

Now, let’s look at what is available today. To get the system that is easily maintained, unless you are a big fan of playing with terminal trying to compile software packages from source, the best is to check the offers of the biggest Linux players. The absolute leaders are RedHat and Novell. But RedHat desktop version is too expensive. Novel’s SuSe is probably a good choice but, similaryl to RedHat, they don’t provide the “real” OS for free. What you get for free from two biggest vendors is “corresponding” community versions. I tried Fedora as a logical upgrade from RedHat 9 and was disappointed. It screwed up my RedHat install (dual boot didn’t want to work properly after) and the very first thing that I would normally do – check for online upgrades – didn’t work. In addition, each version is supported with updates only for several months – then you have to move to the next, downloading several CDs again. OpenSuse’s release notes that I checked at that time started with explanations on how to repair the broken update manager (same problem as with Fedora?). Now I wonder how both things managed to go to “production”.

Among smaller vendors there is Mandriva. I checked it recently, but found KDE to be kind of cluttered. So, I decided to continue with Ubuntu, whose CD I got for free directly from Canonical.

Though some things look nicer and more polished even on now four year old RedHat 9, there are many reasons to look at Ubuntu. Main ones for me are:

  1. The OS you get for free is the same that is commercially supported by its vendor. That means, they have some incentive to polish it.
  2. If you don’t want to wait for CDs (they ship them for free), all you have to download is one CD, which will have everything most users need. Among general software, I had to download another firewall because I didn’t want to play with iptable. (RedHat provides easy GUI applet to configure the firewall, but Ubuntu doesn’t). I could never understand who may need all those gigabytes that you have to download from the very beginning from Fedora or OpenSuse folks.
  3. Each version is supported for at least 18 months. In 2006 they have released a duo of “long term support” versions. Desktop gets three years and server gets five years of security updates. Yes, it still doesn’t beat Windows life cycle, but is already long enough.

Having said all that, the choice becomes easy. Even not-so-nice default font rendering and other less important points don’t affect Ubuntu as a winner for me.