Stop Letting Default MySQL Settings Kill Your Web Server
I recently watched a client's e-commerce launch melt down. They weren't hit by a DDoS. They were hit by legitimate traffic. Their frontend was a shiny new Magento installation running on a standard LAMP stack, and within ten minutes, the site was serving 503 errors. Why? Because the default my.cnf shipping with most Linux distributions is tuned for a server with 64MB of RAM from 1999.
If you are serious about hosting high-traffic applications, you cannot rely on defaults. In the world of VPS Norway hosting, latency isn't just network pingβit's disk I/O and query execution time. Let's fix your database before your next traffic spike.
1. The Engine Debate: MyISAM vs. InnoDB
In 2009, this shouldn't be a debate, yet I still see developers using MyISAM for write-heavy applications. MyISAM uses table-level locking. If one user is writing to the `orders` table, everyone else trying to read from it has to wait. On a busy site, this queue explodes, Apache worker processes pile up waiting for MySQL, and your server runs out of RAM.
Switch to InnoDB. It supports row-level locking. It handles concurrency far better. Unless you are running a read-only archive, change your default storage engine.
ALTER TABLE tableName ENGINE = InnoDB;2. The Holy Grail: innodb_buffer_pool_size
If you change only one setting in your /etc/my.cnf, make it this one. This variable determines how much memory MySQL uses to cache data and indexes for InnoDB tables. The default is often a pathetic 8MB.
If you have a dedicated database server, set this to 70-80% of your total RAM. On a shared web/db server (common in VPS environments), be more conservative to leave room for Apache and the OS.
Pro Tip: Don't guess. Check your current memory usage with `free -m` before changing this. Swapping to disk is death for database performance.
3. Disk I/O: The Bottleneck You Can't Config Away
You can tune configurations all day, but if your underlying storage subsystem is slow, your database will crawl. Databases are I/O intensive. They hate seeking.
This is where the choice of hosting provider becomes architectural, not just financial. Many budget hosts overload their nodes with SATA drives in software RAID. The seek times (latency) are horrendous when 50 tenants are hitting the disk simultaneously.
At CoolVDS, we configure our nodes with enterprise-grade Hardware RAID 10 controllers and high-RPM SAS drives (and we are beginning to roll out SSD caching layers for select zones). When your database flushes the transaction log, you need that write to happen now. Slow I/O causes the `iowait` metric in `top` to spike, and the system becomes unresponsive.
4. Key Configuration Flags for 2009
Here is a snippet from a production my.cnf I deployed last week for a client in Oslo:
[mysqld]
skip-name-resolve
query_cache_size = 64M
query_cache_limit = 2M
thread_cache_size = 8
innodb_buffer_pool_size = 512M
innodb_flush_log_at_trx_commit = 2Note on innodb_flush_log_at_trx_commit = 2: This gives you a massive performance boost by flushing the log to the OS cache rather than the physical disk every second. You risk losing one second of data in a total power failure, but for most web apps, the speed gain is worth it. However, if you are handling banking transactions, keep it at 1.
5. The Norwegian Context: Latency and Law
Hosting physically in Norway matters. If your users are in Oslo or Bergen, hosting in Texas adds 100ms+ of latency to every TCP handshake. For a database-driven application making multiple calls, that delay stacks up.
Furthermore, we have to consider the Personopplysningsloven (Personal Data Act). Datatilsynet is becoming stricter about where user data resides. Keeping your customer data on servers physically located within Norwegian borders simplifies compliance significantly compared to explaining safe harbor nuances to an auditor.
Conclusion
Performance is a stack. It starts with hardware (RAID 10, low-latency connectivity to NIX), moves to the OS (Linux kernel tuning), and ends with the application config (MySQL tuning). Don't let default settings cripple your growth.
If you are tired of fighting for disk I/O on oversold servers, it is time to move to a platform designed for professionals. Deploy a high-performance instance on CoolVDS today and see what your database can actually do.